带有阴影和边框底部

时间:2015-07-27 12:31:17

标签: jquery html css css3 css-shapes

更新所以我刚刚发现椭圆边界半径。实现了我所寻找的几乎相同的结果,但是边框随着省略号变粗,所以如果有人知道关于更好的方法,我仍然在寻找。 Here's my JSfiddle - 结果如下fiddle result

小提琴中使用的代码

border-bottom: 3px solid green;
-moz-border-radius-bottomleft: 70% 40px;
-webkit-border-bottom-left-radius: 70% 40px;
-webkit-box-shadow: 0 3px 7px 0 rgba(0,0,0,0.91) ;
box-shadow: 0 3px 7px 0 rgba(0,0,0,0.91) ;

原始帖子

我想知道是否可以创建类似于下面的形状

imgur of the shape

形状将覆盖图像。我知道我可以创建一个带有border-bottom-left-radius的再结果DIV,然后给它border-bottom: 3px solid greendrop-shadow,但是边框半径实际上并没有达到与图像中相同的“角度”以上..

我以为我会使用一个SVG,但后来我不能拥有投影..所以如果有任何方法可以使用投影创建这样的形状,我会对所有建议开放。谢谢

2 个答案:

答案 0 :(得分:9)

边界半径

您可以在右侧添加相同的样式border-radius,占用剩余的30%。



body {
  background: lightblue;
}
#box {
  width: 500px;
  height: auto;
  border-bottom: 3px solid green;
  -moz-border-radius-bottomleft: 70% 40px;
  -webkit-border-bottom-left-radius: 70% 40px;
  -moz-border-radius-bottomright: 30% 20px;
  -webkit-border-bottom-right-radius: 30% 20px;
  -webkit-box-shadow: 0 3px 7px 0 rgba(0, 0, 0, 0.91);
  box-shadow: 0 3px 7px 0 rgba(0, 0, 0, 0.91);
}

<img id="box" src="http://www.hdwallpapersinn.com/wp-content/uploads/2014/11/Sunset-Cityscape-Scene.jpg" />
&#13;
&#13;
&#13;

剪辑路径

您还可以考虑使用clip-path来获取所需的区域。遗憾的是,这并不允许box-shadows

&#13;
&#13;
body {
  background: lightblue;
}
.container {
  -webkit-clip-path: ellipse(100% 56% at 71% 39%);
  clip-path: ellipse(100% 56% at 71% 39%);
  width: 500px;
  height: auto;
  background: green;
}
img {
  -webkit-clip-path: ellipse(100% 56% at 71% 39%);
  clip-path: ellipse(100% 56% at 71% 39%);
  width: 500px;
  height: auto;
}
&#13;
<div class="container">
  <img src="http://www.hdwallpapersinn.com/wp-content/uploads/2014/11/Sunset-Cityscape-Scene.jpg" />
</div>
&#13;
&#13;
&#13;

Clip Path Support

SVG

您还可以使用SVG获得所需的形状。

&#13;
&#13;
body {
  background: lightblue;
}
&#13;
<svg width="500" height="250" viewBox="0 0 100 50">
  <defs>
    <pattern id="image" patternUnits="userSpaceOnUse" height="50" width="100">
      <image x="0" y="0" height="50" width="100" xlink:href="https://31.media.tumblr.com/cd4319a4a4ba642649bcf7936d48eec8/tumblr_inline_mn089qqjI71qz4rgp.png"></image>
    </pattern>
    <filter id="blur" x="0" y="0" width="100%" height="110%">
      <feOffset result="offOut" in="SourceAlpha" dx="0" dy="1" />
      <feGaussianBlur result="blurOut" in="offOut" stdDeviation="2" />
      <feBlend in="SourceGraphic" in2="blurOut" mode="normal" />
    </filter>
  </defs>
  <g class="curve">
    <path fill="url(#image)" filter="url(#blur)" stroke="green" stroke-width="1" d="M-1,-1 
             L-1,40 
             C-1,40 60,45 101,42 
             L101,-1z" />
  </g>
</svg>
&#13;
&#13;
&#13;

SVG符合使用要求

&#13;
&#13;
body {
  background: lightblue;
  margin: 0;
  padding: 0;
}
&#13;
<svg width="100%" viewBox="0 0 100 50" preserveAspectRatio="none" height="150px">
  <defs>
    <filter id="blur" x="0" y="0" width="100%" height="110%">
      <feOffset result="offOut" in="SourceAlpha" dx="0" dy="1" />
      <feGaussianBlur result="blurOut" in="offOut" stdDeviation="2" />
      <feBlend in="SourceGraphic" in2="blurOut" mode="normal" />
    </filter>
  </defs>
  <path fill="#ffffff" filter="url(#blur)" stroke="green" stroke-width="1" d="M-1,-1 
             L-1,40 
             C-1,40 60,45 101,42 
             L101,-1z" />
</svg>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

我使用内部阴影而不是边框​​底部,它非常诚实地保持线条的粗线(您可以尝试将box-shadow:inset的第一个值设置为1或2px,以便向右移动绿色阴影)。 JSFiddle

HTML

<div class="container">
  <div class="line-shadow"></div>
  <div class="line"></div>
</div>

CSS

.container {
    position: relative;
    width: 900px;
    height: 600px;
    overflow: hidden;
}
.line-shadow{
    position: absolute;
    bottom: 21px;
    left: -19px;
    width: 1000px;
    height: inherit;
    border-bottom-left-radius: 800px 150px;
    border-bottom-right-radius: 800px 30px;
    -webkit-box-shadow: 0 0 12px 1px #000000;
    box-shadow: 0 0 12px 1px #000000;
    background-image: url(http://filepic.ru/file/1438005661.jpg);
    background-size:  cover;
}
.line {
    position: absolute;
    bottom: 20px;
    left: -20px;
    width: 1000px;
    height: inherit;
    border-bottom-left-radius: 800px 150px;
    border-bottom-right-radius: 800px 30px;
    -webkit-box-shadow:inset 0 0 0 4px #6db43d;
    box-shadow:inset 0 0 0 4px #6db43d;
}

有一个明显的缺点 - 太多的div。但您可以尝试使用css ::after而不是一个div。