为什么CSS min-width属性不强制div具有指定的最小宽度? [英] Why does the CSS min-width attribute not force a div to have the specified minimum width?

查看:112
本文介绍了为什么CSS min-width属性不强制div具有指定的最小宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html>
    <head>
        <style type="text/css">
            div {
                border:1px solid #000;
                min-width: 50%;
            }
        </style>
    </head>
    <body>
        <div>This is some text. </div>
    </body>
</html>

我相信div应该是页面的50%,除非由于某种原因, div使它更大。但是,div周围的边框在整个页面宽度上延伸。

I believe the div should be 50 percent of the page, unless, for some reason, the text inside the div makes it larger. However, the border around the div stretches across the entire page width. This occurs in both IE and Firefox.

建议?

推荐答案

如果您为元素提供绝对定位,则在Firefox中将为 50%。但是,IE不喜欢 min-width min-height 属性,因此您必须定义width 50%也可以在IE中使用。

If you provide absolute positioning to the element, it will be 50% in Firefox. However, IE doesn't like the min-width or min-height attributes, so you will have to define width as 50% also for it to work in IE.

这篇关于为什么CSS min-width属性不强制div具有指定的最小宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆