一、 填空題(每空4分,共24分)
1. 為div設置類a與b,應編寫HTML代碼 _<div class=”a b”>_</div>_________。
2. 設置CSS屬性clear的值為 _both___________時可清除左右兩邊浮動。
3. ____li________標簽必須直接嵌套於ul、ol中。
ul 顯示小黑點, ol 顯示 數字。
4. CSS屬性 _____margin_______可為元素設置外補丁。
5. 設置CSS屬性float的值為 ___none_________時可取消元素的浮動。
none為float默認屬性值。
6. 文字居中的CSS代碼是 ____text-align:center________。
<body>居中還需要加上 margin:auto;
二、 選擇題(每題4分,共16分)
1. 下列哪個樣式定義后,內聯(非塊狀)元素可以定義寬度和高度( C )
A. display:inline B. display:none C. display:block D. display:inheric
block元素的特點是:
總是在新行上開始;
高度,行高以及頂和底邊距都可控制;
寬度缺省是它的容器的100%,除非設定一個寬度
<div>, <p>, <h1>, <form>, <ul> 和 <li>是塊元素的例子。inline元素的特點是:
和其他元素都在一行上;
高,行高及頂和底邊距不可改變;
寬度就是它的文字或圖片的寬度,不可改變。
2. 選出你認為最合理的定義標題的方法( C )
A. <span class=”heading”>文章標題</span>
B. <p><b>文章標題</b></p>
C. <h1>文章標題</h1>
D. <strong>文章標題</strong>
3. br標簽在XHTML中語義為( A )
A.換行 B.強調 C.段落 D.標題
4. 不換行必須設置( AC )
A.word-break B.letter-spacing C.white-space D.word-spacing
5. 在使用table表現數據時,有時候表現出來的會比自己實際設置的寬度要寬,為此需要設置下面哪些屬性值( AD )
A. cellpadding=”0″ B. padding:0 C. margin:0 D. cellspacing=”0″
三、判斷題 (每題4分,共24分)
1. CSS屬性font-style 用於設置字體的粗細。 ( × )
2. CSS屬性overflow用於設置元素超過寬度時是否隱藏或顯示滾動條。 ( √ )
3. 在不涉及樣式情況下,頁面元素的優先顯示與結構擺放順序無關。 ( × )
4. 在不涉及樣式情況下,頁面元素的優先顯示與標簽選用無關。 ( √ )
5. display:inline兼容所有的瀏覽器。 ( √ )
6. input屬於窗體元素,層級顯示比flash、其它元素都高。 ( × )
四、代碼題 (每題9分,共36分)
1. 寫出ul、ol、dl三種列表的html結構。
<ul> <li></li> </ul> <ol> <li></li> </ol> <dl> <dt></dt> <dd></dd> </dl>
2. 將以下CSS代碼進行縮寫,注意要符合縮寫的規范。
a) 代碼一:
border-width:1px;
border-color:#000;
border-style:solid;
代碼一:border:1px #000 solid;
b) 代碼二:
background-position:0 0;
background-repeat:no-repeat;
background-attachment:fixed;
background-color:#f00;
background-image:url(background.gif);
代碼二:background: #f00 url(background.gif) no-repeat fixed 0 0;
c)代碼三:
font-style:italic;
font-family:"Lucida Grande",sans-serif;
font-size:1em;
font-weight:bold;
font-variant:small-caps;
line-height:140%;
代碼三:font:italic bold small-caps 1em/140% "lucida Grande",sans-serif;
d) 代碼四:
list-style-position:inside;
list-style-type:square;
list-style-image:url(image.gif);
代碼四:list-style: url(image.gif) square inside;
e)代碼五:
margin-left:20px;
margin-right:20px;
margin-bottom:5px;
margin-top:20px;
代碼五:margin:20px 20px 5px 20px;
例子 1
margin:10px 5px 15px 20px;
- 上外邊距是 10px
- 右外邊距是 5px
- 下外邊距是 15px
- 左外邊距是 20px
例子 2
margin:10px 5px 15px;
- 上外邊距是 10px
- 右外邊距和左外邊距是 5px
- 下外邊距是 15px
例子 3
margin:10px 5px;
- 上外邊距和下外邊距是 10px
- 右外邊距和左外邊距是 5px
f)代碼六
color:#336699;
color:#ffcc00;
代碼六:color:#369;color:#fc0;
3. 修改以下代碼,使其結構更加合理以及符合W3C標准。(XHTML 1.0 Strict)
代碼:
<div> <h2>Don’t buy these electronics used</h2> Money may be tight, but you may kick yourself for purchasing these electronics secondhand. Even when the price is low, the risk may be too high. <p> <img src='”album.jpg”'> </p> <p> <a href='”home.html”' target='”_blank”'>home</a><a href='”content.html”' target='”_blank”'>content</a> </p> </div>
答:
<div> <h2>Don’t buy these electronics used</h2> <p> Money may be tight, but you may kick yourself for purchasing these electronics secondhand. </p> <p> Even when the price is low, the risk may be too high. </p> <img src="album.jpg" alt="album" /> <ul> <li><a href="home.html" rel="external" title="home">home</a></li> <li><a href="content.html" rel="external" title="content">content</a></li> </ul> </div>
4. 簡述border:none以及border:0的區別,並給出使用建議。
答:border:none表示邊框樣式無,border:0表示邊框寬度為0;當定義了border:none,即隱藏了邊框的顯示,實際就是邊框寬度為0.
當定義邊框時,必須定義邊框的顯示樣式.因為邊框默認樣式為不顯示none,所以僅設置邊框寬度,由於樣式不存在,邊框的寬度也自動被設置為0.
五、勇氣拼一拼,讓你超越別人的加分題目來了! (不限於一種方法,共30分)
使用重構的方式制作出一個如下圖的水平、垂直都居中短邊為50px,長邊為150px的紅色十字架。
十字架
要求:
1.使用2個div完成
2.使用3個div完成
3.使用5個div完成
答案:
1.使用2個div完成
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>2個DIV</title> <style type="text/css"> #heng,#shu{left:50%;top:50%;position:absolute; background-color:#f00;} #shu{width:50px;height:150px;margin-left:-25px;margin-top:-75px;} #heng{width:150px;height:50px;margin-left:-75px;margin-top:-25px;background-color:#f00;} </style> </head> <body> <div id="heng"></div> <div id="shu"></div> </body> </html>
2.使用3個div完成
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> .main{width:150px; height:150px; top:50%; left:50%; position:absolute; margin:-75px 0 0 -75px; border:2px #F00 solid;} .heng{width:150px; height:50px; background:#F00; margin-top:50px;} .shu{width:50px; height:150px; background:#F00; margin-left:50px; margin-top:-100px;/*margin上邊界疊加*/} </style> <title>3個DIV</title> </head> <body> <div class="main"> <div class="heng"></div> <div class="shu"></div> </div> </body> </html>
3.使用5個div完成
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>5個DIV(www.hemin.cn)</title> <style type="text/css"> #top,#middle,#left,#right,#bottom{height:50px;width:50px;position:absolute;top:50%;left:50%;} #top{margin:-75px 0 0 -25px;background:#F00;} #middle{margin:-25px 0 0 -25px;background:#000;} #left{margin:-25px 0 0 -75px;background:#00F;} #right{margin:-25px 0 0 25px;background:#0F0;} #bottom{margin:25px 0 0 -25px;background:#FF0;} </style> </head> <body> <div id="top"></div> <div id="middle"></div> <div id="left"></div> <div id="right"></div> <div id="bottom"></div> </body> </html>