0

我有一个 900px 宽度的容器,然后在里面我有一个 100% 宽度的标题,但它只占用容器的 100%,我怎样才能让它占据整个页面并忽略容器而不将它从容器中取出html标签?

#container {
width: 900px;
margin: auto;
padding: auto;
position: relative;
}

#header {
background-image: url(pat.png);
background-repeat: repeat;
padding: 0px;
margin: 0px;
height: 150px;
width: 100%;
}
4

1 回答 1

2

使用绝对定位。然后,标题元素将根据已position: relative;定义的最近父元素(默认情况下为<body>元素)调整大小和定位。像这样:

#header {
    position: absolute;
    left: 0;
    right: 0; /* it will span from the left to the right edges */
    height: 100px; /* it helps to set a fixed-sized height too, but this isn't required */
}
于 2012-09-07T22:31:55.657 回答