Creating Intrinsic Ratios for Video

by Thierry Koblentz

24 Reader Comments

Back to the Article
  1. I like the scaling aspect of this, that will come in handy. I made a simple jQuery based 16:9 calculator based on the width of a content section: http://www.brianartka.com/jqueryVideoBox.html Its simple, but solved my issues. I did some research and there is no set “standard” to what the width of a 16:9 video should be on the net, its all over the board. The key is keeping the aspect ratio, as Thierry mentions in the article. Maybe this little tool will be helpful for others. Thanks!
    Copy & paste the code below to embed this comment.
  2. Just today, I released something *very* pertinent to this! It’s called “Video For Everybody” and it’s a block of HTML to support HTML5 <video>, fall then back to Flash and then QuickTime/WMP for other browsers. It uses a biscuit method much like you’re doing here. See it here: “Video For Everybody”:http://camendesign.com/code/files/video_for_everybody/test.html I’m wondering if I can roll your ratio work into this, to better support various Flash/QT/WMP controller sizes.
    Copy & paste the code below to embed this comment.
  3. Nice article. Cool way to size video and a pretty clean object tag. But, I can’t believe the web still doesn’t have a “real” way to embed media on a webpage. I truly hope the video tag is not another 5 years away from being useful on a public page. The single object method (one of the cleanest yet) and even Kroc’s project are still short of the mark. All methods still require that you know which plugin the browser should use which is madness. (Krocs method does not but instead requires at least 3 different versions of the same content which can be even worse) You want to serve “.3gp” video or “.ogg” audio or even mov, flv, wmv and any number of possible formats. That is: a dynamic page where the embedded media may be ANY of these formats. Today I need to create templates for each possible format and browser. Just like the bad old times. (Since the media is user generated and not of to any one particular format) All methods serve (at least for IE) a specific plugin. Not a file format. I have no idea which plugin is your preferred plugin to play ogg or 3gp in Firefox on Ubuntu or Opera on Windows. And frankly I’d rather not know. Any of you very clever people know of a way to actually render a page where the browser decides the type of plugin to be used?
    Copy & paste the code below to embed this comment.
  4. @MartinWestin My format only requires an MP4 and an OGG. Firefox 3.5 plays the OGG and Safari / iPhone / Flash plays the MP4. So technically, you’re only exporting one more video file, and OGG is worth using to target Firefox users (in the future) without any need for any plugins. Other browsers may adopt OGG in the future too. Sure the object tag is a mess, but we have to start somewhere in moving to <video> and “Video For Everybody” my first attempt at doing that. With a FLV file, you only get Flash and nothing else. With my method and with one MP4 file you support Safari/iPhone/Flash/QuickTime and Windows Media Player embeds. I really can’t see how that’s worse off than only Flash.
    Copy & paste the code below to embed this comment.
  5. This really is amazing, it’s perfect for fluid layouts that contain video… I’ve wanted to do this for ages but never worked it out, relying on JavaScript resizing instead. Only thing I don’t like is the horizontal scrollbar, what’s that all about?
    Copy & paste the code below to embed this comment.
  6. @Kroc
    Your method looks like a good one, under certain circumstances. I was not trying to pick on you but only point out that your method as well as the one in the article is still short of nirvana. As I understand it your method uses a fixed fallback path. Video -> quicktime -> flash -> error display, or did I get that wrong? What I have been looking for, and am baffled by not finding, is ONE tag (or composite mess for that matter) to embed “video”. I.E. a method that lets the browser decide the plugin to be used. The same tag should take a quicktime mov, a wmv video, or any other video format the world has ever known. It must be up to the browser to decide if it has support for a certain media type, not the server script, javascript or the html tags. The examples of formats I used are immaterial. What if I want to serve fbv files (Fabouls Basass Videoformat) or I have installed “MartinPlayer2.0”? Do you see my point?
    Copy & paste the code below to embed this comment.
  7. @brianartka
    With this solution there is no need to calculate height or width, the only value needed is the ratio (set via padding). @Kroc
    That’s an interesting approach. I think you should have no problem implementing this solution with it as long as the UA can style the element you want to stretch within the box. @Thomas
    The horizontal scrollbar has nothing to do with the video, it is because of the markup that is displayed within <pre></pre> (it does not wrap). Use Firebug to remove this element and you should see that scrollbar disappear.
    Copy & paste the code below to embed this comment.
  8. Great….thanks for nice article guys.
    Copy & paste the code below to embed this comment.
  9. I posted a very similar technique around 3 years ago on css-d (“css-d archive”:http://www.mail-archive.com/css-d@lists.css-discuss.org/msg12569.html—the link to my site is dead now, but you get the gist). Whether you found that and adapted it or came up with this independently (where the latter is far more likely), good to know it wasn’t just my crazy idea!
    Copy & paste the code below to embed this comment.
  10. @Leszek:
    Hi,
    Actually, _after_ I wrote this article (but before it was published on ALA), Ingo Chao sent me a link to the thread you mention.
    I asked the editor to somehow plug that link in the article, but that didn’t happen. 
    On the other hand, our techniques are *very different* (even if both use padding) as I am relying on the width of the parent of the outer div - which allows me to use a “constant” - while you calculate the padding of the element based on its own width.
    In my opinion, that approach cannot really work as you need to keep width and padding “in sync”.
    Copy & paste the code below to embed this comment.
  11. Great article.  I’m struggling to find a solution for the same idea, but rather than having the height of the wrapper-div based on the width of the window—I need the opposite—the width of the wrapper-div be based on the height of the window.  Any thoughts on this?
    Copy & paste the code below to embed this comment.
  12. Thanks Thierry, really useful article. Bytheway, what video format do you suggest? I like flv anf avi, works best for me.
    Copy & paste the code below to embed this comment.
  13. @dedsused Thanks.
    Unfortunately, I don’t know much about videos so I can’t answer your question.
    May be someone here will be able to…
    Copy & paste the code below to embed this comment.
  14. This is an issue I’ve been struggling with for a week - and this solves a lot of the problems I’ve been having - thanks. Couple of questions tho’: First… is it possible to add the same resizing relative to browser height? And second, I’m now having a problem trying to center the video in the browser window - would you have any suggestions about which method might best apply here…? much appreciated!
    Copy & paste the code below to embed this comment.
  15. @Piers Hi,
    As far as I know, there is no pure CSS solution to resize an element based on the height of the viewport (while keeping its aspect ratio). Centering the video is a matter of centering the parent container, the one that provides the padding computation.
    Copy & paste the code below to embed this comment.
  16. A client was asking for something similar to this to be implemented - should be able to sort it now :)
    Copy & paste the code below to embed this comment.
  17. Hmm… I’m trying to use this, but something is wrong. Can you, please, take a look at following part of css: .videoWrapper div,
    .videoWrapper embed,
    .videoWrapper object {
      position: absolute;
      width: 100%;
      height: 100%;
      left: 0;
      top: 0; and check it again? All is fine there? Thanks!
    Copy & paste the code below to embed this comment.
  18. Hi Noak, Yes, this rule is correct. It could be an issue with your markup or with other rules(?).
    Do you have a page I can look at?
    Copy & paste the code below to embed this comment.
  19. Brilliant information helped with embedding my vids correctly, thanks!
    Copy & paste the code below to embed this comment.
  20. Unfortunately, I’m don’t use video on my blog now, but I liked the article because there is a thought to use these knowledge on another project which will be a lot of video clips! Thank for article!
    Copy & paste the code below to embed this comment.
  21. Brilliant workaround. Thanks for ensuring the code validates properly too - I’ve had some nasty experiences with the object tag in the past.
    Copy & paste the code below to embed this comment.
  22. Your article is well thought out and extremely well written. Clearly you know your CSS. But Flash is incompatible with iPhone. How do I get other video on iPhone?
    Copy & paste the code below to embed this comment.
  23. Very useful article even two and a half years later.  I’m using your technique (as closely as I can) to post video on my blog.  It is working for all current browsers EXCEPT IE9.  I have spent hours unsuccessfully trying to figure this out.  An example can be found here: http://blog.tlinn.com/2011/09/rogue-river/

    I don’t have any conditional statements in the <object> code; don’t know where to put them.  But the video plays fine when the <div class=“video-wrapper”> and <div class=“video-container”> are removed.  Any thoughts?  Thanks.
    Copy & paste the code below to embed this comment.
  24. Very useful article… Thank so much Thierry… May I translate this article into Indonesian?
    Copy & paste the code below to embed this comment.