CSS3 信封形状

发布于 2024-12-14 22:04:47 字数 605 浏览 0 评论 0原文

正如您可能已经猜到的,该图像是邮件信封形状的一部分,如果可能的话,我想使用 CSS3 创建该形状。我已经制作了其他部分,但这个很棘手。该形状需要两侧都有三角形切口和圆角(大概是 border-radius-bottom-left/border-radius-bottom-right)。它必须具有投射小阴影的能力。

这就是我到目前为止所做的 -

#envelope {
background: #fff;
}

.closed {
width: 860px;
height: 0; 
border-top: 80px solid fff;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
-moz-box-shadow: 0 1px 5px #ccc;
-webkit-box-shadow: 0 1px 5px #ccc;
box-shadow: 0 1px 5px #ccc;
}

jsFiddle - http://jsfiddle.net/hsYUy/

As you might have guessed this image is part of a mail envelope shape which I would like to create with CSS3 if possible. I've made the other parts but this one's tricky. The shape needs both a triangular cut on both sides and rounded corners (presumably border-radius-bottom-left/border-radius-bottom-right). It also has to have the ability to cast a small shadow.

This is what I've done so far -

#envelope {
background: #fff;
}

.closed {
width: 860px;
height: 0; 
border-top: 80px solid fff;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
-moz-box-shadow: 0 1px 5px #ccc;
-webkit-box-shadow: 0 1px 5px #ccc;
box-shadow: 0 1px 5px #ccc;
}

jsFiddle - http://jsfiddle.net/hsYUy/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

苍暮颜 2024-12-21 22:04:47

这是我的尝试,只有一个 div

div {
    margin:20px;
    width:500px;
    height:60px;
    border-bottom-left-radius: 90px 200px;
    border-bottom-right-radius: 90px 200px;
    box-shadow: 0 5px 3px -5px #888,
    5px 0 3px -5px #888,
    -5px 0 3px -5px #888;    
}
<div></div>

http://jsfiddle.net/Simo990/Z8cPc/4

Here's my try, with just one div

div {
    margin:20px;
    width:500px;
    height:60px;
    border-bottom-left-radius: 90px 200px;
    border-bottom-right-radius: 90px 200px;
    box-shadow: 0 5px 3px -5px #888,
    5px 0 3px -5px #888,
    -5px 0 3px -5px #888;    
}
<div></div>

http://jsfiddle.net/Simo990/Z8cPc/4

迟月 2024-12-21 22:04:47

对伪元素使用 2D 倾斜变换的 1 元素解决方案。

演示

结果< /strong>:

envelope

HTML:

.envelope {
  overflow: hidden;
  position: relative;
  margin: 0 auto;
  width: 20em;
  height: 10em;
  border-radius: .25em;
  background: lemonchiffon;
}
.envelope:before,
.envelope:after {
  position: absolute;
  top: -.25em;
  width: 40%;
  height: 30%;
  content: '';
}
.envelope:before {
  left: 1em;
  border-radius: 0 0 0 .25em;
  box-shadow: -.2em .2em .2em dimgrey;
  transform: skewX(37.5deg);
}
.envelope:after {
  right: 1em;
  border-radius: 0 0 .25em 0;
  transform: skewX(-37.5deg);
  box-shadow: .2em .2em .2em dimgrey;
}
<div class='envelope'></div>

A 1 element solution using 2D skew transforms on pseudo-elements.

DEMO

Result:

envelope

HTML:

.envelope {
  overflow: hidden;
  position: relative;
  margin: 0 auto;
  width: 20em;
  height: 10em;
  border-radius: .25em;
  background: lemonchiffon;
}
.envelope:before,
.envelope:after {
  position: absolute;
  top: -.25em;
  width: 40%;
  height: 30%;
  content: '';
}
.envelope:before {
  left: 1em;
  border-radius: 0 0 0 .25em;
  box-shadow: -.2em .2em .2em dimgrey;
  transform: skewX(37.5deg);
}
.envelope:after {
  right: 1em;
  border-radius: 0 0 .25em 0;
  transform: skewX(-37.5deg);
  box-shadow: .2em .2em .2em dimgrey;
}
<div class='envelope'></div>

塔塔猫 2024-12-21 22:04:47

我的尝试,我只使用了 chrome 的阴影和旋转属性,但您可以为其他浏览器添加它,

http:// /jsfiddle.net/hsYUy/7/

body {
  background: #f2f2f2;
}
#content {
  width: 460px;
  margin: 0 auto;
  background: #fff;
  height: 400px;
  /* for demo */
  -moz-box-shadow: 0 1px 5px #ccc;
  -webkit-box-shadow: 0 1px 5px #ccc;
  box-shadow: 0 1px 5px #ccc;
  border-bottom-left-radius: 15px;
  -moz-border-radius-bottomleft: 15px;
  -webkit-border-bottom-left-radius: 15px;
  border-bottom-right-radius: 15px;
  -moz-border-radius-bottomright: 15px;
  -webkit-border-bottom-right-radius: 15px;
  z-index: 0;
}
.closed {
  z-index: 1;
  width: 460px;
  overflow: hidden;
  margin: 0 auto;
  height: 80px;
  margin-bottom: -5px;
}
.closed .mid {
  /*background: #fff;*/
  width: 360px;
  margin: 0 auto;
  margin-top: -70px;
  height: 80px;
  background-color: #fff;
  -moz-box-shadow: 0 1px 5px #ccc;
  -webkit-box-shadow: 0 1px 5px #ccc;
  box-shadow: 0 1px 5px #ccc;
  -webkit-border-radius: 12px;
}
.left,
.right {
  display: none;
}
.closed .right {
  display: block;
  width: 0;
  height: 100px;
  border-left: 60px solid #fff;
  border-right: 1px solid #ccc;
  margin-left: 384px;
  -webkit-transform: rotate(39deg);
  margin-top: -34px;
  box-shadow: 1px -1px 1px #ccc;
}
.closed .left {
  display: block;
  width: 0;
  height: 100px;
  border-right: 60px solid #fff;
  border-left: 1px solid #ccc;
  margin-left: 16px;
  -webkit-transform: rotate(-39deg);
  margin-top: -100px;
  box-shadow: -1px -1px 1px #ccc;
}
<div id="content">
  <div class="closed">
    <div class="right"></div>
    <div class="left"></div>
    <div class="mid"></div>
  </div>
</div>

My attempt, I only used the shadow and rotate properties for chrome, but you can add it for other browsers,

http://jsfiddle.net/hsYUy/7/

body {
  background: #f2f2f2;
}
#content {
  width: 460px;
  margin: 0 auto;
  background: #fff;
  height: 400px;
  /* for demo */
  -moz-box-shadow: 0 1px 5px #ccc;
  -webkit-box-shadow: 0 1px 5px #ccc;
  box-shadow: 0 1px 5px #ccc;
  border-bottom-left-radius: 15px;
  -moz-border-radius-bottomleft: 15px;
  -webkit-border-bottom-left-radius: 15px;
  border-bottom-right-radius: 15px;
  -moz-border-radius-bottomright: 15px;
  -webkit-border-bottom-right-radius: 15px;
  z-index: 0;
}
.closed {
  z-index: 1;
  width: 460px;
  overflow: hidden;
  margin: 0 auto;
  height: 80px;
  margin-bottom: -5px;
}
.closed .mid {
  /*background: #fff;*/
  width: 360px;
  margin: 0 auto;
  margin-top: -70px;
  height: 80px;
  background-color: #fff;
  -moz-box-shadow: 0 1px 5px #ccc;
  -webkit-box-shadow: 0 1px 5px #ccc;
  box-shadow: 0 1px 5px #ccc;
  -webkit-border-radius: 12px;
}
.left,
.right {
  display: none;
}
.closed .right {
  display: block;
  width: 0;
  height: 100px;
  border-left: 60px solid #fff;
  border-right: 1px solid #ccc;
  margin-left: 384px;
  -webkit-transform: rotate(39deg);
  margin-top: -34px;
  box-shadow: 1px -1px 1px #ccc;
}
.closed .left {
  display: block;
  width: 0;
  height: 100px;
  border-right: 60px solid #fff;
  border-left: 1px solid #ccc;
  margin-left: 16px;
  -webkit-transform: rotate(-39deg);
  margin-top: -100px;
  box-shadow: -1px -1px 1px #ccc;
}
<div id="content">
  <div class="closed">
    <div class="right"></div>
    <div class="left"></div>
    <div class="mid"></div>
  </div>
</div>

静谧幽蓝 2024-12-21 22:04:47

这里有 3 个近似 http://jsfiddle.net/JKirchartz/RNChA/ 仅使用边框半径,应该在具有正确前缀的所有浏览器中工作。

HTML:

.env {
  width: 100%;
  height: 300px;
  border: 3px solid #bbb;
  margin: 1em
}
.env_top {
  border: 0.2em solid #bbb;
  border-top: 0;
  height: 60px;
  max-width: 100%;
}
.one {
  -webkit-border-radius: 0px 0px 24px 24px / 0px 0px 200px 200px;
  -moz-border-radius: 0px 0px 24px 24px / 0px 0px 200px 200px;
  border-radius: 0px 0px 24px 24px / 0px 0px 200px 200px;
}
.two {
  -webkit-border-radius: 0px 0px 24px 24px / 0px 0px 300px 300px;
  -moz-border-radius: 0px 0px 24px 24px / 0px 0px 300px 300px;
  border-radius: 0px 0px 24px 24px / 0px 0px 300px 300px;
}
.thr {
  -webkit-border-radius: 0px 0px 100px 100px / 0px 0px 300px 300px;
  -moz-border-radius: 0px 0px 100px 100px / 0px 0px 300px 300px;
  border-radius: 0px 0px 100px 100px / 0px 0px 300px 300px;
}
<div class="env">
  <div class="env_top one"></div>
</div>
<div class="env">
  <div class="env_top two"></div>
</div>
<div class="env">
  <div class="env_top thr"></div>
</div>

Here's 3 approximations http://jsfiddle.net/JKirchartz/RNChA/ using only border-radius, should work in all browsers with the proper prefixes.

HTML:

.env {
  width: 100%;
  height: 300px;
  border: 3px solid #bbb;
  margin: 1em
}
.env_top {
  border: 0.2em solid #bbb;
  border-top: 0;
  height: 60px;
  max-width: 100%;
}
.one {
  -webkit-border-radius: 0px 0px 24px 24px / 0px 0px 200px 200px;
  -moz-border-radius: 0px 0px 24px 24px / 0px 0px 200px 200px;
  border-radius: 0px 0px 24px 24px / 0px 0px 200px 200px;
}
.two {
  -webkit-border-radius: 0px 0px 24px 24px / 0px 0px 300px 300px;
  -moz-border-radius: 0px 0px 24px 24px / 0px 0px 300px 300px;
  border-radius: 0px 0px 24px 24px / 0px 0px 300px 300px;
}
.thr {
  -webkit-border-radius: 0px 0px 100px 100px / 0px 0px 300px 300px;
  -moz-border-radius: 0px 0px 100px 100px / 0px 0px 300px 300px;
  border-radius: 0px 0px 100px 100px / 0px 0px 300px 300px;
}
<div class="env">
  <div class="env_top one"></div>
</div>
<div class="env">
  <div class="env_top two"></div>
</div>
<div class="env">
  <div class="env_top thr"></div>
</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文