問答
1. 塊級元素和行內元素分別有哪些?動手測試并列出4條以上的特性區別
塊級元素: p, h1~h6, div, form, ul, ol, li, address, fieldset, hr, menu, table
行內元素: strong, em, span, br(替換元素), img(..) , input, label, select, textarea, cite
區別:
塊級元素占據一整行空間,行內元素只占據自身寬度的空間,一行中可以排列多個行內元素。
塊級元素可以包含塊級元素和行內元素,行內元素只能包含行內元素和文本。
塊級元素可以設置寬高,行內元素設置寬高是無效的。
行內元素設置寬高無效(可以設置line-height)
-
margin左右有效 上下無效,設置padding時左右會把距離推開,而上下會延伸到別的行內,但不會增加上下兩行之間的距離。
2. 什么是 CSS 繼承? 哪些屬性能繼承,哪些不能?
當一個元素的可以繼承的屬性沒有設置時,默認繼承其父元素對此屬性的設置。
- 繼承性的屬性:
- 字體相關屬性:font,font-family,font-weight,font-size,font-style,font-stretch,font-size-adjust
- 文本相關屬性:text-indent(文本縮進),text-align,line-height,word-spacing,letter-spacing,text-transform,direction,color
- 元素可見性:visibility
- 表格布局屬性:caption-side,border-collapse,border-spacing,empty-cells,table-layout
- 列表布局屬性:list-style-type,list-style-image,list-style-position,list-style
- 生成內容屬性:quotes
- 光標屬性:cursor
- 頁面樣式屬性:page,page-break-inside,window,orphans
- 聲音樣式屬性:speak,speak-punctuation....
- 無繼承性的屬性
- display
- 文本屬性:vertical-align,text-shadow,text-decoration,white-space,unicode-bidi
- 盒子模型相關屬性:width,height,margin相關屬性,border相關屬性,padding相關屬性
- 背景相關屬性:background,background-XXX
- 定位屬性:float,clear,position,top,right,bottom,left,min-width,min-height,max-width,max-height,overflow,clip,z-index
- 生成內容屬性:content,counter-reset,counter-increment
- 輪廓樣式屬性:outline-style,outline=width,outline-color,outline
- 頁面樣式屬性:size,page-break-before,page-break-after
- 聲音樣式屬性:pause-before,pause-after,pause,cue-before,cue-after,cue,play-during
3. 如何讓塊級元素水平居中?如何讓行內元素水平居中?
塊級元素水平居中:設置其寬度,并把左右margin設為auto
行內元素水平居中:text-align: center;
4. 用 CSS 實現一個三角形
canvas.png
5. 單行文本溢出加 ...如何實現?
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
6. px, em, rem 有什么區別
px: 絕對/固定單位,瀏覽器默認文字大小為16px
em: 相對單位,表示當前字體大小是父容器字體大小的多少倍
rem:相對單位,表示當前字體大小是根元素(html)字體大小的多少倍
7. 解釋下面代碼的作用?為什么要加引號? 字體里\5b8b\4f53代表什么?
body{
font: 12px/1.5 tahoma,arial,'Hiragino Sans GB','\5b8b\4f53',sans-serif;
}
對body設置字體大小為12px,行高為字體大小的1.5倍,
tahoma,arial,'Hiragino Sans GB','\5b8b\4f53',sans-serif表示字體選擇的優先順序,(如果存在)排在前面的字體會優先使用
'\5b8b\4f53':是“宋體”的Unicode編碼表示