如何让 css 框扩展浏览器窗口的整个宽度?
例如,如果您查看 Facebook,它们顶部有一个短蓝色条,延伸了浏览器的整个宽度。我考虑过使用 width:100%;但我知道它需要有一个父元素才能做到这一点。
For example, if you look at Facebook, they have a short blue bar on top that extends the entire width of the browser. I thought about using width:100%; but I know that it needs to have a parent element to be able to do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
单程:
One way:
文档本身充当父元素。默认情况下,div 的宽度是其父级宽度的 100%。
您可能需要做的是在
body
元素上不设置边距或填充。演示位于 http://www.coffeepowered.net/projects/navstrip.html
如果你使用 CSS 重置,那么这应该可以工作。
The document itself acts as a parent element. Divs, by default, are 100% of their parent's width.
What you probably need to do is set no margin or padding on the
body
element.Demo at http://www.coffeepowered.net/projects/navstrip.html
If you use a CSS reset, then this should Just Work.