Show box-shadow of child element while parent element has overflow hidden?

老子叫甜甜 提交于 2021-01-28 08:05:44

问题


You can see the problem I'm having here : https://jsfiddle.net/xa6b8qmm/

I'm using overflow: hidden because I want to hide the scrollbar

However, this hides the left & right shadow of the elements.

I can't find a way to hide the scrollbar while at the same time allow for left/right sides of the box-shadow property to be visible.

Any ideas ?

CSS :

.noscrollbar {
    position: relative;
    float: left;
    height: 300px;
    width: 500px;
    overflow: hidden;
}

.scroller {
    position: relative;
    float: left;
    height: 100%;
    width: 100%;
    overflow: auto;
    padding-right: 60px;
}

.scroller div {
    float: left;
    width: 100%;
    height: 50px;
    margin-bottom: 20px;
    background-color: blue;
    box-shadow: 1px 1px 10px 1px black;
}
.scroller div:nth-child(1) {
    margin-top: 20px;
}

HTML :

<div class="noscrollbar">
    <div class="scroller">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
    </div>
</div>

回答1:


Maybe you can try like this

.scroller div {
    float: left;
    width: calc(100% - 10px);
    height: 50px;
    margin:0 5px 20px;
    background-color: blue;
    box-shadow: 1px 1px 10px 1px black;
}

margin : top rightleft bottom;

width : calculate width - margin+padding;



来源:https://stackoverflow.com/questions/32924860/show-box-shadow-of-child-element-while-parent-element-has-overflow-hidden

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!