【发布时间】:2020-02-02 15:52:06
【问题描述】:
我正在做一个网站,我需要剪掉主体的左上角。 之后我想在主体上应用阴影。这个阴影不应该绕过原来的盒子,它应该跟随主体并带有新的切角 - 我为此使用了阴影。
我尝试使用渐变背景,但无论我尝试什么,我的标题要么与主体重叠,要么阴影不起作用
我目前的尝试是这样的:https://codepen.io/Sophvy/pen/MWgMZzG
HTML:
<div id ="main1">
<div id ="wrap"></div>
<header>
</header>
<main>
</main>
</div>
CSS:
#main1 {
height:500px;
width:500px;
position:relative;
}
#wrap {
width:500px;
height:500px;
background: linear-gradient(135deg, transparent 70px,green 0);
filter: drop-shadow(0px 0px 10px blue);
position:absolute;
}
header {
height:55px;
max-width:100%;
background-color:#eee;
position: relative;
}
我的问题是标题没有被切断,所以它只是重叠。 我尝试使用 z-index 但即使在每个元素上使用 position:absolute / relative 也无法使其工作。我查看了很多不同的想法,但没有发现任何可以处理与我的标题相同的问题。
我需要改变什么来切断主体和头部的角落,然后得到一个工作阴影?
编辑:我的解决方案
HTML:
<div id="background">
<div id ="main1">
<div id ="wrap">
<header>
header
</header>
<main>
main
</main>
</div>
</div>
</div>
CSS:
#background {
height:500px;
width:600px;
padding-top: 5px;
background-color:#bbb;
padding-bottom: 5px;
}
#main1 {
margin: 10px auto;
width: 90%;
height:400px;
text-align:right;
filter: drop-shadow(0px 0px 10px blue);
}
#wrap {
width:500px;
height:500px;
background: linear-gradient(135deg, transparent 70px,green 0);
clip-path: polygon(25% 0, 100% 0, 100% 100%, 0 100%, 0 25%);
position:absolute;
}
header {
height:55px;
max-width:100%;
background-color:#eee;
position: relative;
}
【问题讨论】:
-
使用剪辑路径而不是渐变......渐变不会被剪切,它会用透明颜色着色