简体   繁体   English

CSS 弯曲渐变和框阴影

[英]CSS curved gradients and box-shadow

Can CSS be used to make a left and right edges of a content container look like this image?可以使用 CSS 使内容容器的左右边缘看起来像这张图片吗? I have been trying to figure out a way to do this without using an image, if that is possible.如果可能的话,我一直在想办法在不使用图像的情况下做到这一点。

左右边框的图像

Here is jsFiddle that I have been working on.这是我一直在研究的 jsFiddle。 The CSS for the "top" class never gets applied. “顶级”类的 CSS 永远不会被应用。 The CSS for the "bottom" class seems to work ok though. “底部”类的 CSS 似乎工作正常。

http://jsfiddle.net/kXuQY/ http://jsfiddle.net/kXuQY/

HTML: HTML:

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

CSS: 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);
}

You can use ::before and ::after pseudo elements to achieve the effect, see here .可以使用::before::after伪元素来实现效果,看这里

Example: ( Demo )示例:(演示

HTML: HTML:

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

CSS: 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%;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM