<ul id="g60s4"><pre id="g60s4"></pre></ul>
<strong id="g60s4"><nav id="g60s4"></nav></strong>
<ul id="g60s4"></ul>
  • <tr id="g60s4"></tr>
  • 
    
  • 或者

    CSS表單設計-Web標準(div+css)教程

    作者:月光邊境 瀏覽:177 發布時間:2018-03-27
    分享 評論 0

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

      如果前邊幾章學習的比較扎實的話,本節教程就相當容易了。下邊先說一下文本框,文本框和文本域都是可以用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: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;}

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

      

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

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

      <!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="看我大吧" />

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

      </p>

      <p>

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

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

      </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>

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

      二、用圖片美化按鈕

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

      

      .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.aa25.cn/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;}

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

      采用以上的按鈕有一個好處是當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.aa25.cn/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呀),使頁面的用戶檢驗大打折扣,所以一些設計師想出了許多辦法來改變這種情況。

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

      

      

      

      <!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模擬來代替下拉列表,但這種方法實現起來麻煩,由于時間關系,本節不過多的介紹這種方法,感興趣的朋友可以參考http://www.aa25.cn/css_example/541.shtml,進一步的學習。

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

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

      

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

      <!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">上網</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>

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


    91久久精品无码一区二区毛片| 国产在视频线精品视频二代| 国产精品JIZZ在线观看无码| 999久久久免费精品国产| 久久久无码人妻精品无码| 国产精品美女久久久久| 99精品国产一区二区三区| 国产精品igao视频| 一本一本久久a久久精品综合| 国产av一区二区三区日韩| 国产精品一区二区久久乐下载 | 国产精品反差婊在线观看| 精品成人乱色一区二区| 久久99国内精品自在现线| 香蕉国产精品频视| 久久国产精品久久久久久久久久| 亚洲伊人久久精品影院| 99精品在线播放| 99精品久久精品一区二区| 91在线视频精品| 国产在线91精品入口| 久久免费国产精品| 久久精品国产99久久丝袜| 精品无码人妻久久久久久| 国内精品久久久久久久久电影网| 久久se精品一区精品二区国产 | 久久精品九九亚洲精品| 99热在线精品免费播放6| 人妻熟妇乱又伦精品视频| 日韩精品中文字幕无码一区| 99热这里只有精品66| 久久er99热精品一区二区| 久久久久久国产精品免费无码| 精品亚洲国产成AV人片传媒| 亚洲午夜国产精品无卡| 99久热任我爽精品视频| 国内揄拍国内精品对白86| 久久久一本精品99久久精品36 | 国产精品久久久久久影视| 午夜精品久久久久久久99| 日韩精品无码专区免费播放|