1

How can I center object content within a div?

.parent{
background-color:yellow;
}

.ob{
margin: 0 auto;
}
</style>

<div class="parent">
<object width="400" height="400" class="ob" data="helloworld.swf">
</object>
</div>

Thanks in advance!

TechWisdom
  • 3,960
  • 4
  • 33
  • 40
yuklia
  • 6,733
  • 5
  • 20
  • 26

2 Answers2

6

An object element has inline style by default, and margin: auto applies to block-level elements only.

Add this style:

.ob {
  display: block;
}

Fiddle

Rick Hitchcock
  • 35,202
  • 5
  • 48
  • 79
1

Or this since the object is an inline element.

.parent{
text-align: center;
}

If you want to get modern.

.parent{
    background-color:yellow;
    display: flex;
    justify-content:center
}
Paulie_D
  • 107,962
  • 13
  • 142
  • 161