1.塊級元素和行內(nèi)元素分別有哪些?動手測試并列出4條以上的特性區(qū)別####
塊級元素:div h1 h2 h3 h4 h5 h6 p hr form ul dl ol pre table li dd dt tr td th blockquote address
行內(nèi)元素:em strong span a br img button iput label select textarea code script i q var cite
區(qū)別:
1.每個塊級元素都從新的一行開始,并且其后的元素也另起一行。一個塊級元素獨占一行。行內(nèi)元素只占據(jù)自身寬度空間,行內(nèi)元素和其他元素都在一行上。
2.塊級元素默認(rèn)寬度與瀏覽器寬度一樣而與內(nèi)容無關(guān)。行內(nèi)元素寬度隨著內(nèi)容增加,高度隨字體大小而改變,
2.塊級元素的高度、寬度、行高以及頂和底邊距都可設(shè)置。行內(nèi)元素不可以設(shè)置寬高,可以設(shè)置margin和padding,但是不對上下起作用,只能對左右起作用。
3.塊級元素可以包含塊級元素和行內(nèi)元素,行內(nèi)元素只能包含文本和行內(nèi)元素。
2.什么是 CSS 繼承? 哪些屬性能繼承,哪些不能?####
繼承是一種規(guī)則,它允許樣式不僅應(yīng)用于某個特定html標(biāo)簽元素,而且應(yīng)用于其后代。css的某些樣式能夠繼承。
不能繼承的:
1、display:規(guī)定元素應(yīng)該生成的框的類型
2、文本屬性:vertical-align:垂直文本對齊;text-decoration:規(guī)定添加到文本的裝飾;text-shadow:文本陰影效果;white-space:空白符的處理;unicode-bidi:設(shè)置文本的方向。
3、盒子模型的屬性: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
4、背景屬性:background、background-color、background-image、background-repeat、background-position、background-attachment
5、定位屬性:float、clear、position、top、right、bottom、left、min-width、min-height、max-width、max-height、overflow、clip、z-index
6、生成內(nèi)容屬性:content、counter-reset、counter-increment
7、輪廓樣式屬性:outline-style、outline-width、outline-color、outline
8、頁面樣式屬性:size、page-break-before、page-break-after
9、聲音樣式屬性:pause-before、pause-after、pause、cue-before、cue-after、cue、play-during
有繼承性的屬性:
1、字體系列屬性 font:組合字體;font-family:規(guī)定元素的字體系列;font-weight:設(shè)置字體的粗細(xì);font-size:設(shè)置字體的尺寸;font-style:定義字體的風(fēng)格;font-variant:設(shè)置小型大寫字母的字體顯示文本,這意味著所有的小寫字母均會被轉(zhuǎn)換為大寫,但是所有使用小型大寫字體的字母與其余文本相比,其字體尺寸更?。籪ont-stretch:對當(dāng)前的 font-family 進(jìn)行伸縮變形。所有主流瀏覽器都不支持;font-size-adjust:為某個元素規(guī)定一個 aspect 值,這樣就可以保持首選字體的 x-height;
2、文本系列屬性 text-indent:文本縮進(jìn);text-align:文本水平對齊;line-height:行高;word-spacing:增加或減少單詞間的空白(即字間隔),letter-spacing:增加或減少字符間的空白(字符間距);text-transform:控制文本大小寫;direction:規(guī)定文本的書寫方向;color:文本顏色;
3、元素可見性:visibility
4、表格布局屬性:caption-side、border-collapse、border-spacing、empty-cells、table-layout
5、列表布局屬性:list-style-type、list-style-image、list-style-position、list-style
6、生成內(nèi)容屬性:quotes
7、光標(biāo)屬性:cursor
8、頁面樣式屬性:page、page-break-inside、windows、orphans
9、聲音樣式屬性:speak、speak-punctuation、speak-numeral、speak-header、speech-rate、volume、voice-family、pitch、pitch-range、stress、richness、、azimuth、elevation
3.如何讓塊級元素水平居中?如何讓行內(nèi)元素水平居中?####
塊級元素居中:margin:0 auto;
行內(nèi)元素居中:text-align:center
4.用 CSS 實現(xiàn)一個三角形####
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style>
.triangle{
width:0px;
border-top:solid 20px transparent;
border-right:solid 20px transparent;
border-bottom:solid 20px blue ;
border-left:solid 20px blue;
}
</style>
</head>
<body>
<div class="triangle"></div>
</body>
</html>
5.單行文本溢出加 ...如何實現(xiàn)?####
white-space: nowrap;文本不折行
overflow: hidden;隱藏溢出文本
text-overflow: ellipsis;用...代表隱藏部分
6.px, em, rem 有什么區(qū)別####
px:固定單位。
em:相對單位,相對于父元素字體大小。例如父元素的 font-size為14px ,那么 1em = 14px。
rem:相對單位,相對于根元素(html)字體大小。
7.解釋下面代碼的作用?為什么要加引號? 字體里\5b8b\4f53代表什么?####
body{
font: 12px/1.5 tahoma,arial,'Hiragino Sans GB','\5b8b\4f53',sans-serif;
}
作用:設(shè)置字體大小為12px行高1.5,字體的優(yōu)先順序依次為 tahoma,arial,'Hiragino Sans GB','\5b8b\4f53',sans-serif。首選第一種字體,沒有則用第二個,依此類推。
引號里是一種字體,加引號是因為中間有空格,不加上引號會被識別成幾個或者不能識別。
\5b8b\4f53是unicode編碼,表示宋體。這種表示方法是最通用的,直接寫宋體可能瀏覽器識別不了。