HTML,CSS:如何将元素拉伸到页面边缘?

时间:2010-12-26 19:58:18

标签: css html stretch

我有一个绝对定位的元素,背景图像必须显示为一个小的水平条带,直到浏览器窗口的边缘,而不需要滚动条。我怎么能这样做?

2 个答案:

答案 0 :(得分:8)

leftright CSS属性设置为0

开球示例:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>SO question 4535198</title>
        <style>
            #strip {
                position: absolute;
                top: 0;
                left: 0;
                right: 0;
                height: 2px;
                background-image: url('some.png');
            }
        </style>
    </head>
    <body>
        <div id="strip"></div>
    </body>
</html>

答案 1 :(得分:1)

试试这个:

<style type="text/css">
.hrBar
{
        background-image: url('<YOUR_IMAGE_PATH>');
        background-repeat: repeat-x;
        height: 1px; // Or the Height of your Image
        position: absolute;
}
</style>
<div class="hrBar">
</div>