CSS / HTML复杂形状

时间:2016-08-04 15:02:22

标签: html css css-shapes

创建以下形状的最佳方法是什么?enter image description here

3 个答案:

答案 0 :(得分:7)

您可以使用一个元素以及:before:after伪元素执行此操作。



.el {
  position: relative;
  display: inline-block;
  text-align: center;
  line-height: 100px;
  background: #89C3EE;
  margin: 50px 150px;
  width: 100px;
  height: 100px;
  border: 3px solid #6295DC;
  border-radius: 50%;
}
.el:before,
.el:after {
  content: 'Text';
  position: absolute;
  height: 50px;
  line-height: 50px;
  width: 100px;
  top: 50%;
  transform: translateY(-50%);
  background: #89C3EE;
  border-top: 3px solid #6295DC;
  border-bottom: 3px solid #6295DC;
}
.el:before {
  width: 150px;
  left: -143px;
}
.el:after {
  right: -94px;
}

<div class="el">Text</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

您可以查看以下codepen

  <div class="bar">
     <div class="left">
       left Text
  </div> 

 <div class="cirlce">
    Circle
  </div>

 <div class="right">
   Right Text
 </div> 
</div>

CSS

.bar{
  margin-top:40px;
  width:100%;
  background:#ddd;
  height:80px;
  position:relative;
text-align:center;
}

.cirlce{
  width:140px;
  height:140px;
  background:#ccc;
  margin:0 auto;
  position:absolute;
  top:-30px;
  left:0;
  right:0;
  border-radius:50%
}

.left{
  left:0;
  position: absolute;
}

.right{
  right:0;
  position: absolute;
}

http://codepen.io/sajiddesigner/pen/NAORAv

答案 2 :(得分:1)

一种方法是将3个单独divs分开,并将中间一个border-radius

正如您从下面的代码段中看到的,这将使您能够在每列中包含多个段落(如果您需要它们)。

示例:

&#13;
&#13;
div {
position: relative;
display: inline-block;
width: 29vw;
padding: 2vw 1vw;
color: rgb(255,255,255);
font-size: 1vw;
background-color: rgb(255,0,0);
vertical-align: middle;
}

div p {
position: relative;
z-index: 12;
width: 22vw;
margin: 1vw auto;
}

div:nth-of-type(2) {
left: -7.5vw;
height: 26vw;
padding-top: 4vw;
text-align: center;
border-radius: 50%;
}

div:nth-of-type(2) p {
width: 15vw;
}

div:nth-of-type(3) {
left: -15vw;
text-align: right;
}
&#13;
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
<p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>

<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
<p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>

<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
<p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
&#13;
&#13;
&#13;