tags:

views:

187

answers:

4

Hello. I am trying to create a liquid 3 column area within a list item. To achieve this, I use the standard method of having 3 elements, of which the first two are the sides, floated left and right, and the 3rd is the content, which should sit between the two. The following HTML works fine in Firefox, but doesn't render correctly in IE7 - the content is rendered below the two floated elements. Any ideas what the problem is?

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
  <head>
    <style>
        *
        {
            margin: 0;
            padding: 0;
            border: 0;
        }
        span
        {
            display:block;
        }
        .corner
        {
            width: 12px;
            height: 12px;
        }
        .tl
        {
            float: left;
        }

        .tr
        {
            float: right;
        }
        .fill
        {
            margin: 0px 12px;
        }
    </style>
  </head>
  <body>
    <ul>
      <li>
        <span class="tl corner">a</span>
        <span class="tr corner">b</span>
        <span class="fill">text text text</span>
      </li>
    </ul>
  </body>
</html>

Note that replacing the spans with divs results in the same effect. I've also tried various DocTypes with no luck. And it works fine outside of the list, hence the problem appears to be intrinsic to using the list.

A: 

It's a bit difficult to say anything without seeing the markup, but why don't you just put the two elements which should float inside the content element? You would have to adjust with some padding on the content element, but that should do the job. Then again, not quite sure what you mean. If you supply us with a bit more markup, it would be easier to tell.

Erik
Because my real html includes repeating background images. This is pretty standard design for 3 column liquid display. If you remove the list, it works fine; however, I want it to work inside the list.
darasd
+2  A: 

The way IE sees it, you're trying to jam in the lines one after the other, but the first two have already taken up their space, FLOATing away, which leaves the last SPAN in the LI to fight for the next level, which in IE looks like the next level below.

Since the last SPAN is not floated, that's also why it gets knocked to the next level.

Also, SPANs are inline styles, not block level elements. You should replace SPAN with DIV is you still want to try and style this in a LI element.

You should also use a full DOCTYPE so the browsers will know how to render the page. Otherwise they will default to quirks mode, ugly and all over the place.

But the better tactic is to create this float of 3 columns outside of the LI and in a DIV setting.

Have a read of CSSplay or Max Design on creating 3 column layouts.

random
+1 for CSSplay and general good advice. However, see my new edit. In effect my code is the same as the 2nd CSSplay example, except that my columns are within a list. Floating the 3rd span helped, but the span then failed to fill the space between the other two.
darasd
Do you want to set a hard width on the LI? Or would you rather it go 100%?
random
A: 

The center block should have margins to either side allowing room for the floated blocks.

Trevor Bramble
it does: margin: 0px 12px.
darasd
A: 

The answer is to wrap the spans in a block level element (say, a div), with overflow set to hidden. Example came from a more in depth look at the 2nd CSSplay example.

darasd