如何使用CSS创建紧身胸衣效果? [英] How to create a corset like effect with CSS?

查看:64
本文介绍了如何使用CSS创建紧身胸衣效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用CSS如下创建效果,最初,我想合并两个带有圆角的矩形,但是我不能用这种方式,因为它是一个锐角而不是圆角,请看一下cirle,这是最难的部分。





因此,我这样做:

1.创建一个圆角矩形作为轮廓。边框颜色为灰色。

2.在矩形的左侧中央创建一个灰色的条纹。

3.创建另一个白色的三角形以覆盖灰色第2步中的三角形带有一点偏移,以使其显示为矩形的边界。



这是效果:





我的问题是:

1.如何添加正确的部分?看来我只能在CSS选择器中同时绘制一个形状:before或:after。

2.如果我想添加边框阴影效果怎么办?如果我添加矩形阴影,则会出现白色三角形,这很难看。

3.或采用其他方法可以产生这种效果吗?



下面是代码:



  .triangle_left {宽度:600px;高度:600像素;职位:相对边距:20px自动;边框:2px实心#cccccc; / *框阴影:0px 0px 8px 1px darkgrey; * / border-radius:20px;}。triangle_left:before {content:’’;宽度:0;高度:0;边框:20px纯透明; border-left-color:#cccccc;位置:绝对;左:0;最高:50%; margin-top:-20px;}。triangle_left:在{内容之后:’’;宽度:0;高度:0;边框:18px纯透明;左边框颜色:白色;位置:绝对;左:-2px;最高:50%; margin-top:-18px;}  

 < div类= triangle_left>< / div>  




您也可以使用剪切路径来做到这一点,但在应用下拉阴影过滤器


  .box {
margin-top:50px;
border-radius:10px;
宽度:200像素;
高度:200像素;
背景:
repeating-linear-gradient(向右,金色0px,金色5px,透明5px,透明10px)中心/ 100%2px不重复,
#fff;
clip-path:polygon(
0 0,100%0,
100%calc(50%-20px),calc(100%-20px)50%,100%calc(50%+ 20px),
100%100%,0 100%,
0 calc(50%+ 20px),20px 50%,0 calc(50%-20px)
);
}

.drop {
filter:drop-shadow(0 0 5px#000);
}

body {
背景:粉红色;
}

 < div class = drop > 
< div class = box>
< / div>
< / div>


I want to create a effect as below with CSS, initially, I was thinking to merge two rectangle with rounded corner, but I can't use that way since it is a sharp angle, not rounded, look at the area in cirle, this is most hard part.

So I do it this way:
1. Create a rounded rectangle as the outline. with border color gray.
2. Create a tringle with gray color at the center of the left side of the rect.
3. Create another triangle with white color to cover the gray triangle in step 2, with a little offset, to make it appears as the border of the rect.

Here is the effect:

My question is:
1. How can I add the right part? it seems I can only draw one shap at the same time in CSS selector :before or :after.
2. What if i want to add border shadow effect? the white triangle will appear if I add shadow of the rect, it's ugly.
3. Or any other way to make this effect?

Here is the code:

.triangle_left {
  width: 600px;
  height: 600px;
  position: relative;
  margin: 20px auto;
  border: 2px solid #cccccc;
  /* box-shadow: 0px 0px 8px 1px darkgrey; */
  border-radius: 20px;
}

.triangle_left:before {
  content: '';
  width: 0;
  height: 0;
  border: 20px solid transparent;
  border-left-color: #cccccc;
  position: absolute;
  left: 0;
  top: 50%;
  margin-top: -20px;
}

.triangle_left:after {
  content: '';
  width: 0;
  height: 0;
  border: 18px solid transparent;
  border-left-color: white;
  position: absolute;
  left: -2px;
  top: 50%;
  margin-top: -18px;
}

<div class="triangle_left">

</div>

Try it here in JSFiddle

解决方案

An idea is to build the shape using gradient and rely on drop-shadow filter

.box {
  margin-top:50px;
  border-radius:10px;
  width:200px;
  height:200px;
  background:
  /*the middle line */
    repeating-linear-gradient(to right,gold 0px,gold 5px,transparent 5px,transparent 10px) center/calc(100% - 40px) 2px,
    /*The background*/
    linear-gradient(to bottom right,#fff 49%,transparent 50%) 100% calc(50% - 10px) / 20px 20px,
    linear-gradient(to top    right,#fff 49%,transparent 50%) 100% calc(50% + 10px) / 20px 20px,
    linear-gradient(to bottom left ,#fff 49%,transparent 50%) 0    calc(50% - 10px) / 20px 20px,
    linear-gradient(to top    left ,#fff 49%,transparent 50%) 0    calc(50% + 10px) / 20px 20px,
    
    linear-gradient(#fff,#fff) top    right / 20px calc(50% - 20px),
    linear-gradient(#fff,#fff) bottom right / 20px calc(50% - 20px),
    
    linear-gradient(#fff,#fff) top    left / 20px calc(50% - 20px),
    linear-gradient(#fff,#fff) bottom left / 20px calc(50% - 20px),
    
    linear-gradient(#fff,#fff) center/calc(100% - 40px) 100%;
   background-repeat:no-repeat;
   filter:drop-shadow(0 0 5px #000); 
}

body {
  background:pink;
}

<div class="box">
</div>

You can also do it with clip-path but you need an extra wrapper where you apply the drop-shadow filter

.box {
  margin-top: 50px;
  border-radius: 10px;
  width: 200px;
  height: 200px;
  background: 
   repeating-linear-gradient(to right, gold 0px, gold 5px, transparent 5px, transparent 10px) center/100% 2px no-repeat,
   #fff;
  clip-path:polygon(
  0 0,100% 0,
  100% calc(50% - 20px),calc(100% - 20px) 50%,100% calc(50% + 20px),
  100% 100%, 0 100%,
  0 calc(50% + 20px),20px 50%,0 calc(50% - 20px)
  );
}

.drop {
  filter: drop-shadow(0 0 5px #000);
}

body {
  background: pink;
}

<div class="drop">
  <div class="box">
  </div>
</div>

这篇关于如何使用CSS创建紧身胸衣效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆