在打开一个网页时,无论你的浏览器缩小的什么程度,都可以实现广告banner区域的图片居中显示。还可以运用定位将小的菜单栏固定到banner部分。具体代码如下(以工商银行的banner作为例子)
html代码:
<div class="pic">
<div class="pic1"><img src="img/back-img1.jpg"></div>
<div class="pic-left total">
<div class="pic-s"></div>
</div>
</div>
CSS样式:
.pic{
height: 380px;
overflow: hidden;
position: relative;}
.pic1 {
height: 380px;
width: 1900px;
position: absolute;
left: 50%;
margin-left: -950px;}
.pic .pic-left {
height: 344px;
position: relative;
margin-top: 19px;}
.pic .pic-left .pic-s{
width: 269px;
height: 344px;
background: rgba(244,231,235,0.5);}
右上角的小窗口主要是用了相对定位,因为它存在别的样式,因此用相对定位是最好的。如果用绝对定位的话,会使它原有的样式失效。