我是靠谱客的博主 香蕉夕阳,这篇文章主要介绍html中怎么设置input的宽度,现在分享给大家,希望可以做个参考。

本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

html中设置input的宽度

方法1:利用input元素的width属性

HTML 5 <input> width 属性属性规定 <input> 元素的宽度。

注意:width 属性只适用于 <input type="image">

提示:为图片指定 height 和 width 属性是一个好习惯。如果设置了这些属性,当页面加载时会为图片预留需要的空间。而如果没有这些属性,则浏览器就无法了解图像的尺寸,也就无法为其预留合适的空间。情况是当页面和图片加载时,页面布局会发生变化。

示例:

复制代码
1
2
3
4
5
6
<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>
登录后复制

效果图:

1.png

方法2:利用css width样式

width属性设置元素的宽度。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!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>
登录后复制

效果图:

2.png

推荐教程:《html视频教程》

以上就是html中怎么设置input的宽度的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是香蕉夕阳最近收集整理的关于html中怎么设置input的宽度的全部内容,更多相关html中怎么设置input内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(91)

评论列表共有 0 条评论

立即
投稿
返回
顶部