域名注冊 網(wǎng)站制作
您現(xiàn)在的位置:首頁 >> 網(wǎng)站建設(shè) >> 內(nèi)容

十天學(xué)會web標準div+css 表單設(shè)計

時間:2014/11/18 11:58:15 點擊:312

摘要:十天學(xué)會web標準div+css 表單設(shè)計,包含以下內(nèi)容和知識點:一、改變文本框和文本域樣式 二、用圖片美化按鈕 三、改變下拉列表樣式 四、用label標簽提升用戶體驗 一、改變...

十天學(xué)會web標準div+css 表單設(shè)計,包含以下內(nèi)容和知識點:

  一、改變文本框和文本域樣式
  二、用圖片美化按鈕
  三、改變下拉列表樣式
  四、用label標簽提升用戶體驗

一、改變文本框和文本域樣式

如果前邊幾章學(xué)習(xí)的比較扎實的話,本節(jié)教程就相當(dāng)容易了。下邊先說一下文本框,文本框和文本域都是可以用css進行美化的。比如改變邊框精細,顏色,添加背景色、背景圖像等。請看下邊的實例:

十天學(xué)會web標準div+css 表單設(shè)計

.text1 { border:1px solid #f60; color:#03C;}

.text2 { border:2px solid #390; width:200px; height:24px; font-size:16px; font-weight:bold; line-height:1.6;}

.text3 { border:2px solid #C3C; height:20px; background:url(icon9.gif) right 3px no-repeat;}

.text4 { border:2px solid #F60; width:150px; height:29px;font-size:16px; line-height:1.6; background:url(bg_9.gif) 0 0 no-repeat;}

這四個樣式表分別對應(yīng)第2、3、4、5行表單,第一行是文本框的默認樣式;第二行為設(shè)置邊框和字體顏色的樣式;第三行為設(shè)置邊框、寬度、高度、字體大小、行高的樣式;第四行設(shè)置邊框和增加背景色和背景圖片;第五行為增加一個gif動畫的背景圖片,看起來是不是生動許多,具體步驟不再贅述。下面我們看一下文本域的樣式設(shè)置:

十天學(xué)會web標準div+css 表單設(shè)計

.area { border:1px solid #F90; overflow:auto; background:#fff url(bg_9_1.gif) right bottom no-repeat; width:99%; height:100px;}

上圖中第一個為默認的文本域樣式,第二個為設(shè)置邊框、寬度為百分比、高度和景圖片。overflow:auto定義當(dāng)內(nèi)容不超過現(xiàn)在文本域高度時不出現(xiàn)滾動條。好了,下面運行一下代碼看看兩者的效果吧

<!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=gb2312" />

<style type="text/css">

.text1 { border:1px solid #f60; color:#03C;}

.text2 { border:2px solid #390; width:200px; height:24px; font-size:16px; font-weight:bold; line-height:1.6;}

.text3 { border:2px solid #C3C; height:20px; background:#ffeeff url(/upload/2010-08/28/icon9.gif) right 3px no-repeat;}

.text4 { border:2px solid #F60; width:150px; height:29px;font-size:16px; line-height:1.6; background:url(/upload/2010-08/28/bg_9.gif) 0 0 no-repeat;}

.area { border:1px solid #F90; overflow:auto; background:#fff url(/upload/2010-08/28/bg_9_1.gif) right bottom no-repeat; width:99%; height:100px;}

</style>

</head>

<body>

<p>

<input type="text" name="textfield" id="textfield" />

這是默認樣式

</p>

<p>

<input name="textfield2" type="text" id="textfield2" value="我是藍色的" />

這是改變邊框的樣式和文字顏色

</p>

<p>

<input name="textfield3" type="text" id="textfield3" value="看我大吧" />

這是改變邊框并設(shè)置高寬和字體大小的樣式

</p>

<p>

<input type="text" name="textfield4" id="textfield4" />

這是增加背景圖片實例,也可放左側(cè)

</p>

<p>

<input type="text" name="textfield5" id="textfield5" />

這是增加了一個背景圖片為gif動畫

</p>

<p>

<textarea name="textarea" id="textarea" cols="45" rows="5"></textarea>

</p>

<p>

<textarea name="textarea2" id="textarea2" cols="45" rows="5"></textarea>

</p>

</body>

</html>

提示:可以先修改部分代碼后再運行

二、用圖片美化按鈕

按鈕也是網(wǎng)頁中經(jīng)常見的元素,但默認的樣式有時候和頁面整體效果不協(xié)調(diào),需要把它美化一下,它的樣式設(shè)置和文本框如出一轍,沒有什么特別之處。下面以三個實例來說明一下:

十天學(xué)會web標準div+css 表單設(shè)計

.btn02 { background:#fff url(btn_bg2.gif) 0 0; height:22px; width:55px; color:#297405; border:1px solid #90be4a; font-size:12px; font-weight:bold; line-height:180%; cursor:pointer;}

.btn04 { background:url(btn_bg2.gif) 0 -24px; width:70px; height:22px; color:#9a4501; border:1px solid #dbb119; font-size:12px; line-height:160%; cursor:pointer;}

.btn07 { background:url(submit_bg.gif) 0px -8px; border:1px solid #cfab25; height:32px; font-weight:bold; padding-top:2px; cursor:pointer; font-size:14px; color:#660000;}

.btn08 { background:url(submit_bg.gif) 0px -64px; border:1px solid #8b9c56; height:32px; font-weight:bold; padding-top:2px; cursor:pointer; font-size:14px; color:#360;}

.btn09 { background:url(http://www.100181.com/upload/2010-08/14/014304_btn_bg.gif) 0 0 no-repeat; width:107px; height:37px; border:none; font-size:14px; font-weight:bold; color:#d84700; cursor:pointer;}

圖中的按鈕,前兩個為固定寬度,但寬度可以根據(jù)需要隨意調(diào)整;中間兩個為自適應(yīng)寬度,根據(jù)字數(shù)多少去適應(yīng);這四個樣式都是采用一個背景圖片橫向循環(huán)實現(xiàn),所以寬度不受限制,最后一個完全采用背景圖片,這樣寬度就得固定死了,要不會影響美觀。需要注意的是這種方式需要去掉按鈕邊框。

采用以上的按鈕有一個好處是當(dāng)css樣式表沒有加載上時,將會顯示為默認按鈕樣式,這樣用戶可以清楚地知道這是個按鈕,正常加載后,會使按鈕更加美觀。它和我們第五天講的css按鈕有所不同,那里的按鈕實際還是個鏈接,而這里的是按鈕元素。注:不同瀏覽器下顯示效果略有不同。

<!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=gb2312" />

<style type="text/css">

.btn02 { background:#fff url(/upload/2010-08/28/btn_bg2.gif) 0 0; height:22px; width:55px; color:#297405; border:1px solid #90be4a; font-size:12px; font-weight:bold; line-height:180%; cursor:pointer;}

.btn04 { background:url(/upload/2010-08/28/btn_bg2.gif) 0 -24px; width:70px; height:22px; color:#9a4501; border:1px solid #dbb119; font-size:12px; line-height:160%; cursor:pointer;}

.btn07 { background:url(/upload/2010-08/28/submit_bg.gif) 0px -8px; border:1px solid #cfab25; height:32px; font-weight:bold; padding-top:2px; cursor:pointer; font-size:14px; color:#660000;}

.btn08 { background:url(/upload/2010-08/28/submit_bg.gif) 0px -64px; border:1px solid #8b9c56; height:32px; font-weight:bold; padding-top:2px; cursor:pointer; font-size:14px; color:#360;}

.btn09 { background:url(http://www.100181.com/upload/2010-08/14/014304_btn_bg.gif) 0 0 no-repeat; width:107px; height:37px; border:none; font-size:14px; font-weight:bold; color:#d84700; cursor:pointer;}

</style>

</head>

<body>

<p>

<input name="button" type="submit" id="button" value="提交" />

</p>

<p>

<input name="button2" type="submit" id="button2" value="提交" />

</p>

<p>

<input name="button" type="submit" id="button" value="提交" />

</p>

<p>

<input name="button2" type="submit" id="button2" value="看看我的寬度有多寬" />

</p>

<p>

<input name="button" type="submit" id="button" value="免費注冊" />

</p>

</body>

</html>

提示:可以先修改部分代碼后再運行

三、改變下拉列表樣式

下拉列表(菜單)是大家最頭疼的一個元素,因其對許多樣式不生效,故而在頁面中顯示很丑陋,而且在IE6下總在最上層,造成許多彈出層不能把其遮擋(可惡的IE6呀),使頁面的用戶檢驗大打折扣,所以一些設(shè)計師想出了許多辦法來改變這種情況。

IE6下對下拉列表的背景和寬度樣式生效,其它絕大部分不生效,IE8下增加了對邊框和高度的支持。但這樣似乎離我們要求還很遠,所以不得不尋求其它的辦法了。先看下面三個圖,同一代碼分別在IE6、FF、IE8下顯示的差異吧。

十天學(xué)會web標準div+css 表單設(shè)計

十天學(xué)會web標準div+css 表單設(shè)計

十天學(xué)會web標準div+css 表單設(shè)計

<!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=gb2312" />

<style type="text/css">

.select { border:1px solid #f60; background:#FF9; height:30px;}

.tip { width:50px; border:1px solid #ccc; background:#fff; position:absolute; top:5px; left:70px; font-size:12px; height:100px; padding:5px;}

</style>

</head>

<body>

<p>請選擇項目:</p>

<p>

<select name="select" id="select">

<option>請選擇----------------</option>

<option>標準之路</option>

</select>

</p>

<div>看看誰能把我擋著</div>

</body>

</html>

提示:可以先修改部分代碼后再運行

在三個瀏覽器下顯示都不盡相同,所以最好是尋求其它的辦法或者使用默認樣式了。基中IE6下被遮擋可以把浮動層用iframe,因下拉列表不會跑到iframe上邊。有更高美化需求的可以用div模擬來代替下拉列表,但這種方法實現(xiàn)起來麻煩,由于時間關(guān)系,本節(jié)不過多的介紹這種方法,感興趣的朋友可以參考http://www.100181.com/class-8.html,進一步的學(xué)習(xí)。

四、用label標簽提升用戶體驗

label標簽常常被大家忽略了,合理利用會使頁面的用戶體驗得到提升,我們可以對表單的說明文字使用label標簽,這樣當(dāng)用戶點擊文字時,光標就定位到表單上了

十天學(xué)會web標準div+css 表單設(shè)計

如上圖,當(dāng)鼠標點擊姓名文字時,光標就會定位到后邊的文本框上了;點擊男女文字也會選中相應(yīng)的選項;同理,復(fù)選框和文本域也是一樣的。

<!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=gb2312" />

<style type="text/css">

</style>

</head>

<body>

<p>

<label for="name">姓名:</label>

<input type="text" name="name" id="name" />

</p>

<p>性別:

<input type="radio" name="sex" id="male" value="radio" /><label for="male">男</label>

<input type="radio" name="sex" id="female" value="radio2" /><label for="female">女</label></p>

<p>愛好:

<input type="checkbox" name="music" id="music" /><label for="music">聽音樂</label>

<input type="checkbox" name="web" id="web" /><label for="web">上網(wǎng)</label>

<input type="checkbox" name="book" id="book" /><label for="book">看書</label></p>

<p>

<label for="content">簡歷:</label>

<textarea name="content" id="content" cols="45" rows="5"></textarea>

</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

</body>

</html>

提示:可以先修改部分代碼后再運行

文章出處:標準之路 編輯:楊雨晨思

轉(zhuǎn)載請保留原文地址: http://www.fij982.cn/show-335.html

責(zé)編:王麗 作者:不詳 來源:網(wǎng)絡(luò)