Search code examples
cssblock

CSS block elements with relative width?


Here's what I'm trying to pull off...

enter image description here

And the corresponding HTML:

<article>
  <h3>Fading Forest</h3>
  <p>Donec id elit non mi porta gravida at eget metus. Nullam quis risus eget urna mollis ornare vel eu leo. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Vestibulum id ligula porta felis euismod semper.</p>
  <p class="permalink"><a href="http://example.com/12345" title="">example.com/12345</a></p>
</article>

So what I need to do is wrap each h3 and p in a box, but right now, since the h3 and p tags are block level elements, the corresponding blocks just extend the full width.

I want the width to adjust according to the content (and just apply max-width so they don't extend too wide).

This is what I've got so far, though it doesn't work...obviously. http://jsfiddle.net/hAtRs/


Solution

  • Forget the inline-block; it doesn't seem to be necessary.

    Float and clear to the left:

    h3, p {
        float: left;
        clear: left;
    }
    

    http://jsfiddle.net/hAtRs/20/