1.塊級元素和行內元素分別有哪些?動手測試并列出4條以上的特性區別
塊級元素 | 行內元素 |
---|---|
block-level | inline-level |
塊級可以包含塊級和行內 | 行內只能包含行內和文本 |
塊級占據一整行空間 | 行內占據自身寬度空間 |
包含標簽:div,h1~h6,p,hr,form,ul,dl,ol,pre,table,li,dd,dt,tr,td,th | em,strong,span,a,br,img,button,input,lable,select, </br> textarea,code,script |
可以設置上下左右外邊距 | 直客設置左右外邊距,設置上下內邊距有效但不占高度 |
寬度默認占整行 | 寬度自適應大小 |
2.什么是 CSS 繼承? 哪些屬性能繼承,哪些不能?
- css繼承:與text文本相關的屬性
- 可繼承的:color、font、font-family、font-size、font-style、font-variant、font-weight、text-decoration、text-transform、direction、letter-spacing、word-spacing、white-space、line-height、list-style、list-style-type、list-style-position、list-style-image。
- 不可繼承: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。
3.如何讓塊級元素水平居中?如何讓行內元素水平居中?
塊級元素水平居中的方法:
box.{
margin:0 auto
}
行內元素水平居中的方法:
h1 {
text-align: center
}
4.用 CSS 實現一個三角形
5.單行文本溢出加 ...如何實現?
在需要加“...”的地方加以下代碼
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
6.px, em, rem 有什么區別
px:固定單位
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都是宋體的意思。加引號是為了讓瀏覽器識別'Hiragino Sans GB'、'\5b8b\4f53'是一個字體不是兩個字體;'\5b8b\4f53'是uincode的編碼,在瀏覽器不兼容字體時候起到良好展現字體避免亂碼的作用。
代碼題:
1.http://js.jirengu.com/poriwahapi/2/edit?html,css,output
2.http://js.jirengu.com/yedabirepi/1/edit?html,css,output
3.http://js.jirengu.com/tevabuxuyo/1/edit?html,css,output