Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have worked on a jQuery-based solution &mdash; probably not as elegant as the one posted by gilly3 though ;) and it's also slower and a bit bloated...</p> <p>My trick is to append two <code>&lt;div&gt;</code>s to the section, which is floated to the left and hidden width a width of 0. One of the div, a designated ghost element that will have the same dimension as the image, will be positioned below another div that is the designated height spacer. The script uses a while loop to establish if the ghost element has reached the bottom of the parent section element. If this has not happened, it will increment the height of the height spacer by 1, until the condition is satisfied.</p> <p>The markup I have used is as follow. I'm using the HTML5 attribute <code>data-bottom-image</code> to identify sections that you have the image to be floated to the bottom. Of course it is dispensable, depending on how you want to select for the correct section element.</p> <pre><code>&lt;section id="c1" data-bottom-image&gt; &lt;h2&gt;...&lt;/h2&gt; &lt;p&gt;...&lt;/p&gt; &lt;img src="http://placehold.it/250x100" /&gt; &lt;/section&gt; </code></pre> <p>And the jQuery script:</p> <pre><code>$(function () { $("section &gt; img:last-child").each(function () { // Offset image based on the bottom and right padding of parent var $par = $(this).parent(); $(this).css({ bottom: $par.css('padding-bottom'), right: $par.css('padding-right') }); }); // Function: adjust height of height-spacer, pixel by pixel function adjustHeightSpacer($par, $hs, $is) { // Stretch height spacer $hs.height(0); $hs.css({ height: $par.find("img").position().top - parseInt($par.css('padding-top')) }); // Adjust height spacer while($par.height() - $is.height() &gt; $is.position().top - parseInt($par.css('padding-top'))) { $hs.height("+=1"); } while($par.height() - $is.height() &lt; $is.position().top - parseInt($par.css('padding-top'))) { $hs.height("-=1"); } }; $("section[data-bottom-image]").each(function() { // Append two spacers: $(this).prepend('&lt;div class="ghost height-spacer" /&gt;&lt;div class="ghost image-spacer" /&gt;') var $hs = $(this).find(".height-spacer"), $is = $(this).find(".image-spacer"); // Adjust image spacer dimension $is.css({ height: $(this).find("img").height(), width: $(this).find("img").width() }); // Adjust height spacer adjustHeightSpacer($(this), $hs, $is); }); $(window).resize($.debounce(250,function() { $("section[data-bottom-image]").each(function() { // Adjust height spacer adjustHeightSpacer($(this), $(this).find(".height-spacer"), $(this).find(".image-spacer")); }); })); }); </code></pre> <p>And here is the working Fiddle: <a href="http://jsfiddle.net/teddyrised/xmkAP/5/" rel="nofollow">http://jsfiddle.net/teddyrised/xmkAP/5/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload