用了float后div块之间的上下顺序不对了_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 12:08:30
原创
1464人浏览过

先看代码

<div id="formpanel">       		<form>          <div id="username_field">                	<div id="usernamepic">                    	<img  src="images/images/images/username_06.jpg"/ alt="用了float后div块之间的上下顺序不对了_html/css_WEB-ITnose" >                    </div>                    <div id="inputfield">                    	<input type="text"   style="max-width:90%" />                    </div>	                 </div>                     <div id="password_field">                	<div id="usernamepic">                    	<img  src="images/images/images/images/password_09.jpg"/ alt="用了float后div块之间的上下顺序不对了_html/css_WEB-ITnose" >                    </div>                    <div id="inputfield">                    	<input type="text"   style="max-width:90%" />                    </div>	                 </div>              </form>   		           		</div>
登录后复制

#formpanel{	width:341px;	height:135px;	margin-left:auto;	margin-right:auto;	}#username_field{	margin-top:0px;	width:340px;	}#usernamepic{	float:left;	margin-top:0px;	margin-left:0px;}#inputfield{	float:right;	margin-top:0px;	margin-right:0px;	width:228px;	height:27px;}#password_field{	width:340px;}
登录后复制

现在出现的问题是我想出现这样的结果
但是却出现了这样的结果 

我在password中设置margin-top却不管用,这是为什么?我想在两个input中间空出24个像素。

知了zKnown
知了zKnown

知了zKnown:致力于信息降噪 / 阅读提效的个人知识助手。

知了zKnown 65
查看详情 知了zKnown

回复讨论(解决方案)

#password_field{
 margin-top:10px;
 width:340px;
}

<html><head>  <title></title>  <style type="text/css">#formpanel{    width:341px;    height:135px;    margin-left:auto;    margin-right:auto;    }.field-container{    margin-top:0px;    width:340px;    position: relative;}.usernamepic{    position: absolute;    margin-top:0px;    margin-left:0px;}.inputfield{    margin-top:0px;    margin-right:0px;    width:228px;    height:27px;}.inputfield input{padding-left: 24px;}  </style></head><body><div id="formpanel">               <form>          <div class="field-container">                    <div class="usernamepic">                        <img  src="images/images/images/username_06.jpg"/ alt="用了float后div块之间的上下顺序不对了_html/css_WEB-ITnose" >                    </div>                    <div class="inputfield">                        <input type="text"   style="max-width:90%" />                    </div>                     </div>                     <div class="field-container">                    <div class="usernamepic">                        <img  src="images/images/images/images/password_09.jpg"/ alt="用了float后div块之间的上下顺序不对了_html/css_WEB-ITnose" >                    </div>                    <div class="inputfield">                        <input type="text"   style="max-width:90%" />                    </div>                     </div>              </form>                              </div></body></html>
登录后复制

最快的方法就是:
#password_field{
float:right;
width:340px;
margin-top:24px;
}

希望对你有帮助,欢迎回访!!

用户名同密码一样的布局为什么还要两个不同层,增加无谓的样式,

  • 用户名:

  • 密码:



简单东西不要复杂化,html上面的足矣。
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号