div 宽度 100% 宽
简单的问题,
如果我制作一个带有边框的 div,其中包含一些文本,则 div 框的宽度将仅与内容一样宽。
如何使 div 始终拉伸 100% 的屏幕,即使里面什么也没有。
我知道 min-width 不适用于 IE,有没有安全、稳定的方法来做到这一点?
simple question
if I make a div with border all way round with some text in, the div box will only be as wide as the content.
how do I make it that the div always stretches 100% of the screen across, even if nothing inside it.
I understand min-width doesnt work with IE, is there a safe, stable way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,
将始终占据 100% 的宽度,除非样式(css)改变它。
请记住,
是一个
block
元素。例如,如果将
的显示值设置为
inline
,则它只会占用其内容的宽度。示例:
另一方面,
只会占用与上下文一样多的宽度,因为它是一个
内联
元素。这里是一个示例。
jsFiddle
No, a
<div>
will always take up the 100% of width unless a style(css) alters it.Keep in mind that a
<div>
is ablock
element.If you set the display value of
<div>
to beinline
, for example, it would only take up the width of its content.Example:
On the otherhand,
A
<span>
will only take up as much width as the context because its aninline
element.Here is an example.
jsFiddle