Foundation Chinese Manual
/ Foundation 表單
Foundation 表單
Foundation 表單控制會自動設(shè)置為全局樣式:
所有 <textarea>
, <select>
及 <input>
元素寬度都為 100%,且?guī)в型膺吘?、?nèi)邊距、陰影喝鼠標(biāo)移動效果。
實(shí)例
<!DOCTYPE html> <html> <head> <title>Foundation 實(shí)例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body style="padding:20px;"> <h2>表單</h2> <form> Input: <input type="text" placeholder="Name"> Textarea: <textarea rows="4" placeholder="Address"></textarea> Select: <select> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> </form> <p> Foundation 會自動渲染表單樣式。你可以移除樣式文件 foundation.min.css 來查看原生的 HTML 表單。</p> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
標(biāo)簽
在表單中使用 <label>
元素來設(shè)置標(biāo)簽,標(biāo)簽可以添加 for 屬性和 id 屬性。用戶在點(diǎn)擊標(biāo)簽或輸入域時(shí)獲取輸入框焦點(diǎn):
實(shí)例
<!DOCTYPE html> <html> <head> <title>Foundation 實(shí)例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body style="padding:20px;"> <h2>標(biāo)簽</h2> <form> <label for="name">Input <input type="text" placeholder="Name" id="name"> </label> <label for="address">Textarea <textarea rows="4" placeholder="Address" id="address"></textarea> </label> <label for="num">Select <select id="num"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> </label> </form> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
如果需要設(shè)置標(biāo)簽右對齊,可以使用 .right
類:
實(shí)例
<!DOCTYPE html> <html> <head> <title>Foundation 實(shí)例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body style="padding:20px;"> <h2>標(biāo)簽</h2> <form> <label for="name" class="right">Input <input type="text" placeholder="Name" id="name"> </label> <label for="address" class="right">Textarea <textarea rows="4" placeholder="Address" id="address"></textarea> </label> <label for="num" class="right">Select <select id="num"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> </label> </form> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
Fieldset
Foundation 渲染 <fieldset>
元素的樣式如下:
實(shí)例
<!DOCTYPE html> <html> <head> <title>Foundation 實(shí)例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body style="padding:20px;"> <h2>fieldset</h2> <form> <fieldset> <legend>fieldset Legend</legend> <label>Name <input type="text" placeholder="First Name.."> </label> <label>Email <input type="text" placeholder="Enter email.."> </label> </fieldset> </form> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
錯(cuò)誤狀態(tài)
使用 .error
類來設(shè)置錯(cuò)誤的標(biāo)簽、輸入框、文本框樣式:
實(shí)例
<!DOCTYPE html> <html> <head> <title>Foundation 實(shí)例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://static.php.cn/assets/foundation-5.5.3/foundation.min.css"> <script src="http://static.php.cn/assets/jquery/2.0.3/jquery.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/foundation.min.js"></script> <script src="http://static.php.cn/assets/foundation-5.5.3/js/vendor/modernizr.js"></script> </head> <body style="padding:20px;"> <h2>錯(cuò)誤狀態(tài)</h2> <form> <label class="error">錯(cuò)誤 <input type="text" placeholder="Name.."> </label> <small class="error">輸入錯(cuò)誤</small> <textarea rows="4" placeholder="Address"></textarea> <small class="error">輸入錯(cuò)誤</small> </form> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
![]() | 你需要使用 JavaScript 來更新用戶輸入的錯(cuò)誤狀態(tài)。 |
---|