When the browser size changes / on devices of different sizes, I need a set of html elements that are all semantically connected to stay together and move in the block. That is, if one of the elements moves to the next "line" due to the fact that they do not have sufficient width to contain the entire group, ALL of it should move down.
IOW, this is similar to the “keep together” attribute that some groups of elements in a word processing document have.
To be more specific, let's say that I have collections of the following elements:
1) an anchor tag, filling out a first "column" 2) a collection of tags, to the right of the anchor tag, consisting of: (a) a div, followed by a <br/> (b) a cite, followed by a <br/> (c) another div, followed by a <br/> (d) two or three anchor tags that are aligned side-by-side at the bottom of the second "column"
So, to summarize, if there is not enough space for the second “column” in the “row” and not contain in the first “column” and move the elements in the second column to the next row, “in the first column you should stick to your brothers and sisters and always stay on the same "row" with them (I put the "rows" and "column" in quotation marks, because I do not use the html table, but those that exist only in the virtual sense).
If you find it a bit hard to imagine (I don't blame you), check out the script: http://jsfiddle.net/W7CYC/8/
Note: wrapping groupings in html5 s did not help.
Here is the code:
HTML:
<div class="yearBanner">2013</div> <section> <a id="mainImage" class="floatLeft" href="http://rads.stackoverflow.com/amzn/click/0299186342"><img height="240" width="160" src="http://ecx.images-amazon.com/images/I/51usxIl4vML._SY346_.jpg"></a> <div id="prizeCategory" class="category">BIOGRAPHY</div> <br/> <cite id="prizeTitle" class="title">Son of the Wilderness: The Life of John Muir</cite> <br/> <div id="prizeArtist" class="author">Linnie Marsh Wolfe</div> <br/> <img class="floatLeft" height="60" width="40" src="http://ecx.images-amazon.com/images/I/51usxIl4vML._SY346_.jpg"> <img class="floatLeft" height="60" width="40" src="http://ecx.images-amazon.com/images/I/51usxIl4vML._SY346_.jpg"> <img class="floatLeft" height="60" width="40" src="http://ecx.images-amazon.com/images/I/51usxIl4vML._SY346_.jpg"> </section> <section> <a class="floatLeft" href="http://rads.stackoverflow.com/amzn/click/0299186342"><img height="240" width="160" src="http://ecx.images-amazon.com/images/I/51usxIl4vML._SY346_.jpg"></a> <div class="category">BIOGRAPHY</div> <br/> <cite class="title">Son of the Wilderness: The Life of John Muir</cite> <br/> <div class="author">Linnie Marsh Wolfe</div> <br/> <img height="60" width="40" src="http://ecx.images-amazon.com/images/I/51usxIl4vML._SY346_.jpg"> <img height="60" width="40" src="http://ecx.images-amazon.com/images/I/51usxIl4vML._SY346_.jpg"> <img height="60" width="40" src="http://ecx.images-amazon.com/images/I/51usxIl4vML._SY346_.jpg"> </section>
CSS
body { background-color: black; } .floatLeft { float: left; padding-right: 20px; padding-left: 5px; } .yearBanner { font-size: 3em; color: white; font-family: Verdana, Arial, Helvetica, sans-serif; float: left; padding-top: 64px; } .category { display: inline-block; font-family: Consolas, sans-serif; font-size: 2em; color: Orange; width: 160px; } .title { display: inline-block; font-family: Calibri, Candara, serif; color: Yellow; width: 160px; } .author { display: inline-block; font-family: Courier, sans-serif; font-size: 0.8em; color: White; width: 160px; }
JQuery
$('#prizeCategory').text("Changed Category"); $('#prizeTitle').text("Changed Title that spans two rows"); $('#prizeArtist').text("Changed Author and co-author"); $('#mainImage img').attr("src", "http://ecx.images-amazon.com/images/I/61l0rZz6mdL._SY300_.jpg"); $('#mainImage img').attr("height", "200");