2017-07-26 62 views
1

我试图用css制作基本形状,因为我需要将它添加到网站的主页。最终版本附在图像下方。 请帮助我,我真的不知道如何实现这一目标如何用CSS制作基本形状?

CSS shape

#base { 
 
    background: #0a863d; 
 
    display: inline-block; 
 
    height: 55px; 
 
    margin-left: 20px; 
 
    margin-top: 55px; 
 
    position: relative; 
 
    width: 100px; 
 
} 
 
#base:before { 
 
    border-bottom: 35px solid #0a863d; 
 
    border-left: 50px solid transparent; 
 
    border-right: 50px solid transparent; 
 
    content: ""; 
 
    height: 0; 
 
    left: 0; 
 
    position: absolute; 
 
    top: -35px; 
 
    width: 0; 
 
}
<div id="base"></div>

回答

1

更改边框:after元素:

#base { 
 
    background: #0a863d; 
 
    display: inline-block; 
 
    height: 60px; 
 
    margin-left: 20px; 
 
    margin-top: 55px; 
 
    position: relative; 
 
    width: 100px; 
 
} 
 
#base:before { 
 
    border-left: 30px solid #0a863d; 
 
    border-top: 30px solid transparent; 
 
    border-bottom: 30px solid transparent; 
 
    content: ""; 
 
    height: 0; 
 
    position: absolute; 
 
    width: 0; 
 
    right: -30px; 
 
}
<div id="base"></div>

1

#base { 
 
    background: #0a863d; 
 
    display: inline-block; 
 
    height: 55px; 
 
    margin-left: 20px; 
 
    margin-top: 55px; 
 
    position: relative; 
 
    width: 100px; 
 
} 
 

 
#base:after { 
 
    content: ""; 
 
    width: 0; 
 
    height: 0; 
 
    border-style: solid; 
 
    border-width: 27.5px 0 27.5px 25px; 
 
    border-color: transparent transparent transparent #0a863d; 
 
    position: absolute; 
 
    right: -25px; 
 
}
<div id="base"></div>

1

#base { 
 
    background: #0a863d; 
 
    display: inline-block; 
 
    height: 50px; 
 
    margin-left: 20px; 
 
    margin-top: 55px; 
 
    position: relative; 
 
    width: 100px; 
 
} 
 
#base:before { 
 
    border-bottom: 25px solid transparent; 
 
    border-left: 50px solid #0a863d; 
 
    border-top: 25px solid transparent; 
 
    content: ""; 
 
    height: 0; 
 
    position: absolute; 
 
    left:100%; 
 
    width: 0; 
 
}
<div id="base"></div>

1

利用::before伪元素。

#base { 
 
    background: #0a863d; 
 
    display: inline-block; 
 
    height: 55px; 
 
    margin-left: 20px; 
 
    margin-top: 55px; 
 
    position: relative; 
 
    width: 100px; 
 
} 
 
#base:before { 
 
     border-bottom: 27px solid transparent; 
 
    border-left: 30px solid #0a863d; 
 
    border-right: 30px solid transparent; 
 
    border-top: 28px solid transparent; 
 
    content: ""; 
 
    height: 0; 
 
    right: -60px; 
 
    position: absolute; 
 
    top: 0px; 
 
    bottom: 0; 
 
    width: 0; 
 
    margin: auto; 
 
}
<div id="base"></div>

0

您可以通过改变marginborder性能旋转箭头:他们必须是 “旋转” 的权利(left变得toptop变得right等):

#base { 
 
    background: #0a863d; 
 
    display: inline-block; 
 
    height: 66px; 
 
    margin-top: 20px; 
 
    margin-right: 55px; 
 
    position: relative; 
 
    width: 500px; 
 
} 
 
#base:before { 
 
    border-left: 35px solid #0a863d; 
 
    border-top: 33px solid transparent; 
 
    border-bottom: 33px solid transparent; 
 
    content: ""; 
 
    height: 0; 
 
    top: 0; 
 
    position: absolute; 
 
    right: -35px; 
 
    width: 0; 
 
}
<div id="base"></div>

高度箭头可以通过调整#baseheightborder-top#base:beforeborder-bottom被改变。 (注意的border-topborder-bottom总和应该是相同height。)
宽度箭头可以通过调整width#base

的改变