yuklia
yuklia

Reputation: 7853

Center an object tag in a div

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!

Upvotes: 1

Views: 2765

Answers (2)

Paulie_D
Paulie_D

Reputation: 115278

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
}

Upvotes: 1

Rick Hitchcock
Rick Hitchcock

Reputation: 35670

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

Add this style:

.ob {
  display: block;
}

Fiddle

Upvotes: 6

Related Questions