4 ms·
My utmost favourite technique for centering unknown width and height DIV's/elements perfectly center in the page is using 2dtransforms. I've created a Codepen h
by DigitalSea 13y ago
My utmost favourite technique for centering unknown width and height DIV's/elements perfectly center in the page is using 2dtransforms. I've created a Codepen here that shows off the technique, it's simple and well supported IE9+: http://codepen.io/Figurated/pen/zcypx http://codepen.io/Figurated/pen/zcypx — if you don't need to support IE8 any more, it's a perfect solution.
- hesslau_ 13y agoMy favourite technique: position absolute and top: 0 bottom: 0 left: 0 right: 0 also doesn't require a fixed width http://codepen.io/anon/pen/vsliJ http://codepen.io/anon/pen/vsliJ
- grannyg00se 13y agoThat's great! And it seems to have pretty good browser support.
- olivier1664 13y agoYour technique is less good (on IE11) when you resize the width of the browser. The text finish outside the div, while DigitalSea's solution works well.