Search code examples
htmlcssshadowspread

#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.


Solution

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