1. 塊級元素和行內元素分別有哪些?動手測試并列出4條以上的特性區(qū)別
塊級元素:div h1 h2 h3 h4 h5 h6 p hr form ul dl ol pre table li dd dt tr td th?
行內元素:em strong span a br img button input label select textare code script
二者區(qū)別:
a.塊級可以包括塊級和行內牧挣;行內只能包含文本和行為
b.塊級占據(jù)一整行空間寺晌;行內占據(jù)自身寬度空間
c塊級可以進行寬高的設置呻征;行內不可以設置寬高
d.塊級可以進行內外邊距的設置;行內對左右內外邊距生效罢浇,對上下內外邊距“在加邊框和背景色時可以看到效果陆赋,但實際上本身高度沒有變化”。
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澎羞。
內聯(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. 如何讓塊級元素水平居中浦马?如何讓行內元素水平居中?
塊級元素水平居中:margin:0时呀,auto
行內元素水平居中:text-align: center
4. 用 CSS 實現(xiàn)一個三角形
#triangle{
width:0;
height:0;
border-left:20px solid transparent;
border-right:20px solid transparent;
border-bottom:20px solid blue;
}
5. 單行文本溢出加...如何實現(xiàn)?
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
6. px, em, rem 有什么區(qū)別
px:固定單位。
em: 相對單位晶默,相對父元素字體的大小谨娜。(倍數(shù))
rem:相對單位,相對于跟元素(html)字體的大小磺陡。(倍數(shù))
7. 解釋下面代碼的作用?為什么要加引號? 字體里\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 這些字體中選擇(若都不存在趴梢,則為瀏覽器默認字體)
當有空格或者Unicode碼時,需要加引號
\5b8b\4f53是字體的Unicode碼币他,表示黑體