How to center a video snipet in WordPress ?


How to center a (you tube) video snipet in WordPress ?

As straightforward as the wp editor is, some things just don’t fit right. One of them is the embedding of a video snippet, let’s say from YouTube. While adding a video make your content much more worthy and live, while the process is now easy, it’s not so easy to actually center an embedded video.

HTML coders would go straight to the HTML view and hardcode the tag, but what can be done for the rest of us ?
Luckily, there’s a very simple fix that allow to center any embedded object: video, flash content, flash game aso…

We all are used to click the “center” text  button on the tools bar. For sure, this does not work for embedded objects.

Once the video is in your post (you can insert the html code, or use a plugin – I do favour the html code option),

Just make sure you are in the html tab, and locate the <embed…> code.
Just before it, add a centered div, that is :

<div style="text-align:center;">

then locate the end of the embed code, and close the div:

</div>

You can then safely switch to the Visual tab and enjoy the centered video box.
This will work for whatever object you’d like to center…
or right align : just use text-align:right instead of center !

Once you’ll hace it done a few times, it will come easily and you’ll be able to impress your friends with your newly acquired “html coder” skills ;-)
You are now able to center a video like a pro.

Edit: In answer to Jim, it is also possible (should you have enough width) to align the video to the left of the content, and let the text flow on its right.
It’s very similar to the center trick: put a div around the embed code, that reads
<div style="float:left;">
and don’t forget to close it after the embed :
</div>
Then the text that follow the video will be in the free space on the right.
Next, if you want to force another paragraph below the video, you can exit of the flow by inserting a
<br style="clear:both"> that will force a reset of the css float rule.

Let me know how this works for you !

, , ,

  1. #1 by Jim Hood on January 7, 2012 - 10:26 pm

    The big challenge with video is how to have the video on the left with words wrapping on the right side, instead of the words having to start below the video! Any suggestions for that?

    • #2 by dadmin on January 8, 2012 - 9:13 am

      Thanks, Jim.

      I just added this trick to the post, too.

      cheers,

      Syl

  2. #3 by BAFA on February 6, 2012 - 5:03 pm

    Merci pour cette astuce, c’est toujours utile comme formation.
    Je travaille comme animateur en BAFA, et c’est le genre de truc qui sert toujours ;-)

    • #4 by dadmin on February 6, 2012 - 5:04 pm

      Merci, ça fait toujours plaisir.

      Syl

  3. #5 by Bruno de Formation logiciels on February 6, 2012 - 6:36 pm

    Merci, vraiment important comme astuce afin de garder une mise en page parfaite.

    Bruno

  4. #6 by Andrilson Alves on February 11, 2012 - 2:40 pm

    Olá gostei muito, dos exercicios de matematica financeira sobre juros simples e composto. valéu!

  5. #7 by Mukesh on February 12, 2012 - 4:51 am

    nice share buddy :)

  6. #8 by iranan man on November 27, 2012 - 12:41 pm

    Tank you for your post…

(will not be published)