2015-05-04 30 views
8

我想在廣告前創建廣場。像這樣image我如何使用:在屬性之前創建廣場前的廣場

enter image description here

但我不是成功與span:before屬性創建此。可以用這個創建嗎?如果是,那麼有人可以告訴我我該怎麼做?

我用簡單的CSS創建了這個。這裏是我的代碼

HTML:

<div id="five_day_table"> 
    <h3>Annual Cleaning Schedule</h3> 
    <div class="r-cl"><span></span>Forecasted Rain Clean</div> 
    <div class="m-cl"><span></span>Forecasted Manual Clean</div> 
    <div class="cm-cl"><span></span>Completed Manual Clean</div> 
    <div class="d-cl"><span></span>Forecasted Dirty Rain</div> 
</div> 

CSS

#five_day_table span { 
    width: 14px; 
    height: 14px; 
    display: block; 
    float: left; 
    margin: 1px 3px 0px 0px; 
} 
.r-cl span 
{ 
background: Blue; 
} 
.m-cl span 
{ 
background: red; 
} 
.cm-cl span 
{ 
background: green; 
} 
.d-cl span 
{ 
background: brown; 
} 

這裏的工作環節。但我只想使用這個HTML。

<div id="five_day_table"> 
    <h3>Annual Cleaning Schedule</h3> 
    <span class='one'>Forecasted Rain Clean</span> 
    <span class='two'>Forecasted Manual Clean</span> 
    <span class='three'>Completed Manual Clean</span> 
    <span class='four'>Forecasted Dirty Rain</span> 
</div> 

這怎麼可能?

回答

10

您需要添加content: ""span:before工作

#five_day_table span { 
 
    display: block; 
 
    margin: 1px 3px 0px 0px; 
 
} 
 
span:before { 
 
    content: ""; 
 
    display: inline-block; 
 
    width: 15px; 
 
    height: 15px; 
 
    margin-right: 5px; 
 
} 
 
.one:before { 
 
    background: Blue; 
 
} 
 
.two:before { 
 
    background: red; 
 
} 
 
.three:before { 
 
    background: green; 
 
} 
 
.four:before { 
 
    background: brown; 
 
}
<div id="five_day_table"> 
 
    <h3>Annual Cleaning Schedule</h3> 
 
    <span class='one'>Forecasted Rain Clean</span> 
 
    <span class='two'>Forecasted Manual Clean</span> 
 
    <span class='three'>Completed Manual Clean</span> 
 
    <span class='four'>Forecasted Dirty Rain</span> 
 

 
</div>

+0

不錯的工作..感謝名單 – MKD

1

試試這個。

CodePen Sample

你需要做的,是從跨度,並改變類中刪除寬度。請注意0​​需要有content: ''屬性才能顯示。

這裏的HTML代碼:

<div id="five_day_table"> 
    <h3>Annual Cleaning Schedule</h3> 
    <span class='one'>Forecasted Rain Clean</span> 
    <span class='two'>Forecasted Manual Clean</span> 
    <span class='three'>Completed Manual Clean</span> 
    <span class='four'>Forecasted Dirty Rain</span> 
</div> 

和CSS:

#five_day_table span { 
    height: 14px; 
    display: block; 
    margin: 1px 3px 3px 0px; 
} 
#five_day_table span:before{ 
    content: ''; 
    display: inline-block; 
    width: 14px; 
    height: 14px; 
    margin-right: 5px; 
} 
.one:before{ 
    background: Blue; 
} 
.two:before{ 
    background: red; 
} 
.three:before{ 
    background: green; 
} 
.four:before{ 
    background: brown; 
} 
1

http://jsfiddle.net/4p3632pg/

這應該是你在找什麼

#five_day_table > span { 
    display:block; 
} 
#five_day_table > span::before { 
    content:''; 
    width: 14px; 
    height: 14px; 
    display: block; 
    float: left; 
    margin: 1px 3px 0px 0px; 
} 
.one::before 
{ 
background: Blue; 
} 
.two::before 
{ 
background: red; 
} 
.three::before 
{ 
background: green; 
} 
.four::before 
{ 
background: brown; 
} 
2

span{ 
 
    display:block; 
 
} 
 

 
#five_day_table span:before { 
 
    width: 14px; 
 
    height: 14px; 
 
    display: inline-block; 
 
    margin: 1px 3px 0px 0px; 
 
    content:""; 
 
} 
 
.one:before 
 
{ 
 
background: Blue; 
 
} 
 
.two:before 
 
{ 
 
background: red; 
 
} 
 
.three:before 
 
{ 
 
background: green; 
 
} 
 
.four:before 
 
{ 
 
background: brown; 
 
}
<div id="five_day_table"> 
 
    <h3>Annual Cleaning Schedule</h3> 
 
    <span class='one'>Forecasted Rain Clean</span> 
 
    <span class='two'>Forecasted Manual Clean</span> 
 
    <span class='three'>Completed Manual Clean</span> 
 
    <span class='four'>Forecasted Dirty Rain</span> 
 
</div>

在舊CSS只需添加:before,改變blockinline-block,使其適合在一條線上,並具有對 整個span一個block和休息更改CSS選擇器:before如此即 取其各自的顏色。

4

你可以通過添加 「內容: '■';」

#five_day_table span { 
 
    width: 14px; 
 
    height: 14px; 
 
    margin: 1px 0 0px 0px; 
 
} 
 

 
#five_day_table span:before { 
 
    content: '■'; 
 
    margin-right: 2px; 
 
    font-size: 25px; 
 
    vertical-align: middle; 
 
    display: inline-block; 
 
    margin-top: -5px; 
 
} 
 

 
#five_day_table span:after { 
 
    content: ''; 
 
    display: block; 
 
    clear:both; 
 
} 
 

 
span.one:before 
 
{ 
 
color: Blue; 
 
} 
 
span.two:before 
 
{ 
 
color: red; 
 
} 
 
span.three:before 
 
{ 
 
color: green; 
 
} 
 
span.four:before 
 
{ 
 
color: brown; 
 
}
<div id="five_day_table"> 
 
    <h3>Annual Cleaning Schedule</h3> 
 
    <span class='one'>Forecasted Rain Clean</span> 
 
    <span class='two'>Forecasted Manual Clean</span> 
 
    <span class='three'>Completed Manual Clean</span> 
 
    <span class='four'>Forecasted Dirty Rain</span> 
 
</div>

+0

這是很好的答案,但他需要調整大小。 –

+0

@zlatkoVujicic我已更新我的代碼,字體大小爲25px。您可以通過增加字體大小來增加大小。 –

+0

你好,我知道,它看起來更靈活,當它完成你的方式 –