div 宽度 100% 宽

发布于 2024-12-29 04:35:53 字数 157 浏览 1 评论 0原文

简单的问题,

如果我制作一个带有边框的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

层林尽染 2025-01-05 04:35:53

不,

将始终占据 100% 的宽度,除非样式(css)改变它。
请记住,

是一个block 元素。

例如,如果将

的显示值设置为 inline,则它只会占用其内容的宽度。

示例:

.myDiv
{
   display: inline;
}

<div class="myDiv">I will take up width of my content only</div>

另一方面,

只会占用与上下文一样多的宽度,因为它是一个内联 元素。

这里是一个示例。
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 a block element.

If you set the display value of <div> to be inline, for example, it would only take up the width of its content.

Example:

.myDiv
{
   display: inline;
}

<div class="myDiv">I will take up width of my content only</div>

On the otherhand,

A <span> will only take up as much width as the context because its an inline element.

Here is an example.
jsFiddle

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文