2014-06-22 57 views
0

我使用的後續PHP輸出我的博客上的一些重要的標籤!字體大小會變得與覆蓋

foreach ($tagvalues as $tag => $count) { 
    $size = 12 + $count * 2; 
    echo '<div class="tag" style=" font-size:' . $size . ' !important; "> ' . $tag . ' </div>'; 
} 

導致這個HTML在我的博客:

... 
<div class="tag" style=" font-size:14 !important; "> career </div> 
<div class="tag" style=" font-size:16 !important; "> parenting </div> 
... 

正如你所看到的,我試圖根據實例的數量來設置每個標籤的大小。代碼輸出罰款,但所有的標籤顯示相同的大小。當我在Chrome中使用開發人員工具查看它時,發現字體大小屬性被覆蓋掉了!這些標籤的字體大小沒有設置在其他任何地方,我真的很困惑爲什麼它被忽略/覆蓋。

You can see my site here (need to click on My Blog to load tags)

+1

試試這個'font-size:'。 $尺寸。 'px!important;' – marathonman

+0

觀察......你真的想用直接從某個計數值派生的像素大小嗎?我會弄清楚一個更強大的解決方案。下面的答案解決了你的問題。 –

回答

4

你不需要因爲CSS順序優先(你申請內嵌樣式)的!important。問題是你錯過了px

例如。

<div class="tag" style=" font-size:16px"> parenting </div>