带有阴影的标签仅在活动周围

时间:2015-10-05 06:36:49

标签: html css3 tabs shadow dropshadow

有没有办法只用CSS实现以下类型的阴影? enter image description here

到目前为止,我只设法在完整的盒子周围绘制阴影而没有非活动标签周围的凹槽:

http://jsfiddle.net/xypjj7uy/1/

HTML:

<div class="box">
    <div class="tabs">
        <span class="tab active">Bild</span>
        <span class="tab">Text</span>
    </div>
    <div class="content"></div>
</div>

CSS:

.box {
    width: 200px;
    height: 250px;
    box-shadow: 0 0 2.5px 2px rgba(0, 0, 0, 0.18);
    margin: 16px;
}

.tabs {
    height: 30px;
}

.tab {
    display: inline-block;
    width: calc(50% - 2px);
    height: 30px;
    text-align: center;
    line-height: 30px;
}

.tab:not(.active) {
    /* Should be removed in the final solution with correct shadows... */
    background-color: rgba(0, 0, 0, 0.18);
}

解决方案不需要处理旧版浏览器(&lt; IE 10)。

由于

1 个答案:

答案 0 :(得分:2)

使用此CSS

.tab.active {
    box-shadow: 0 -5px 2.5px 2px rgba(0, 0, 0, 0.18);
    position: relative;
    z-index: 99999;
}
.tab {
    background: #fff none repeat scroll 0 0;
    display: inline-block;
    height: 30px;
    line-height: 30px;

    text-align: center;
    width: calc(50% - 2px);

}

.content {
    box-shadow: 0 0 2.5px 2px rgba(0, 0, 0, 0.18);
    margin-top: 0;
    min-height: 50px;
    position: relative;
    z-index: 999;
}

编辑您的CSS

.box {
- Remove this-
    /*box-shadow: 0 0 2.5px 2px rgba(0, 0, 0, 0.18); */ 
    height: 250px;
    margin: 16px;
    width: 200px;
}