border:none;與border:0;的區別體現有兩點:一是理論上的性能差異二是瀏覽器兼容性的差異。
性能差異:
【border:0;】把border設爲“0”像素雖然在頁面上看不見,但按border默認值理解,瀏覽器依然對border-width/border-color進行了渲染,即已經佔用了內存值。
【border:none;】把border設爲“none”即沒有,瀏覽器解析“none”時將不作出渲染動作,即不會消耗內存值。
兼容性差異:
兼容性差異只針對瀏覽器IE6、IE7與標籤button、input而言,在win、win7、vista 的XP主題下均會出現此情況。
【border:none;】當border爲“none”時似乎對IE6/7無效邊框依然存在,,如下例
1 |
< style type = "text/css" > |
2 |
input,button{border:none;} |
4 |
< button type = "button" >button</ button > |
5 |
< input name = "" type = "button" value = "input
button" /> |
6 |
< input name = "" type = "text" value = "input
text" /> |
【border:0;】當border爲“0”時,感覺比“none”更有效,所有瀏覽器都一致把邊框隱藏,如下例
1 |
< style type = "text/css" > |
2 |
input,button{border:0;} |
4 |
< button type = "button" >button</ button > |
5 |
< input name = "" type = "button" value = "input
button" /> |
6 |
< input name = "" type = "text" value = "input
text" /> |
總結:
對比border:0;與border:none;之間的區別在於有渲染和沒渲染,感覺他們和display:none;與 visibility:hidden;的關係類似,而對於border屬性的渲染性能對比暫時沒找測試的方法,雖然認爲他們存在渲染性能上的差異但也只能
說是理論上。
如何讓border:none;實現全兼容?只需要在同一選擇符上添加背景屬性即可,如下例
1 |
< style type = "text/css" > |
2 |
input,button{border:none;background:none;} |
4 |
< button type = "button" >button</ button > |
5 |
< input name = "" type = "button" value = "input
button" /> |
6 |
< input name = "" type = "text" value = "input
text" /> |
對於border:0;與border:none;個人更向於使用,border:none;,因爲border:none;畢竟在性能消耗沒有爭議,而且兼容性可用背景屬性解決不足以成爲障礙。而且兼容性可用背景屬性解決不足以成爲障礙。