在CSS中的横幅中实现箭头形状 [英] Achieving arrow-like shapes in a banner in CSS
问题描述
我想使用纯CSS,没有图片来实现以下形状。
我来到以下几点。
strong> HTML 结构:
< div class =sixteen columns>
< div id =applicationStatus>
< ul>
< li class =applicationStatus>申请已收到< / li>
< li class =applicationStatusGood>语言考试< / li>
< li class =applicationStatusNoGood>口试考试< / li>
< li class =applicationStatus> Grant< / li>
< / ul>
< / div>
< / div>
这里是 CSS :
#applicationStatus {
position:relative;
width:auto;
height:140px; $ b $ d left:40px; }
ul.applicationStatus {
list-style:none; }
li.applicationStatus,li.applicationStatusGood,li.applicationStatusNoGood {
height:140px;
background-color:#767676;
display:inline-block;
/ * Dirty IE Hack * /
zoom:1;
* display:inline;
margin-right:30px;
margin-left:30px;
padding:10px;
color:white;
font-size:18px;
text-align:center;
line-height:150px;
/ * vertical-align:middle; * /}
li.applicationStatus:after,li.applicationStatusGood:after,li.applicationStatusNoGood:after {
content:;
position:absolute;
width:0;
height:0;
border-top:80px solid transparent;
border-left:30px solid#767676;
border-bottom:80px solid transparent;
margin:-10px 90px 0 10px; }
li.applicationStatus:before,li.applicationStatusGood:before,li.applicationStatusNoGood:before {
content:;
position:absolute;
width:0;
height:0;
left:0px;
border-top:80px solid transparent;
border-left:30px solid white;
border-bottom:80px solid transparent;
margin:-10px 0px 0 0px; }
li.applicationStatus:first-child,li.applicationStatusGood:first-child,li.applicationStatusNoGood:first-child {
margin-left:0px;
text-indent:30px; }
li.applicationStatus:last-child,li.applicationStatusGood:last-child,li.applicationStatusNoGood:last-child {
border-top:0px solid transparent;
border-left:0px solid transparent;
border-bottom:0px solid transparent; }
li.applicationStatusGood {
background-color:#77a942; }
li.applicationStatusGood:after {
border-left:30px solid#77a942; }
li.applicationStatusNoGood {
background-color:#c42c00; }
li.applicationStatusNoGood:after {
border-left:30px solid#c42c00; }
为什么:before
修改代码 h2>
您遇到的主要问题是您的 li $ c上没有
position:relative
$ c>元素。但还有其他事情需要调整。
我在上面的HTML中添加了您未能引用的类别到 ul
元素,所以这里是HTML:
< div class =十六列>
< div id =applicationStatus>
< ul class =applicationStatus>
< li class =applicationStatus>申请已收到< / li>
< li class =applicationStatusGood>语言考试< / li>
< li class =applicationStatusNoGood>口试考试< / li>
< li class =applicationStatus> Grant< / li>
< / ul>
< / div>
< / div>
然后,我修改你的CSS有点浓缩(如果CSS3只支持):
#applicationStatus {
position:relative;
width:auto;
height:140px; $ b $ d left:40px; }
.applicationStatus li {/ *添加了这个,并将很多代码移动到这里* /
position:relative; / *这是你的代码丢失的关键属性* /
text-indent:30px;
height:140px;
background-color:#767676;
display:inline-block;
/ * Dirty IE Hack * /
zoom:1;
* display:inline;
/ * margin-right:30px;消除这个* /
margin-left:30px;
padding:10px 10px 10px 30px; / * tweaking this * /
color:white;
font-size:18px;
text-align:center;
line-height:150px;
}
ul.applicationStatus {/ *这与您提供的HTML无关,但我将类添加到ul * /
list-style:none; }
/ *调整下面的各种事情* /
li.applicationStatus:first-child:after,li.applicationStatusGood:after,li.applicationStatusNoGood:after {
content:;
position:absolute;
width:0;
height:0;
border-top:80px solid transparent;
border-left:30px solid#767676;
border-bottom:80px solid transparent;
margin:-10px 90px 0 10px;
}
li.applicationStatus:last {
}
li.applicationStatus:last-child:before,li.applicationStatusGood:before,li.applicationStatusNoGood:before {
content:
position:absolute;
width:0;
height:0;
left:0;
border-top:80px solid transparent;
border-left:30px solid white;
border-bottom:80px solid transparent;
margin:-10px 0px 0 0px;
}
li.applicationStatus:first-child {
padding-left:10px;
margin-left:0;
}
li.applicationStatus:last-child {
padding-right:30px;
}
li.applicationStatusGood {
background-color:#77a942; }
li.applicationStatusGood:after {
border-left:30px solid#77a942; }
li.applicationStatusNoGood {
background-color:#c42c00; }
li.applicationStatusNoGood:before {
border-left:30px solid#c42c00; }
I want to achieve the following shapes using pure CSS, no images.
I've come to the following point.
Here is the HTML structure:
<div class="sixteen columns">
<div id="applicationStatus">
<ul>
<li class="applicationStatus">Application Received</li>
<li class="applicationStatusGood">Language Exam</li>
<li class="applicationStatusNoGood">Oral Exam</li>
<li class="applicationStatus">Grant</li>
</ul>
</div>
</div>
And here is the CSS:
#applicationStatus {
position: relative;
width: auto;
height: 140px;
left: 40px; }
ul.applicationStatus {
list-style: none; }
li.applicationStatus, li.applicationStatusGood, li.applicationStatusNoGood {
height: 140px;
background-color: #767676;
display: inline-block;
/* Dirty IE Hack */
zoom: 1;
*display: inline;
margin-right: 30px;
margin-left: 30px;
padding: 10px;
color: white;
font-size: 18px;
text-align: center;
line-height: 150px;
/* vertical-align: middle; */ }
li.applicationStatus:after, li.applicationStatusGood:after, li.applicationStatusNoGood:after {
content: "";
position: absolute;
width: 0;
height: 0;
border-top: 80px solid transparent;
border-left: 30px solid #767676;
border-bottom: 80px solid transparent;
margin: -10px 90px 0 10px; }
li.applicationStatus:before, li.applicationStatusGood:before, li.applicationStatusNoGood:before {
content: "";
position: absolute;
width: 0;
height: 0;
left: 0px;
border-top: 80px solid transparent;
border-left: 30px solid white;
border-bottom: 80px solid transparent;
margin: -10px 0px 0 0px; }
li.applicationStatus:first-child, li.applicationStatusGood:first-child, li.applicationStatusNoGood:first-child {
margin-left: 0px;
text-indent: 30px; }
li.applicationStatus:last-child, li.applicationStatusGood:last-child, li.applicationStatusNoGood:last-child {
border-top: 0px solid transparent;
border-left: 0px solid transparent;
border-bottom: 0px solid transparent; }
li.applicationStatusGood {
background-color: #77a942; }
li.applicationStatusGood:after {
border-left: 30px solid #77a942; }
li.applicationStatusNoGood {
background-color: #c42c00; }
li.applicationStatusNoGood:after {
border-left: 30px solid #c42c00; }
Why doesn't the :before
selector apply to all of the shapes or all in all how can I achieve what I want?
Modification of Your Code
The main issue you faced was not having position: relative
on your li
elements. But there were other things that needed tweaking too.
Here is a fiddle example to see.
I added the class you failed to reference in your HTML above to the ul
element, so here is the HTML:
<div class="sixteen columns">
<div id="applicationStatus">
<ul class="applicationStatus">
<li class="applicationStatus">Application Received</li>
<li class="applicationStatusGood">Language Exam</li>
<li class="applicationStatusNoGood">Oral Exam</li>
<li class="applicationStatus">Grant</li>
</ul>
</div>
</div>
Then I modified your CSS a bit to condense it (could be more condensed if CSS3 only was being supported):
#applicationStatus {
position: relative;
width: auto;
height: 140px;
left: 40px; }
.applicationStatus li { /* Added this and moved much code to here */
position: relative; /* this was a key property missing from your code */
text-indent: 30px;
height: 140px;
background-color: #767676;
display: inline-block;
/* Dirty IE Hack */
zoom: 1;
*display: inline;
/* margin-right: 30px; Eliminated this */
margin-left: 30px;
padding: 10px 10px 10px 30px; /* tweaked this */
color: white;
font-size: 18px;
text-align: center;
line-height: 150px;
}
ul.applicationStatus { /* this was irrelevant with the HTML you gave, but I added the class to the ul */
list-style: none; }
/* tweaked various things below here */
li.applicationStatus:first-child:after, li.applicationStatusGood:after, li.applicationStatusNoGood:after {
content: "";
position: absolute;
width: 0;
height: 0;
border-top: 80px solid transparent;
border-left: 30px solid #767676;
border-bottom: 80px solid transparent;
margin: -10px 90px 0 10px;
}
li.applicationStatus:last-child:before, li.applicationStatusGood:before, li.applicationStatusNoGood:before {
content: "";
position: absolute;
width: 0;
height: 0;
left: 0;
border-top: 80px solid transparent;
border-left: 30px solid white;
border-bottom: 80px solid transparent;
margin: -10px 0px 0 0px;
}
li.applicationStatus:first-child {
padding-left: 10px;
margin-left: 0;
}
li.applicationStatus:last-child {
padding-right: 30px;
}
li.applicationStatusGood {
background-color: #77a942; }
li.applicationStatusGood:after {
border-left: 30px solid #77a942; }
li.applicationStatusNoGood {
background-color: #c42c00; }
li.applicationStatusNoGood:after {
border-left: 30px solid #c42c00; }
这篇关于在CSS中的横幅中实现箭头形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!