下午好
我想使用具有固定宽度和高度值的 float 创建一个位于屏幕中央的区域。即使调整屏幕大小时,该区域也必须居中。我的目标是在屏幕上集中显示密码字段、登录按钮和图像。这些元素必须放置在 float 中, float 必须集中在屏幕上。
非常感谢您的帮助。
谢谢,
最佳答案
这是我刚刚掀起的东西:
position:absolute;
div 将始终居中,无论浏览器的高度/宽度如何。
我刚刚输入的表格来证明它有效。
HTML:
<div>
<form>
<input style='width:45%;float:left;' placeholder='Username'/>
<input style='width:45%;float:right;' placeholder='Password'/>
<input style='width:45%;float:left;' placeholder='email'/>
<input style='width:45%;float:right;' placeholder='favourite color'/>
<p style='clear:both;'></p>
<input type='submit' value='Go'/>
</form>
</div>
CSS:
html,body{
margin:0;
border:0;
}
div{
height:500px;
width:500px;
background:red;
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
margin:auto;
}
关于html - 如何使用 CSS 在屏幕上集中 float (例如水平或垂直),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22564707/