相邻div之间的阴影接缝 [英] Seams in shadows between adjacent divs

查看:360
本文介绍了相邻div之间的阴影接缝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相邻的元素通常看起来好像是融合的,它们之间没有线或接缝)。示例: http://jsfiddle.net/4m3L79w4/1/



但是,如果使用阴影,则不会出现这种情况。



Html:

 < div class =top>< / div> 
< div class =bottom>< / div>

Css:

 code> DIV {
background-color:#7faf7f;
width:400px;
height:50px;
position:relative;
box-shadow:0px 5px 20px 5px#000000;
}
.top {
z-index:2;
}
.bottom {
z-index:2;
}

bottom元素投影阴影在顶部两者都有相同的z-index。



JSFiddle: https ://jsfiddle.net/b4fvb7e0/1/



是否可以使两个元素之间的阴影消失,以便看起来融合?

这实际上是我试图创建的一个标题的简化版本,在一些页面应该出现融合到下一个元素。 JSFiddle with the header standalone and with the following element: http://jsfiddle.net/c8oat7vo/3/

解决方案

在顶部和底部设置一个伪元素,并在此设置阴影。



此外,将伪元素的z-index设置为-1



固定z-索引问题感谢Jose Gomez



  DIV {background-color:#7faf7f; width:400px; height:50px; position:relative;}。stack {background-color:#7f7faf;宽度:80%;身高:60%;左:10%; top:20%; box-shadow:0px 5px 20px 5px#000000; z-index:1;}。top {width:350px; margin-left:auto; margin-right:auto; z-index:auto; position:relative;}。bottom {width:100%; z-index:auto;}。top:after,.bottom:after {content:; position:absolute; top:0px; left:0px;右:0px; bottom:0px; box-shadow:0px 5px 20px 5px#000000; z-index:-1;}  

 < div class =top> < div class =stack>< / div>< / div>< div class =bottom>< / div>   


Adjacent elements typically appear as if they were fused, with no lines or seams between them). Example: http://jsfiddle.net/4m3L79w4/1/

However, this does no longer appear to be the case if shadows are in use.

Html:

<div class="top"></div>
<div class="bottom"></div>

Css:

DIV {
    background-color: #7faf7f;
    width: 400px;
    height: 50px;
    position: relative;
    box-shadow: 0px 5px 20px 5px #000000;
}
.top {
    z-index: 2;
}
.bottom {
    z-index: 2;
}

The "bottom" element projects shadow over the "top" one, even though both have the same z-index.

JSFiddle: https://jsfiddle.net/b4fvb7e0/1/

Is it possible to make the shadow between the two elements disappear, so that the look fused?

This is actually a simplified version of a header I am trying to create, which in some pages should appear fused to the next element. JSFiddle with the header standalone and with the following element: http://jsfiddle.net/c8oat7vo/3/

解决方案

Set a pseudo element on top and bottom, and in this one set the shadow.

Also, set z-index of the pseudo elements to -1

fixed z-index issue thank to Jose Gomez

DIV {
    background-color: #7faf7f;
    width: 400px;
    height: 50px;
    position: relative;
}
.stack {
    background-color: #7f7faf;
    width: 80%;
    height: 60%;
    left: 10%;
    top: 20%;
    box-shadow: 0px 5px 20px 5px #000000;
    z-index: 1;
}
.top {
    width: 350px;
    margin-left: auto;
    margin-right: auto;
    z-index: auto;
    position: relative;
}
.bottom {
    width: 100%;
    z-index: auto;
}

.top:after, .bottom:after {
    content: "";
    position: absolute;
    top: 0px; left: 0px; right: 0px; bottom: 0px;
    box-shadow: 0px 5px 20px 5px #000000;
    z-index: -1;
}

<div class="top">
    <div class="stack"></div>
</div>
<div class="bottom"></div>

这篇关于相邻div之间的阴影接缝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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