6

Hi I am trying to center the iframe for a Youtube video in Twitter Boostrap 3, currently it is left aligned.

I have used the following html:

      <div class="embed-responsive embed-responsive-16by9">

      <iframe class="embed-responsive-item"  
       src="http://www.youtube.com/embed/zpOULjyy-n8?rel=0" 
       align="center" id="videothumbnail"></iframe>

       </div>

CSS:

    #videothumbnail{
    height: 50%;
    width: 50%;
    float: center;}
Dan
  • 9,391
  • 5
  • 41
  • 73
user3931756
  • 111
  • 2
  • 3
  • 4
  • possible duplicate of [Shrink a Youtube video to responsive width](http://stackoverflow.com/questions/15844500/shrink-a-youtube-video-to-responsive-width) – davidcondrey Oct 05 '14 at 00:04
  • @dcc this is definitely not a duplicate of that question. This question is talking about how to use classes that are built into the Bootstrap from Twitter framework, Version 3. – wuliwong Jan 04 '15 at 18:53

6 Answers6

15

Use classes col-xs-12 text-center. You don't need float:center;

So change this:

<div class="embed-responsive embed-responsive-16by9">

to

<div class="embed-responsive embed-responsive-16by9 col-xs-12 text-center">
Dan
  • 9,391
  • 5
  • 41
  • 73
8

I was able to center my embed-responsive by bordering it with smaller grids like so:

<div class='row'>
    <div class='col-sm-2'></div>
    <div class='col-sm-8'>
        <div class="embed-responsive embed-responsive-16by9">
            <iframe src="https://www.youtube.com/embed/Qt7DFLovvD8?modestbranding=1&showinfo=0" allowfullscreen></iframe>
        </div>
    </div>
    <div class='col-sm-2'></div>
</div>
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Emeka
  • 782
  • 2
  • 9
  • 15
  • You can add the class `col-sm-offset-2` to your centered div instead of having an empty one before. – ymoreau Nov 17 '18 at 14:27
4

Just add center tags

<center>
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item"  id="videothumbnail" src="http://www.youtube.com/embed/zpOULjyy-n8?rel=0" align="center"></iframe>
</div>
</center>
2

If working with Bootstrap 4 you could use offset.

<div class="col-sm-8 offset-md-2 embed-responsive embed-responsive-16by9">
    <iframe class="embed-responsive-item" width="750" height="415" src="https://www.youtube.com/embed/{your-video}" frameborder="0" gesture="media" allowfullscreen>
</iframe>
</div>

This limites the embed to 8 columns and keeps 2 columns either side of it blank (totalling 12).

Dave
  • 75
  • 7
0

wrap the iframe with h(1-2-3...)

<h4 class="text-center">   <iframe ....> </iframe>    </h4>
  • Wouldn't just the class do the text align if placed on any element? Why is your answer better than the other ones given a few years back? – Syfer May 27 '18 at 21:23
-1
<div class='row text-center'>


    <div class="embed-responsive embed-responsive-16by9">
        <iframe src="https://www.youtube.com/embed/Qt7DFLovvD8?modestbranding=1&showinfo=0" allowfullscreen>

        </iframe>
    </div>
</div>
wogsland
  • 9,106
  • 19
  • 57
  • 93
macs
  • 1
  • Welcome to Stack Overflow! Please add some explanation of why this code helps the OP. This will help provide an answer future viewers can learn from. See [answer] for more information. – Heretic Monkey Jul 29 '16 at 22:32