javascript - CSS 曲线渐变和盒子阴影

标签 javascript html css

可以使用 CSS 使内容容器的左右边缘看起来像这张图片吗?如果可能的话,我一直在尝试找出一种不使用图像来执行此操作的方法。

image of left and right borders

这是我一直在研究的 jsFiddle。 “顶级”类的 CSS 永远不会被应用。不过,“底层”类的 CSS 似乎工作正常。

http://jsfiddle.net/kXuQY/

HTML:

<div class="drop-shadow top bottom">
  Content here.
</div>

CSS:

.drop-shadow {
/** Create container.  Box-shadow here is to color the inside of the container **/
 position:relative;
 width:50%;
 background: none repeat scroll 0 0 #FFFFFF;
 box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
 padding:3em;
 margin: 2em 20px 4em;
 text-align:center
}

.top:before,
.top:after {
  /** Generate pseudo-elements ('before' and 'after') and push them behind the container box. Position pseudo-elements ('before', and 'after') and give them dimensions **/
 content:"";
 position:absolute;
 z-index:-1;
 top:20px;
 left:0;
 width:40%;
 height:1em;
 max-width:150px;
 -webkit-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
 -moz-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
 box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
 -webkit-transform:rotate(70deg);
 -moz-transform:rotate(70deg);
 -o-transform:rotate(70deg);
 transform:rotate(70deg);
}

.top:after{
  /**One of the pseudo-elements then needs to be positioned on the other side of the element and rotated in the opposite direction. This is easily done by overriding only the properties that need to differ **/
 right:0;
 left:auto;
 -webkit-transform:rotate(-70deg);
 -moz-transform:rotate(-70deg);
 -o-transform:rotate(-70deg);
 transform:rotate(-70deg);
}

.bottom:before,
.bottom:after {
  /** Generate pseudo-elements ('before' and 'after') and push them behind the container box. Position pseudo-elements ('before', and 'after') and give them dimensions **/
 content:"";
 position:absolute;
 z-index:-2;
 top:90px;
 left:0;
 width:10%;
 max-width:150px;
 -webkit-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
 -moz-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
 box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
 -webkit-transform:rotate(99deg);
 -moz-transform:rotate(99deg);
 -o-transform:rotate(99deg);
 transform:rotate(99deg);
}

.bottom:after{
  /**One of the pseudo-elements then needs to be positioned on the other side of the element and rotated in the opposite direction. This is easily done by overriding only the properties that need to differ **/
 right:0;
 left:auto;
 -webkit-transform:rotate(-99deg);
 -moz-transform:rotate(-99deg);
 -o-transform:rotate(-99deg);
 transform:rotate(-99deg);
}

最佳答案

您可以使用::before::after 伪元素来实现效果,参见here .

示例:( Demo )

HTML:

<div id="box">
<h1>css-3-box-shadow</h1>
<p>some text</p>
</div>

CSS:

#box:before, #box:after {
    background: none repeat scroll 0 0 rgba(0, 0, 0, 0.7);
    bottom: 15px;
    box-shadow: 0 15px 10px rgba(0, 0, 0, 0.7);
    content: "";
    left: 10px;
    max-width: 300px;
    position: absolute;
    top: 80%;
    transform: rotate(-3deg);
    width: 50%;
    z-index: -1;
}

#box:after {
    left: auto;
    right: 10px;
    transform: rotate(3deg);
}

#box {
    background: none repeat scroll 0 0 #DDDDDD;
    border-radius: 4px 4px 4px 4px;
    color: rgba(0, 0, 0, 0.8);
    line-height: 1.5;
    margin: 60px auto;
    padding: 2em 1.5em;
    position: relative;
    text-shadow: 0 1px 0 #FFFFFF;
    width: 60%;
}

关于javascript - CSS 曲线渐变和盒子阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14324809/

相关文章:

javascript - OWL Carousel afterMove 获取 img alt

javascript - 如何用二维数组实例化类对象?

html - css 不同的链接样式

html - 如何制作没有文本但里面有图像的html.actionlink

javascript - facebook like box 使个人资料图片变小

javascript - parseInt()/parseFloat() 忽略非数字参数

javascript - 函数回调、局部变量和 chrome.storage.sync.get

html - 为按钮的内边距设置圆 Angular

javascript - page(height,width) 的 CSS 看起来比它实际必须的要小

javascript - 使用javascript删除div后无法读取空错误的属性 'appendChild'