23914Views7Replies

Author Options:

How can I center an embedded YouTube video (without using the deprecated <center> tag)? Answered

Tags:htmlcss

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.
0
kenvonrauch
kenvonrauch

8 years ago

The following thing worked for me:

I put this code in my style.css file:

.youtube {
margin-right: auto;
margin-left: auto;
display:block;
width:700px;
}


And I added my youtube video to the actual post like this:


http://www.youtube.com/watch?v=cUtw7sjnqFg
0
threecheersfornick
threecheersfornick

Answer 12 years ago

. text-align won't work as it is not text
. <div class="youtube"> <video> </div>
+
.youtube {
margin-right: auto;
margin-left: auto
}

didn't work for unknown reasons

0
dawnselene
dawnselene

Answer 8 years ago

you need to add display:block; and a width to make that work

0
Padlock
Padlock

Answer 11 years ago

Add this before the first object tag:
<div style="text-align:center">
and this after:
</div>

Text align still centers it, even though it is not text.

0
iPodGuy
iPodGuy

12 years ago

align=center?