简体   繁体   中英

Non-floated element between two floated ones - IE7

This is my code (really simplified):

<div style="float: left;">
    <div style="float: left;">
        <!-- Some content -->
    </div>
    <div style="float: right;">
        <!-- Some content -->
    </div>
    <form method="post" style="display: block; width: 100%; position: relative;">
        <fieldset>
            <!-- Some content -->
        </fieldset>
    </form>
</div>

In IE8, FF3.6/4, Chrome and Opera it looks good. Div's don't have specified width, and I want form to fill remaining space. But in IE7 non-floated form drops lower. What should I do?

You can see this on this site (top bar)

Is there a reason that you don't want to specify widths? It seems like their header is much more verbose than necessary. would something like below accomplish the same thing for you?

<div style="float: left; width:100%;">
<div style=" display:block;float: left; position:relative; top:0; left:0; width:20%">
    <p>LEFT SIDE</p>
</div>
<div style="display: block; position: relative; float:left; top:0; left:0; width:60%;">
        <form method="post">
    <fieldset>
        form stuff
    </fieldset>
</form>
</div>
<div style="display: block; float: left; position:relative; top:0; left:0; width:20%;">
    <p>RIGHT SIDE</p>
</div>

This should work in IE but CSS may need tweaking to compensate for how older IE handles the box model.

when you specify the form to have 100% width, it will ocupy the full width of the parent, and in this case, the parent is the same as the one for the floated divs.

You either clear the width of the non-floated and keep the rest or specify a width for the floated ones and clear the width of the non-floated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM