如何制作体积阴影 css
How to make volume shadow css
如何制作这样的阴影(图片示例)。我试过 after
伪元素,带有半径和剪辑,但结果还差得远。
.page{
width: 100%;
display: flex;
justify-content: center;
min-height:100%;
background: #ebebeb;
padding-top: 100px;
padding-bottom: 100px;
}
.sidebar{
width: 260px;
height: 500px;
background: #ebebeb;
position: relative;
}
.sidebar::after{
content: '';
position: absolute;
top: 0;
bottom: 0;
height: 500px;
right: 0;
width: 40px;
box-shadow: 5px 0 20px 0 rgba(0, 0, 0, 0.4);
display: block;
border-radius: 50% / 20px;
clip: rect(auto, 80px, auto, 40px);
}
<div class="page">
<div class="sidebar">Sidebar</div>
<div class="content"></div>
</div>
只把盒子阴影放在右边怎么样:
.page{
width: 100%;
display: flex;
justify-content: center;
min-height:100%;
background: #ebebeb;
padding-top: 100px;
padding-bottom: 100px;
}
.sidebar{
width: 260px;
height: 500px;
background: #ebebeb;
box-shadow: 15px 0 15px -15px rgba(0, 0, 0, 0.8);
}
<div class="page">
<div class="sidebar">Sidebar</div>
<div class="content"></div>
</div>
如果你需要在伪元素上:
.page {
width: 100%;
display: flex;
justify-content: center;
min-height: 100%;
background: #ebebeb;
padding-top: 100px;
padding-bottom: 100px;
}
.sidebar {
width: 260px;
height: 500px;
background: #ebebeb;
position: relative;
}
.sidebar:after {
content: '';
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 100%;
width: 50px;
transform: translateX(-50px);
box-shadow: 15px 0 15px -15px rgba(0, 0, 0, 0.9);
}
<div class="page">
<div class="sidebar">Sidebar</div>
<div class="content"></div>
</div>
有更多的曲线(但需要一个内部元素)
.page {
width: 100%;
display: flex;
justify-content: center;
min-height: 100%;
background: #ebebeb;
padding-top: 100px;
padding-bottom: 100px;
}
.sidebar {
width: 260px;
height: 500px;
position: relative;
}
.sidebar .inner {
min-height:100%;
background: #ebebeb;
position: relative;
z-index:2;
}
.sidebar:after {
content:'';
position: absolute;
z-index:1;
bottom: 3%;
left:100%;
transform: translateX(-18px);
width: 15px;
height: 94%;
background: #999999;
border-radius: 15px / 100%;
box-shadow: 0 0 10px 10px #999999;
}
<div class="page">
<div class="sidebar"><div class="inner">Sidebar</div></div>
<div class="content"></div>
</div>
body ,html {
height:100%;
}
.page{
width: 100%;
height:100%;
background: #ebebeb;
display:flex;
flex-direction: row;
justify-content: center;
}
.sidebar{
width: 260px;
background: #ebebeb;
position: relative;
left:0;
top:0;
height:100%;
box-shadow:5px 0px 5px #cacaca;
}
.content {
width: calc(100% - 260px);
padding-left: 25px;
background-color: #dedede;
}
<div class="page">
<div class="sidebar">Sidebar</div>
<div class="content">Content</div>
</div>
如何制作这样的阴影(图片示例)。我试过 after
伪元素,带有半径和剪辑,但结果还差得远。
.page{
width: 100%;
display: flex;
justify-content: center;
min-height:100%;
background: #ebebeb;
padding-top: 100px;
padding-bottom: 100px;
}
.sidebar{
width: 260px;
height: 500px;
background: #ebebeb;
position: relative;
}
.sidebar::after{
content: '';
position: absolute;
top: 0;
bottom: 0;
height: 500px;
right: 0;
width: 40px;
box-shadow: 5px 0 20px 0 rgba(0, 0, 0, 0.4);
display: block;
border-radius: 50% / 20px;
clip: rect(auto, 80px, auto, 40px);
}
<div class="page">
<div class="sidebar">Sidebar</div>
<div class="content"></div>
</div>
只把盒子阴影放在右边怎么样:
.page{
width: 100%;
display: flex;
justify-content: center;
min-height:100%;
background: #ebebeb;
padding-top: 100px;
padding-bottom: 100px;
}
.sidebar{
width: 260px;
height: 500px;
background: #ebebeb;
box-shadow: 15px 0 15px -15px rgba(0, 0, 0, 0.8);
}
<div class="page">
<div class="sidebar">Sidebar</div>
<div class="content"></div>
</div>
如果你需要在伪元素上:
.page {
width: 100%;
display: flex;
justify-content: center;
min-height: 100%;
background: #ebebeb;
padding-top: 100px;
padding-bottom: 100px;
}
.sidebar {
width: 260px;
height: 500px;
background: #ebebeb;
position: relative;
}
.sidebar:after {
content: '';
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 100%;
width: 50px;
transform: translateX(-50px);
box-shadow: 15px 0 15px -15px rgba(0, 0, 0, 0.9);
}
<div class="page">
<div class="sidebar">Sidebar</div>
<div class="content"></div>
</div>
有更多的曲线(但需要一个内部元素)
.page {
width: 100%;
display: flex;
justify-content: center;
min-height: 100%;
background: #ebebeb;
padding-top: 100px;
padding-bottom: 100px;
}
.sidebar {
width: 260px;
height: 500px;
position: relative;
}
.sidebar .inner {
min-height:100%;
background: #ebebeb;
position: relative;
z-index:2;
}
.sidebar:after {
content:'';
position: absolute;
z-index:1;
bottom: 3%;
left:100%;
transform: translateX(-18px);
width: 15px;
height: 94%;
background: #999999;
border-radius: 15px / 100%;
box-shadow: 0 0 10px 10px #999999;
}
<div class="page">
<div class="sidebar"><div class="inner">Sidebar</div></div>
<div class="content"></div>
</div>
body ,html {
height:100%;
}
.page{
width: 100%;
height:100%;
background: #ebebeb;
display:flex;
flex-direction: row;
justify-content: center;
}
.sidebar{
width: 260px;
background: #ebebeb;
position: relative;
left:0;
top:0;
height:100%;
box-shadow:5px 0px 5px #cacaca;
}
.content {
width: calc(100% - 260px);
padding-left: 25px;
background-color: #dedede;
}
<div class="page">
<div class="sidebar">Sidebar</div>
<div class="content">Content</div>
</div>