html - Div 背景阴影适合自定义 CSS 形状

标签 html css

我想要一个有小切口的盒子。这个盒子有一个形状相同的覆盖阴影。 下面是我对阴影和背景的尝试。

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/

相关文章:

javascript - 旋转后我的 div 移动位置并且永远不会返回

php - 使用 php 和 MySql 的 html 下拉列表

css - Bootstrap slider 图像在响应 View 中被拉伸(stretch)

c# - 使用 C# 代码 (ASP.net) 选择 CSS 样式

javascript - 如何添加一个 div 而不是用 jquery 替换它

jquery - 无法在顶部使用固定菜单栏制作滚动后修复的 div

css - angular-flex-layout:fxLayoutWrap 将 ... 附加到不适合的文本,而不是将文本换行到下一行

html - 如何在此下拉菜单中为链接添加样式

html - css 中的 body 和 (*) 属性

html - 使用 SVG 的最佳实践,关于高度和宽度?