简体   繁体   English

#div1的阴影散布在#div2上

[英]#div1's shadow spreads on #div2

I have two floated divs. 我有两个浮动div。 They are close enough to each other. 它们彼此足够接近。 When I use box-shadow on that divs, one of the shadows spreads on the other one. 当我在该div上使用box-shadow时,其中一个阴影会扩散到另一个阴影上。 I want them NOT to spread on their shadows. 我希望他们不要在阴影中散布。 I've tried z-index, no hope there.. 我尝试过z-index,那里没有希望。

Here my code goes: 我的代码在这里:

<div class="bloklar">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>

CSS: CSS:

.bloklar
{
    padding:0;
    position:relative;
    width:1000px;
}
.bloklar div
{
    display:block;
    padding:5px;
    margin:5px;
    width:230px;
    height:280px;
    background-color:white;
    float:left;
    font-size:20px;
    -webkit-box-shadow: 0px 0px 30px 0px rgba(50, 50, 50, 0.75);
    -moz-box-shadow:    0px 0px 30px 0px rgba(50, 50, 50, 0.75);
    z-index:2;
    box-shadow:         0px 0px 30px 0px rgba(50, 50, 50, 0.75);
}

Cheers. 干杯。

Edit: 编辑:

Here's the solution based on what you want: http://jsfiddle.net/4pc5ckps/4/ 这是根据您想要的解决方案: http : //jsfiddle.net/4pc5ckps/4/

Added another div inside the div you wanted to have shadows: 在要具有阴​​影的div内添加了另一个div:

<div class="bloklar">
<div class="shadow-container"><div></div></div>
<div class="shadow-container"><div></div></div>
<div class="shadow-container"><div></div></div>
<div class="shadow-container"><div></div></div>
<div class="shadow-container"><div></div></div>
<div class="shadow-container"><div></div></div>

Then gave the following CSS: 然后给出以下CSS:

.bloklar {
        padding:0;
        position:relative;
        width:1000px;
}

.bloklar .shadow-container {
        display:block;
        margin:5px;
        width:230px;
        height:280px;
        background-color:white;
        float:left;
        font-size:20px;
        -webkit-box-shadow: 0px 0px 30px 0px rgba(50, 50, 50, 0.75);
        -moz-box-shadow:    0px 0px 30px 0px rgba(50, 50, 50, 0.75);
        box-shadow:         0px 0px 30px 0px rgba(50, 50, 50, 0.75);
}

.bloklar .shadow-container div { 
    background-color: white;
    padding: 5px;
    margin: 0px;
    width: 100%;
    height: 100%;
    position: relative;
    box-sizing: border-box;
}

I would create a div inside that is going to cover the shadow. 我会在内部创建一个div来覆盖阴影。 Try this solution, it's working! 试试这个解决方案,它正在工作!

HTML 的HTML

<div class="bloklar">
    <div>
        <div>
            your content
        </div>
    </div>
    <div>
        <div>
            your content
        </div>
    </div>
</div>

CSS 的CSS

.bloklar {
    padding: 0;
    position: relative;
    width: 1000px;
}

.bloklar > div {
    display: block;
    margin: 5px;
    width: 240px;
    height: 290px;
    float: left;
    font-size: 20px;
    -webkit-box-shadow: 0px 0px 30px 0px rgba(50, 50, 50, 0.75);
    -moz-box-shadow:    0px 0px 30px 0px rgba(50, 50, 50, 0.75);
    box-shadow:         0px 0px 30px 0px rgba(50, 50, 50, 0.75);
}

.bloklar > div > div {
    width: 230px;
    height: 280px;
    padding: 5px;
    background-color: #ffffff;
    z-index: 2;
    position: absolute;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何动态地将可滚动Div2内的Div1宽度更改为Div2的宽度 - How to dynamically change width of Div1 inside a scrollable Div2 to Div2's width Fade Div1 In / Out然后Fade Div2 In? - Fade Div1 In/Out Then Fade Div2 In? 为什么将div1位置设置为div2的顶部和左侧偏移+ div2的宽度而不是将其放置在右上角? - Why does setting div1 position to div2's top & left offset + div2's width not position it to the right top corner? 在div2 mousover上突出显示div1和div2,在div1 mouseover上不突出显示任何内容 - highlight div1 and div2 on div2 mousover, highlight nothing on div1 mouseover 将鼠标悬停在div2上时如何更改div1的图像? - How to change div1's image when hovering over div2? Css可见性属性div1悬停在另一个div(div2) - Css visibility property div1 hovering another div(div2) 当DIV1的高度略大于DIV2和DIV3的高度时,是否有办法将DIV4浮在同级的第一个DIV1下? - Is there a way to float a DIV4 under first DIV1 of same class when DIV1's height is slightly bigger than of DIV2 and DIV3? 关于css float为div1,div2的外观? - About css float left for div1, the appearance of div2? 使用负边距将div1粘附到div2的左侧 - Using negative margin to adhere div1 to the left of div2 计算角度div1和div2之间的距离 - Calculate distance between div1 and div2 in angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM