简体   繁体   中英

#div1's shadow spreads on #div2

I have two floated divs. They are close enough to each other. When I use box-shadow on that divs, one of the shadows spreads on the other one. I want them NOT to spread on their shadows. I've tried z-index, no hope there..

Here my code goes:

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

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/

Added another div inside the div you wanted to have shadows:

<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:

.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. Try this solution, it's working!

HTML

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

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM