22660Views7Replies

Author Options:

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

Tags:htmlcss

7 Replies

user
BrettA17 (author)2016-07-12

Thanks for the tip. This came in handy for my personal self defense website, Armor and Shield Tech. http://www.armorandshieldtech.com

Select as Best AnswerUndo Best Answer

user
kenvonrauch (author)2012-12-27
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

Select as Best AnswerUndo Best Answer

user

. 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

Select as Best AnswerUndo Best Answer

user

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

Select as Best AnswerUndo Best Answer

user

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.

Select as Best AnswerUndo Best Answer