开发者

css width % in ie7

I have a parent container which is 100%. It contains 2 floating divs which are widt开发者_如何学运维h:50%. The children contains only text. The problem is that the children on get as wide as the text, and not 50% of the width of the parent container. It is only ie7 that is a problem. Maybe also ie6, but I don't care about that browser.

ball (width 16px position absolute)
   parent (width 100% position absolute. Should be more than 16px)
      child (width:50% float left)
      child (width:50% float left)

Can someone help?


No need for a JS hack. Just use the right doctype.

Copy'n'paste'n'run this, check the result, then remove the doctype and retest in IE.

<!doctype html>
<html lang="en">
    <head>
        <title>Test</title>
        <style>
            body { width: 300px; }
            .parent { width: 100%; border: 1px solid black; overflow: hidden; }
            .child { float: left; width: 50%; }
            h3 { clear: left; }
        </style>
    </head>
    <body>
        <h3>Test 1</h3>
        <div class="parent">
            <div class="child">text</div>
            <div class="child">text</div>
        </div>
        <h3>Test 2</h3>
        <div class="parent">
            <div class="child">text text text text text text text text text text</div>
            <div class="child">text</div>
        </div>
        <h3>Test 3</h3>
        <div class="parent">
            <div class="child">text</div>
            <div class="child">text text text text text text text text text text</div>
        </div>
    </body>
</html>

Without doctype or with a non-standards-mode doctype IE will namely render in quirks mode.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜