Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here the way to handle this <em>with only CSS and without changing your HTML order</em>, by adding a small additional html attribute*:</p> <p>*<em>In my opinion, this is only possible way to get this work, because the floating behavior, specified by the w3c, can't work this way without adding at least one html attribute.</em></p> <h2>HTML</h2> <pre><code>&lt;div id="desired_wrap"&gt; &lt;div id="desired_main" data-placeholder="my box text"&gt; main text, dont know height in advance&lt;br /&gt; main text, dont know height in advance&lt;br /&gt; main text, dont know height in advance&lt;br /&gt; &lt;/div&gt; &lt;div id="desired_right" class="somediv"&gt; my box text &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Now, we're placing the text from <code>data-placeholder</code> via the <a href="http://reference.sitepoint.com/css/pseudoelement-before" rel="nofollow"><code>:before</code></a>, before <code>#desired_main</code> via the <a href="http://reference.sitepoint.com/css/content" rel="nofollow"><code>content</code></a> css property.</p> <p>This way, the height of the generated element will be exactly the same as the height from <code>#desired_right</code>, because they contain the same text.</p> <h2>CSS</h2> <pre><code>#desired_wrap{ width:200px; padding:10px; position: relative; } .somediv { width: 100px; } #desired_main:before { content: attr(data-placeholder); float: right; width: 100px; }​ </code></pre> <p>Positioning <code>#desired_right</code> absolute to the right top, will simulate a float right, like in your first, working example:</p> <h2>CSS</h2> <pre><code>#desired_right{ position: absolute; top: 10px; right: 10px; } </code></pre> <h3>Works well in:</h3> <ul> <li>Internet Explorer 8+</li> <li>Firefox 3.6</li> <li>Chrome 17+</li> <li>Safari 5+</li> </ul> <p><strong>Live demo</strong>: <a href="http://jsfiddle.net/SPgyA/3/" rel="nofollow">http://jsfiddle.net/SPgyA/3/</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. 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