1. 塊級(jí)元素和行內(nèi)元素分別有哪些?動(dòng)手測(cè)試并列出4條以上的特性區(qū)別
塊級(jí)元素:div h1 h2 h3 h4 h5 h6 p hr form ul dl ol pre table li dd dt tr td th?
行內(nèi)元素:em strong span a br img button input label select textare code script
二者區(qū)別:
a.塊級(jí)可以包括塊級(jí)和行內(nèi);行內(nèi)只能包含文本和行為
b.塊級(jí)占據(jù)一整行空間;行內(nèi)占據(jù)自身寬度空間
c塊級(jí)可以進(jìn)行寬高的設(shè)置;行內(nèi)不可以設(shè)置寬高
d.塊級(jí)可以進(jìn)行內(nèi)外邊距的設(shè)置;行內(nèi)對(duì)左右內(nèi)外邊距生效,對(duì)上下內(nèi)外邊距“在加邊框和背景色時(shí)可以看到效果,但實(shí)際上本身高度沒(méi)有變化”。
2. 什么是 CSS 繼承? 哪些屬性能繼承,哪些不能?
a.CSS繼承就是子元素繼承了父元素的CSS樣式的屬性
不可繼承的:display、margin、border、padding、background、height、min-height、max-height、width、min-width、max-width、overflow、position、left、right、top、bottom、z-index、float、clear、table-layout、vertical-align、page-break-after、page-bread-before和unicode-bidi。
所有元素可繼承:visibility和cursor。
內(nèi)聯(lián)元素可繼承:letter-spacing、word-spacing、white-space、line-height、color、font、font-family、font-size、font-style、font-variant、font-weight、text-decoration、text-transform、direction。
終端塊狀元素可繼承:text-indent和text-align。
列表元素可繼承:list-style、list-style-type、list-style-position、list-style-image。
3. 如何讓塊級(jí)元素水平居中?如何讓行內(nèi)元素水平居中?
塊級(jí)元素水平居中:margin:0,auto
行內(nèi)元素水平居中:text-align: center
4. 用 CSS 實(shí)現(xiàn)一個(gè)三角形
#triangle{
width:0;
height:0;
border-left:20px solid transparent;
border-right:20px solid transparent;
border-bottom:20px solid blue;
}
5. 單行文本溢出加...如何實(shí)現(xiàn)?
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
6. px, em, rem 有什么區(qū)別
px:固定單位。
em: 相對(duì)單位,相對(duì)父元素字體的大小。(倍數(shù))
rem:相對(duì)單位,相對(duì)于跟元素(html)字體的大小。(倍數(shù))
7. 解釋下面代碼的作用?為什么要加引號(hào)? 字體里\5b8b\4f53代表什么?
body{font:12px/1.5tahoma,arial,'Hiragino Sans GB','\5b8b\4f53',sans-serif;}
表示字體規(guī)格為:
字體大小為12px
字體行高為1.5倍字體大小
字體可在tahoma,arial,'Hiragino Sans GB','\5b8b\4f53',sans-serif 這些字體中選擇(若都不存在,則為瀏覽器默認(rèn)字體)
當(dāng)有空格或者Unicode碼時(shí),需要加引號(hào)
\5b8b\4f53是字體的Unicode碼,表示黑體