tags:

views:

135

answers:

5
A: 

sounds like a table to me... oh, I can see the comments and down votes coming already. "tables are only for tabular data"... Yeah, I know but they are also a qnd way of doing exactly what steve wants to do.

Badfish
+1  A: 

Have you tried experimenting with the CSS property called float? Specifying float: left causes the width of the containing element to adjust to the text - seems like a secondary effect but it works.

If you don't want the containing elements lining up, you can add <br /> tags or you can add "clear: both;" to the style.

I definitely think it's achievable - you just need to find the right combination of attributes/values.

Mayo
If you go this route, you can add clearfix to avoid extra markup. ( http://www.positioniseverything.net/easyclearing.html )
easement
Note: `<br />` tags won't keep the elements from lining up unless you apply some basic CSS to them: `br { clear: left; }`
brianreavis
I'll just scratch out the tag reference - the question is about css anyway :)
Mayo
+1  A: 

You can get the highlighted paragraphs to minimally surround the text by making the highlighted paragraphs float left as block elements (<p> is by default). Then, get the paragraphs to clear:left to prevent them from stacking up horizontally.

The CSS:

.pars {
    /* this is used to prevent the last floating element 
    from causing issues below the paragraph (.pars) container */
    width: 100%;
    overflow: visible;
}
.pars p {
    clear: left;
    margin: 0 0 0.5em 0;
}
.pars .highlighted {
    float: left;
    padding: 1.0em;
    border-style: solid;
    border-width: 2px;
    background-color: #FFFFCC;
    border-color:#E8E800;
}

Your HTML:

<div class="pars">
   <p>Some paragraph text</p>
   <p class="highlighted">Some bordered text</p>
   <p class="highlighted">Some more bordered text</p>
   <p>Some very long bordered text blah blah blah 
   blah blah blah blah blah blah blah blah blah blah</p>
</div>
brianreavis
A: 

what about display:inline-block?

easement
IE6 / cross browser stuff about inline-block: http://foohack.com/2007/11/cross-browser-support-for-inline-block-styling/
easement
+1  A: 

Just add

p.highlighted {
    float: left;
}

p {
    clear: both;
}

This will cause the highlighted paragraphs to only be as wide as required by their text, and will ensure that existing paragraphs never overlap horizontally with the highlighted ones.

JSBangs