Strange float behaviour in IE7

后端 未结 6 735
长发绾君心
长发绾君心 2020-12-03 05:56

I want to create a simple box with a header bar containing a title and some tool buttons. I have the following markup:

&
相关标签:
6条回答
  • 2020-12-03 06:09

    Make this <div style="background-color:blue; padding: 1px; height: 20px;> the parent of the 2 floating divs also clear:all

    0 讨论(0)
  • 2020-12-03 06:11

    Specify width in outermost div. If that width in your content div means this is the total width of your box, simply add it to the outermost div, and (optionally) remove it from content, like this:

    <div style="float:left; width: 200px;">
        <div style="background-color:blue; padding: 1px; height: 20px;">
            <div style="float: left; background-color:green;">title</div>
            <div style="float: right; background-color:yellow;">toolbar</div>
        </div>
        <div style="clear: both; background-color: red;">content</div>
    </div>
    
    0 讨论(0)
  • 2020-12-03 06:13

    Got to know recently that the right floated elements need to be appended with the divs before the other elements. This is the easiest fix without adding a line of change.

    <div style="background-color:blue; padding: 1px; height: 20px;">
        <div style="float: right; background-color:green;">title</div>
        <div style="float: left; background-color:yellow;">toolbar</div>
    </div>
    
    0 讨论(0)
  • 2020-12-03 06:21

    I fixed it using jQuery to emulate the behaviour of the non-IE browsers:

        // IE fix for div widths - size header to width of content
        if (!$.support.cssFloat) {
            $("div:has(.boxheader) > table").each(function () {
                    $(this).parent().width($(this).width());
            });
        }
    
    0 讨论(0)
  • 2020-12-03 06:24

    This is just a quick answer, so I hold my hands up if it doesn't quite work. I think Marko's solution will probably work if you just add min-width rather than width. If you are trying to cater for ie6 as well, you may need to use a hack, as min width is not supported by ie6 and it's descendants.

    So this should work with IE7 and other modern browers. Set the min-width to whatever is appropriate.

    <div style="float:left; min-width: 200px;">
        <div style="background-color:blue; padding: 1px; height: 20px;">
            <div style="float: left; background-color:green;">title</div>
            <div style="float: right; background-color:yellow;">toolbar</div>
        </div>
        <div style="clear: both; background-color: red;">content</div>
    </div>
    
    0 讨论(0)
  • 2020-12-03 06:26

    Try putting position:relative; to parent-element and to the child-element. It solved the problem for me.

    0 讨论(0)
提交回复
热议问题