HTML中的表单Form实现居中效果
2021-06-06 04:12
1136 查看
之前碰到一个作业,给了一张图片,让按照图片样式做一个表单,但在所有功能都实现后,发现无法让表单居中,一直缩在左上角,看起来很难看。在经过了各种修改后,终于成功将表单居中,下面分享一下我所经历过程中的错误与最终结果。(因为做这部分作业的时候还没有学 css,所以没用)
1、刚做出来的样子
<form> <label for="firstname">名字:</label> <input type="text" name="firstname" id="firstname" required="required" value="" /><br /> <label for="lastname">姓氏:</label> <input type="text" name="lastname" id="lastname" required="required" value="" /><br /> <label for="login name">登录名:</label> <input type="text" name="login name" required="required" pattern="^\w{4,8}$" id="login name" value="" />(可包含a-z、0-9和下划线)<br /> <label for="password">密码:</label> <input type="password" name="password" required="required" pattern="^[a-zA-Z]\w{5,17}$" id="password" value="" />(至少包含6个字符)<br /> <label for="password2">再次输入密码:</label> <input type="password" name="password2" required="required" pattern="^[a-zA-Z]\w{5,17}$" id="password2" value="" /><br /> <label for="myEmail">电子邮箱:</label> <input type="email" name="myEmail" id="myEmail" value="" />(必须包含@字符) </form>
看起来很别扭,所以要继续改进一下。。。
2、经过修改后
看起来好像更别扭了,但是实现了居中,到这里时,我也不知道自己用的 < center> 对不对。。。
<center> <form> ````` ````` </ form> </ center>
3、使用表格布局后
这就是在经过了一晚上的修改后,最终呈现的结果。
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <link rel="icon" type="text/css" href="./img/favicon.png"/> <title></title> </head> <body> <center> <form action="Success.html" target="_blank" method="get"> <table border="0" cellspacing="" cellpadding=""> <tr> <td><label for="firstname">名字:</label></td> <td><input type="text" name="firstname" id="firstname" required="required" value="" /></td> </tr> <tr> <td><label for="lastname">姓氏:</label></td> <td><input type="text" name="lastname" id="lastname" required="required" value="" /></td> </tr> <tr> <td><label for="login name">登录名:</label></td> <td><input type="text" name="login name" required="required" pattern="^\w{4,8}$" id="login name" value="" />(可包含a-z、0-9和下划线)</td> </tr> <tr> <td><label for="password">密码:</label></td> <td><input type="password" name="password" required="required" pattern="^[a-zA-Z]\w{5,17}$" id="password" value="" />(至少包含6个字符)</td> </tr> <tr> <td><label for="password2">再次输入密码:</label></td> <td><input type="password" name="password2" required="required" pattern="^[a-zA-Z]\w{5,17}$" id="password2" value="" /></td> </tr> <tr> <td><label for="myEmail">电子邮箱:</label></td> <td><input type="email" name="myEmail" id="myEmail" value="" />(必须包含@字符)</td> </tr> <tr> <td><label>性别:</label></td> <td> <input type="radio" name="sex" id="" value="male" />男<img src="./img/Male.gif" > <input type="radio" name="sex" id="" value="female" />女<img src="./img/Female.gif" > </td> </tr> <tr> <td><label>头像:</label></td> <td><input type="file" name="myFile" /></td> </tr> <tr> <td><label>爱好:</label></td> <td> <input type="checkbox" name="hobby" id="" value="运动" />运动 <input type="checkbox" name="hobby" id="" value="聊天" />聊天 <input type="checkbox" name="hobby" id="" value="玩游戏" />玩游戏 </td> </tr> <tr> <td><label>出生日期:</label></td> <td> <input type="text" size="1" name="year"placeholder="yyyy" id="" value="" />年 <select name="month"> <option value ="0">[选择月份]</option> <option value ="1">1月</option> <option value ="2">2月</option> <option value ="3">3月</option> <option value ="4">4月</option> <option value ="5">5月</option> <option value ="6">6月</option> <option value ="7">7月</option> <option value ="8">8月</option> <option value ="9">9月</option> <option value ="10">10月</option> <option value ="11">11月</option> <option value ="12">12月</option> </select> <input type="text" size="1" name="day" placeholder="dd"/>日 </td> </tr> </table> <input type="image" src="img/submit.gif" value="提交" /> <input type="image" src="img/reset.gif" onclick="reset();return false;" value="重填" /> </form> </center> </body> </html>
若觉得左边的标签左对齐不好看,也可以在 < td >标签中加入align=“right”,使文字右对齐
<td align="right"><label for="firstname">名字:</label></td>
到此这篇关于HTML中的表单Form实现居中效果的文章就介绍到这了,更多相关HTML表单Form居中内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!
相关文章推荐
- html+js实现form表单多值的验证
- html+js 使用FormData对象实现无跳转表单传值PHP
- ASP.NET WebForm Form表单如何实现MVC那种“自动装配”效果呢?
- JQuery实现Tooltip效果表单验证(jQuery Inline Form Validation Engine控件)
- HTML一个form表单中有两个(多个)submit,后台如何区分(纯HTML实现,无需javascript)
- Javascript实现HTML表单form多个HttpPost请求
- ASP.NET WebForm Form表单如何实现MVC那种“自动装配”效果呢?
- html js点击含id的 标签实现form表单跳转到指定的标签位置
- js 使用form表单select类实现级联菜单效果
- HTML网页中插入输入框,输入框内容或代码可点击"运行代码"运行,在浏览器看到运行输入框内代码效果。此HTML代码由表单代码textarea和简单JS代码实现。 HTML代码: <textarea n
- HTML一个form表单中有两个(多个)submit,后台如何区分(纯HTML实现,无需javascript)
- PHP PEAR/HTML/QuickForm实现用户注册表单界面
- HTML一个form表单中有两个(多个)submit,后台如何区分(纯HTML实现,无需javascript)
- html实现form表单提交后不重新刷新页面
- Fieldset,一个不常用的HTML标签 (表单分组实现效果,象Winfrom 里的GroupBox 在左上角显示标题.)
- js 使用form表单select类实现级联菜单效果
- ASP.NET WebForm Form表单如何实现MVC那种“自动装配”效果呢?
- PHP PEAR/HTML/QuickForm实现用户注册表单界面
- ASP.NET WebForm Form表单如何实现MVC那种“自动装配”效果呢?
- 实例:应用CSS实现表单form布局(博主:http://www.bm777.com/post/32.html)