I struggle with HTML5/CSS and have a simple task of laying out three DIVs differently based on screen size, using @media declarations.
Layout 1 Layout 2
+----- container -----------------+ +----- container ---------------------+
| +-----------------------------+ | | +------------+ +-----------------+ |
| | header text | | | | thumbnail | | header text | |
| +-----------------------------+ | | | image | +-----------------+ |
| +------------+ +-------------+ | | | | +-----------------+ |
| | thumbnail | | body text | | | +------------+ | body text body | |
| | image | | body text | | | | text body text | |
| | | | body text | | | | body text ..... | |
| +------------+ +-------------+ | | +-----------------+ |
+---------------------------------+ +-------------------------------------+
The basic structure is as follows:
<div id="container">
<div id="header">header text</div>
<div id="thumbnail"><a href="xxx"><img src="yyy" /></a></div>
<div id="bodytext">Some free-form text to be wrapped</div>
</div>
The thumbnail images are fixed in size. My current approach involves:
In Layout 1, I use float:left for the 'thumbnail' and 'bodytext' divs. In Layout 2, I apply padding-left: [image width]px; to the 'header' and 'bodytext' divs, along with absolute positioning of the 'thumbnail'.
However, this solution feels inelegant and makeshift, with concerns about compatibility across different browsers and devices.
Is there a better alternative such as flexbox?