Using HTML/CSS, I'm trying to create the following:
- a fluid-size box with a fixed aspect ratio (16:9)
- a 50% black overlay inside the box
- vertically centered arbitrary content on top of the overlay
I combined a couple of techniques that I found:
- vertical centering: http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/
- maintaining aspect ratio: http://martinbean.co.uk/blog/2013/09/12/maintaining-aspect-ratio-in-css/
to arrive at something pretty close to the target:
http://codepen.io/troywarr/pen/zxNdKP?editors=110
That looks great in a 1280px wide viewport, but if you stretch the browser narrower or wider, you'll see that the .overlay maintains a fixed height while the .container resizes fluidly while still maintaining a 16:9 aspect ratio.
If I could set the value of line 20 to 100% and thus have .overlay expand to the visual height of .container, I'd be golden. It's understandable why that doesn't work (.container has an actual height of 0), but I'm stumped as to what to try next.
Please keep in mind that I may be going about this all wrong, and there may be a completely different approach that works better. Ultimately, all that's important to me is:
- cross-browser support back to IE10
- HTML/CSS only (as I could just add some JS to what I have now and get it to work well enough)
Thanks for any help!
 
     
    