HTML input width 属性

htmlweb developmentfront end technology更新于 2025/6/13 18:20:17

<input> 元素的 width 属性仅适用于图像,允许您使用 − 设置添加图像的宽度。

<input type=”image”>

HTML5 中引入的 width 属性,用作提交按钮。以下是语法 −

<input width=”pixels>

以上,width 表示以像素为单位的宽度。

现在让我们看一个实现 <input> 元素 width 属性的示例,其中设置了输入类型为图像的宽度。 −

示例

<!DOCTYPE html>
<html>
<body>
<h2>Register</h2>
<form action="" method="get">
   Id − <input type="text" name="id" placeholder="Enter UserId here..." size = "25"><br>
   Password − <input type="password" name="pwd" placeholder="Enter password here..."><br>
   DOB − <input type="date" name="dob"><br>
   Telephone − <input type="tel" name="tel" placeholder="Enter mobile number here..."><br>
   Email − <input type="email" name="email" placeholder="Enter email here..." size = "35"><br><br>
   <input type="image" src="go.jpg" alt="Submit" width="120" height="60">
</form>
</body>
</html>

输出

在上面的例子中,我们有一个带有按钮的表单,用于添加图像 −

<form action="" method="get">
   Id − <input type="text" name="id" placeholder="Enter UserId here..." size = "25"><br>
   Password − <input type="password" name="pwd" placeholder="Enter password here..."><br>
   DOB − <input type="date" name="dob"><br>
   Telephone − <input type="tel" name="tel" placeholder="Enter mobile number here..."><br>
   Email − <input type="email" name="email" placeholder="Enter email here..." size = "35"><br><br>
   <input type="image" src="go.jpg" alt="Submit" width="120" height="60">
</form>

按钮的图片已添加,表单控件输入类型为 image −

<input type="image" src="go.jpg" alt="Submit" width="120" height="60">

<input> width 属性用于设置此图片集的宽度。


相关文章


有用资源