日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

【总有一些东西要弄清】——说说面试时一系列的CSS问题

發布時間:2023/12/13 63 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【总有一些东西要弄清】——说说面试时一系列的CSS问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

僅以此篇緬懷那些筆試100次,問100次的CSS問題。

問:

  CSS選擇符有哪些?哪些屬性可以繼承?優先級?內聯和important哪個優先級高?

選擇符

1通配選擇符(*)表示頁面內所有元素的樣式*{font-size:12px;margin:0;padding:0;}
2類型選擇符(body、div、p、span等)網頁中已有的標簽類型作為名稱的選擇符div{width:10px;height:10px;}
3群組選擇符(,)對一組對象同時進行相同的樣式指派a:link,a:visited{color:#fff;}
4層次選擇符(空格)包含選擇符對某對象中的子對象進行樣式指派#header top{width:100px;}
5id選擇符(#)id選擇符具有唯一性,在頁面中不能重復使用#header{width:300px;}
6class選擇符(.)可以在頁面中重復使用.title{width:300px;}
7IEhack選擇符(_、*、\0、\9\0;)兼容不同的瀏覽器.title{_width:50px;*height:30px;}

?

可繼承的屬性

azimuth, border-collapse, border-spacing,          //紅色為常用的 caption-side, color, cursor, direction, elevation, empty-cells, font-family, font-size, font-style, font-variant, font-weight, font, letter-spacing, line-height, list-style-image, list-style-position, list-style-type, list-style, orphans, pitch-range, pitch, quotes, richness, speak-header, speaknumeral, speak-punctuation, speak, speechrate, stress, text-align, text-indent, texttransform, visibility, voice-family, volume, whitespace, widows, word-spacing

優先級的四大原則

原則1:繼承沒指定的牛B

demo1:

<style type="text/css"> *{font-size:20px} .class3{ font-size: 12px; } </style>
<span class="class3">我是多大字號?</span> <!-- 運行結果:.class3{ font-size: 12px; }-->

demo2:

<style type="text/css"> #id1 #id2{font-size:20px} .class3{font-size:12px} </style> <div id="id1" class="class1"> <p id="id2" class="class2"> <span id="id3" class="class3">我是多大字號?</span> </p> </div> <!--運行結果:.class3{ font-size: 12px; }-->

原則2:#ID > .class > 標簽

demo1:

<style type="text/css"> #id3 { font-size: 25px; } .class3{ font-size: 18px; } span{font-size:12px} </style> <span id="id3" class="class3">我是多大字號?</span> <!--運行結果:#id3 { font-size: 25px; }-->

原則3:越具體越牛B

demo1:

<style type="text/css"> .class1 .class2 .class3{font-size: 25px;} .class2 .class3{font-size:18px} .class3 { font-size: 12px; } </style> <div class="class1"> <p class="class2"> <span class="class3">我是多大字號?</span> </p> </div> <!--運行結果:.class1 .class2 .class3{font-size: 25px;}-->

原則4:標簽#ID > 標簽.class

demo1:

<style type="text/css"> span#id3{font-size:18px} #id3{font-size:12px} span.class3{font-size:18px} .class3{font-size:12px} </style><span id="id3">我是多大字號?</span> <span class="class3">我是多大字號?</span> <!--運行結果:span#id3{font-size:18px} | span.class3{font-size:18px}-->

最后:當原則之前沖突的時候,原則1 >?原則2?>?原則3?>?原則4

?

!important

IE6到底認不認識!important???

  答:認識,但是有一個小bug。

例如:

<style> #ida {size:18px} .classb { font-size: 12px; } </style><div id=“ida” class=“classb”>!important測試:18px</div>

加入!important

<style> #ida{font-size:18px} .classb{ font-size: 12px !important; } </style><div id=“ida” class=“classb”>!important測試:12px</div>

IE6 BUG:

<style> .classb{ font-size: 18px !important; font-size: 12px } </style><div class=“classA”>!important測試:12px</div>

原因和辦法:

  這里在ie6下是12像素的字,而其他瀏覽器下是18px的字。

  但是當我們把樣式改一下,!important放在后面,即.classb{ font-size: 12px;font-size: 18px !important; },那么ie6下和其他瀏覽器一樣也是18px的字。

  

?

?

轉載于:https://www.cnblogs.com/ccto/archive/2013/03/19/2970309.html

總結

以上是生活随笔為你收集整理的【总有一些东西要弄清】——说说面试时一系列的CSS问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。