8

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

4

2 回答 2

9

leftrightCSS 属性都设置为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>
于 2010-12-26T20:02:06.070 回答
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>
于 2010-12-26T20:15:11.587 回答