html中設(shè)置input寬度的方法:1、給input元素設(shè)置width屬性,語(yǔ)法“<input width="寬度值">”;2、給input元素添加width樣式,語(yǔ)法“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 屬性是一個(gè)好習(xí)慣。如果設(shè)置了這些屬性,當(dāng)頁(yè)面加載時(shí)會(huì)為圖片預(yù)留需要的空間。而如果沒(méi)有這些屬性,則瀏覽器就無(wú)法了解圖像的尺寸,也就無(wú)法為其預(yù)留合適的空間。情況是當(dāng)頁(yè)面和圖片加載時(shí),頁(yè)面布局會(huì)發(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視頻教程》