HTML CSS examples for CSS Layout:Flex Container
Place text on top of flexible images
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style id="compiled-css" type="text/css"> .responsive-container {<!-- ww w . j av a2s .c om--> display: inline-block; position: relative; width: 50%; border: 1px solid black; background-image: url(https://www.java2s.com/style/demo/InternetExplorer.png); background-size: 100%; background-repeat: no-repeat; } .dummy { padding-top: 100%; } .img-container { position: absolute; top: 0; bottom: 0; left: 0; right: 0; text-align:center; font: 0/0 a; } .img-container .centerer { display: inline-block; vertical-align: middle; height: 100%; } .img-container h2 { vertical-align: middle; display: inline-block; font-size: 16px; line-height: 16px; background-color: #888; padding: 15px; } </style> </head> <body> <div class="responsive-container"> <div class="dummy"></div> <div class="img-container"> <div class="centerer"></div> <h2> Underwater <br> Swimming </h2> </div> </div> </body> </html>