CSS3 box-shadow用于重叠的div [英] CSS3 box-shadow for overlapping-like divs

查看:232
本文介绍了CSS3 box-shadow用于重叠的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用css3实现这个效果:

I'm trying to achieve this effect with css3:

HTML代码完全像

...
<header>
    ...
</header>

<div id="wrapper">
    ...
</div>
...

,css目前为

header {
    display: block;
    width: 900px;
    height: 230px;
    margin: 0 auto;
    border: 1px solid #211C18;
    ...
    box-shadow: 2px 4px 20px #005377;
    -moz-box-shadow: 2px 4px 20px #005377;
    -webkit-box-shadow: 2px 4px 20px #005377;
}

#wrapper {
    width: 820px;    
    margin: 0 auto;
    ...
    border-right: 1px solid #211C18;
    border-bottom: 1px solid #211C18;
    border-left: 1px solid #211C18;
    ...
    box-shadow: 2px 4px 20px #005377;
    -moz-box-shadow: 2px 4px 20px #005377;
    -webkit-box-shadow: 2px 4px 20px #005377;
}



为了获得所需的结果,我需要:

In order to obtain the desired result, I need to:


  1. 隐藏主div的顶部阴影(没有问题)


我已经阅读很多了关于box-shadow,我没有找到一个解决方案真的很喜欢我...
任何想法?

I've been reading a lot about box-shadow, and I haven't found a solution that really pleases me... Any idea?

推荐答案

p>此 jsfiddle 可满足您的需求。

This jsfiddle does what you want.

它的工作方式是使用一个主要的 #wrap 元素,其中心的内容,并创建一个坐标地图的绝对定位 #main 元素。它这样做是因为它的位置:相对CSS规则。您最终得到以下标记:

The way it works is with a main #wrap element that centres the content and creates a coordinate map for the absolutely positioned #main element. It does this because of its position: relative CSS rule. You end up with the following markup:

<div id="wrap">
    <header></header>
    <div id="main"></div>
</div>

然后将标题并给定position:relative和一个z-index,以便将它堆叠在 #main 容器之上。

The header is then placed inside of this and given position: relative and a z-index to set it stacking above the #main container.

code> #main 绝对位于下面。 CSS看起来像这样:

Finally #main is absolutely positioned below the header. The CSS looks like so:

/* centre content and create coordinate map for absolutely positioned #main */
#wrap {
    width: 300px;
    margin: 20px auto;
    position: relative;
}

header, #main {
    background: #fff;

    /* rounded corners */
    border: 1px solid #211C18;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;    

    /* dropshadows */
    box-shadow: 2px 4px 20px #005377;
    -moz-box-shadow: 2px 4px 20px #005377;
    -webkit-box-shadow: 2px 4px 20px #005377;
}

header {
    display: block;
    width: 300px;
    height: 50px;

    /* stack above the #main container */
    position: relative;
    z-index: 2;
}

#main {
    width: 200px;
    height: 70px;

    /* stack below the header and underlap it...if that's even a word */
    position: absolute;
    z-index: 1;
    top: 40px;
    left: 50px;
}

这篇关于CSS3 box-shadow用于重叠的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆