CSS控制HTML中元素的对齐问题_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 11:50:00
原创
1238人浏览过

写的一个注册界面如下:


属性设置的是居中,现在想让红色的提示语出现在输入框的下面,并且与输入框左对齐,要怎么实现?我的HTML代码如下:
<form action="registPro" method="post" id="regist">   <div>       <input type="text" id="name" name="user.username" placeholder="用户名">                         </div>       <span id="msg01" class="msg"></span>   <div>       <input type="password" id="pass" name="user.pass" placeholder="设置密码">         </div>       <span id="msg02" class="msg"></span>   <div>      <input type="submit" id="submit" value="注  册" class="button"/>   </div>                  	  	     		      		     	  		
登录后复制


CSS属性设置如下:
<style type="text/css"> input{width:280px;height:30px} .msg{color:red; font-size:1pt;} div{text-align:center;line-height:60px;}                    .button{background-color:OrangeRed;width:250px;height:30px;border:0;}</style>
登录后复制


请问该如何实现我想要的功能??

知元AI
知元AI

AI智能语音聊天 对讲问答 AI绘画 AI写作 AI创作助手工具

知元AI 30
查看详情 知元AI

回复讨论(解决方案)

 .msg{color:red; font-size:1pt; text-align:center; display:block;}
登录后复制

 .msg{color:red; font-size:1pt; text-align:center; display:block;}
登录后复制



你说的这样是让居中,我想的是让红色的提示语和输入框是左对齐的


 .msg{color:red; font-size:1pt; text-align:center; display:block;}
登录后复制



你说的这样是让居中,我想的是让红色的提示语和输入框是左对齐的

 .msg{color:red; font-size:1pt;display:block;width:280px;margin:0 auto;}
登录后复制

<div class="cen"><form action="registPro" method="post" id="regist">   <div>       <input type="text" id="name" name="user.username" placeholder="用户名">                         </div>       <span id="msg01" class="msg">ssssss</span>   <div>       <input type="password" id="pass" name="user.pass" placeholder="设置密码">         </div>       <span id="msg02" class="msg">ssss</span>   <div class="tc">      <input type="submit" id="submit" value="注  册" class="button"/>   </div> </form></div>  <style type="text/css">    .tc{text-align:center;}    .cen{text-align:center;margin:0 auto;width:300px;}    .cen form{text-align:left;} input{width:280px;height:30px} .msg{color:red; font-size:1pt;} div{line-height:30px;}                    .button{background-color:OrangeRed;width:250px;height:30px;border:0;}</style>
登录后复制

把文本框和提示框在一个父级div中,在这个父级div中设置css样式text-aline:left

如果是自己练手可以这样写,公司项目的话,可以用验证框架,很方便

参照Jquery validate 


                             
   

       


----》

改成


                             
       

       
   


要一样 就要在一起

<style type="text/css">*{margin:0px;padding:0px;} form{width:282px;margin:auto;} input{width:280px;height:30px} .msg{color:red; font-size:15px;} div{line-height:60px;}                    .button{margin-left:16px;background-color:OrangeRed;width:250px;height:30px;border:0;}</style>
登录后复制


你可以给form设置width,很轻松解决问题,把这些东西都当成块来看,布局很简单

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号