1. 塊級元素和行內元素分別有哪些?動手測試并列出4條以上的特性區別
- 塊級元素(block-level):
div h1 h2 h3 h4 h5 h6 p hr
form ul dl ol pre table
li dd dt tr td th - 行內元素 (內聯元素,inline-level):
em strong span a br img
button input label select textarea
code script
區別:
- 塊級元素課包含塊級元素和行內元素,而行內元素只能包含行內元素;
- 塊級元素會占據一整行的空間,而行內元素占據的只是自身的寬度空間;
- 寬高只對塊級元素的設置生效,對行內元素無效;
- 邊距對于塊級元素上下右左都有效,而對行內元素左右生效,上下不生效;
- 塊級元素總是在新行上開始,而行內元素和其他元素都在一行;
塊級元素和行內元素可以通過display方法相互轉換,塊元素默認display:block;行內非替換元素(a,span)默認為display:inline;行內替換元素(input)默認為display:inline-block;
display:none:不顯示該元素,也不會保留該元素原先占有的文檔流位置;
display:block:轉換為塊級元素;
display:inline:轉換為行內元素;’
display:inline-block:轉換為行內塊級元素。
float(inline-block化)
把當前行內元素設置完float:left/right后,該行元素的display屬性會被賦予block值,且擁有浮動特性。行內元素去除了之間的莫名空白。position(inline-block化)
當為行內元素進行定位時,position:absolute與position:fixed都會使得原先的行內元素變成會計元素。
2. 什么是 CSS 繼承? 哪些屬性能繼承,哪些不能?
CSS繼承就是子元素繼承了父元素的CSS樣式的屬性。
- 能繼承的屬性:
字體:
font:組合字體
font-family:規定元素的字體系列
font-weight:設置字體的粗細
font-size:設置字體的尺寸
font-style:定義字體的風格
font-variant:設置小型大寫字母的字體顯示文本,這意味著所有的小寫字母均會被轉換為大寫,但是所有使用小型大寫字體的字母與其余文本相比,其字體尺寸更小。
font-stretch:對當前的 font-family 進行伸縮變形。所有主流瀏覽器都不支持。
font-size-adjust:為某個元素規定一個 aspect 值,這樣就可以保持首選字體的 x-height。文本:
text-indent:文本縮進
text-align:文本水平對齊
line-height:行高
word-spacing:增加或減少單詞間的空白(即字間隔)
letter-spacing:增加或減少字符間的空白(字符間距)
text-transform:控制文本大小寫
direction:規定文本的書寫方向
color:文本顏色列表:
list-style-type
list-style-image
list-style-position
list-style顏色:color(a標簽不能繼承父元素的字體顏色,因為a標簽有自己默認的字體顏色,會覆蓋掉繼承來的顏色)
- 不能被繼承的屬性
- display
- 盒子模型屬性
盒子模型的屬性:width、height、margin 、margin-top、margin-right、margin-bottom、margin-left、border、border-style、border-top-style、border-right-style、border-bottom-style、border-left-style、border-width、border-top-width、border-right-right、border-bottom-width、border-left-width、border-color、border-top-color、border-right-color、border-bottom-color、border-left-color、border-top、border-right、border-bottom、border-left、padding、padding-top、padding-right、padding-bottom、padding-left - 定位屬性:
float、clear、position、top、right、bottom、left、min-width、min-height、max-width、max-height、overflow、clip、z-index
如何讓塊級元素水平居中?
margin:0px auto;
如何讓行內元素水平居中?
text-align:center;
用 CSS 實現一個三角形
單行文本溢出加 ...如何實現?
溢出不換行:white-space: nowrap;
溢出隱藏:overflow:hidden;
在后面填充...:text-overflow:ellipsis;
px, em, rem 有什么區別
- px 像素點,固定單位
- em 相對父元素的大小,相對單位
- rem 相對根元素(html)的大小,相對單位
解釋下面代碼的作用?為什么要加引號? 字體里\5b8b\4f53代表什么?
body{
font: 12px/1.5 tahoma,arial,'Hiragino Sans GB','\5b8b\4f53',sans-serif;
}
字體大小設置為12px,行高為1.5倍字體大小,按順序檢索tahoma,arial,"Hiragino Sans GB','\5b8b\4f53',sans-serif,有則顯示,沒有則
默認。
因為字母之間有空格,避免歧義,所以要加上引號。
\5b8b\4f53代表宋體(Unicode碼)