[英]'Stretching' a div to the edge of a browser
I have an absolutely positioned header with background image. 我有一个绝对定位的标题与背景图像。 I would like both divs (also with background image) "stretch" from my header to the left and right edges of the users browser without needing a scrollbar. 我希望两个div(也有背景图像)从我的标题“拉伸”到用户浏览器的左右边缘而不需要滚动条。 How could I do this? 我怎么能这样做? Thanks! 谢谢!
Use width: 100%;
使用width: 100%;
and set the position to left: 0px;
并将位置设置为left: 0px;
. 。
Check out: http://jsfiddle.net/joshcomley/ma26B/ 退房: http : //jsfiddle.net/joshcomley/ma26B/
THis is normally done with width:100%
on CSS. 这通常使用width:100%
CSS上的width:100%
。 I mean, browser nuances notwithstanding. 我的意思是,浏览器的细微差别尽管如此。
See normally a HTML page have the margins set to 5px
or something else. 通常情况下,HTML页面的边距设置为5px
或其他。 But if you want your div
element to be stretched up to the both edges do this -- 但是如果你想让你的div
元素被拉伸到两个边缘那么这样做 -
<html>
<head>
<style>
body { margin: 0px 0px 0px 0px; background: #555; }
div.element { width: 100%; display: block; background: #000; color: #fff; padding: 5px 5px;}
</style>
</head>
<body>
<div class="element">Stretched to the both edges of you HTML page!</div>
</body>
</html>
That's all just copy and past the above code in your HTML page and execute and see the magic! 这只是复制并通过HTML页面中的上述代码并执行并看到魔术!
I hope this would help! 我希望这会有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.