我有一个绝对定位的元素,具有背景图片,必须显示为一个小型水平条,延伸到浏览器窗口的边缘,而无需滚动条。我该怎么做?
将CSS属性left
和right
都设置为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>
试试这个:
<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>