html中設(shè)置input寬度的方法:1、給input元素設(shè)置width屬性,語法“<input width="寬度值">”;2、給input元素添加width樣式,語法“input{width:寬度值;}”。
本教程操作環(huán)境:windows7系統(tǒng)、CSS3&&HTML5版、Dell G3電腦。
html中設(shè)置input的寬度
方法1:利用input元素的width屬性
HTML 5 <input> width 屬性屬性規(guī)定 <input> 元素的寬度。
注意:width 屬性只適用于 <input type="image">
。
提示:為圖片指定 height 和 width 屬性是一個好習慣。如果設(shè)置了這些屬性,當頁面加載時會為圖片預留需要的空間。而如果沒有這些屬性,則瀏覽器就無法了解圖像的尺寸,也就無法為其預留合適的空間。情況是當頁面和圖片加載時,頁面布局會發(fā)生變化。
示例:
<form action="demo-form.php"> 用戶名: <input type="text" name="name"><br> 密 碼: <input type="password" name="pass"><br> <input type="image" src="img_submit.gif" alt="Submit" width="48" height="48"> <input type="image" src="img_submit.gif" alt="Submit" width="100" height="100"> </form>
效果圖:
方法2:利用css width樣式
width屬性設(shè)置元素的寬度。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style type="text/css"> #pass { width: 200px; } </style> </head> <body> <form action="demo-form.php"> 用戶名: <input type="text" name="name"><br> 密 碼: <input type="password" name="pass" id="pass"> </form> </body> </html>
效果圖:
推薦教程:《html視頻教程》