css怎么控制div的叠加

html-css015

css怎么控制div的叠加,第1张

css可以通过样式代码控制div叠加,具体代码如下:

.FaceDiv {

position:absolute

z-index:1000

width:248px

height:159px

}

.BackDiv {

position:relative

z-index:900

top:0px

left:0px

overflow:hidden

width:248px

height:159px

}

重叠在一起需要改变默认的布局方式,将其中一个显示在上层需要设置深度顺序,这两点分别用如下样式完成

position: absolute/*设置为绝对定位*/

z-index:999 /*设置重叠的上下次序,值越大月在上方*/示例如下

1.

创建Html元素

<div class="top">

<div class="b">我是绝对定位,并且重叠在上方</div>

<div class="a">我是默认定位</div>

</div>2.

设置css样式

div.top{margin:50pxpadding:20pxwidth:200pxheight:200pxborder:2px dashed #ebbcbe}

div.top div{width:100pxheight:100pxpadding:10pxcolor:white}

div.a{background:red}

div.b{background:greenposition:absolutetop:100pxleft:100pxz-index:999}3.

观察显示效果

如果大盒子套小盒子,可以这样:

<div style="position:relativewidth:400pxheight:300pxbackground-color:yellow">

<div style="position:absolutebottom:0left:50pxwidth:300pxheight:150pxbackground-color:red"></div>

</div>

如果两个盒子是独立的,则可以这样:

<div style="width:400pxheight:300pxbackground-color:yellow"></div>

<div style="position:relativetop:-150pxleft:50pxwidth:300pxheight:150pxbackground-color:red">2</div>

其实有N多种方式实现,上述只是其中的一两种