我想要一个有小切口的盒子。这个盒子有一个形状相同的覆盖阴影。 下面是我对阴影和背景的尝试。
http://jsfiddle.net/roman_khrystynych/EH7mu/2/
HTML 内容
<body>
<div class="box">
<div class="background"></div>
<div class="shadow"></div>
<div class="content">
Content
</div>
</div>
</body>
CSS
body{
background: #222;
}
box{
height: 135px;
width: 450px;
}
.content{
position:absolute;
margin-left: 120px;
margin-top: -120px;
}
.background{
margin-left:50px;
position:relative;
height:135px;
width:400px;
background:#fff;
}
.background:after{
position:absolute;
bottom:0px; left:-20px;
content:".";
text-indent:-999px; overflow:hidden;
display:block;
width:0px; height:0px;
border-top: 20px solid #fff;
border-left: 20px solid transparent;
}
.background:before{
position:absolute;
top:0; left:-20px;
content:"#";
text-indent:-999px; overflow:hidden;
display:block;
background:#fff;
width:20px; height:115px;
}
.shadow
{
margin-left:30px;
width:420px;
height: 135px;
margin-top: -135px;
position:absolute;
background: -moz-linear-gradient(top, rgba(181,181,181,0) 0%, rgba(163,163,163,0) 51%, rgba(145,145,145,0.36) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(181,181,181,0)), color-stop(51%,rgba(163,163,163,0)), color-stop(100%,rgba(145,145,145,0.36))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(181,181,181,0) 0%,rgba(163,163,163,0) 51%,rgba(145,145,145,0.36) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(181,181,181,0) 0%,rgba(163,163,163,0) 51%,rgba(145,145,145,0.36) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(181,181,181,0) 0%,rgba(163,163,163,0) 51%,rgba(145,145,145,0.36) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(181,181,181,0) 0%,rgba(163,163,163,0) 51%,rgba(145,145,145,0.36) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00b5b5b5', endColorstr='#5c919191',GradientType=0 ); /* IE6-9 */
}
关于如何使阴影覆盖也包含相同的剪切有什么建议吗?有没有更简单的方法来做到这一点?
注意:分离阴影和框的原因是为了背景颜色有 jQuery 动画,而覆盖层保持不变。
最佳答案
我不清楚你真正的意图是什么。 不管怎样,既然没有人给你答案,我想我可以帮助你。
对于这个 html:
<div class="clip">
<div class="inner">aaaaa</div>
</div>
如果你给出这个CSS:
.clip {height: 173px; width: 181px; left: 85px; top: 74px;position: absolute;
overflow: hidden;
-webkit-transform: rotate(50deg);
background-color: rgba(200, 0, 0, 0.1);}
.inner {
-webkit-transform: rotate(-50deg);
background-color: blue;
height: 100px;width: 150px;left: 16px;top: 52px;position: absolute;}
您将在内部 div 中获得带有所需截断的矩形。
外部 div 已旋转并启用了裁剪,因此它可以为您提供对 Angular 线裁剪。
然后将内部矩形放置在剪辑 div 内,以便仅在左下角进行剪辑。您反向旋转该 div,使其再次水平。
现在你可以用它做任何你想做的事情(我还没有使用任何背景或边框属性),或者在另一个内部 div 中,而不会丢失形状。
请注意,定位内部 div 很棘手,您是在旋转坐标中进行的!
演示中的剪辑 div 是半透明的。
fiddle
关于html - Div 背景阴影适合自定义 CSS 形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15148421/