gpt4 book ai didi

html - 导航栏干扰 div - HTML/CSS

转载 作者:太空宇宙 更新时间:2023-11-04 11:17:30 25 4
gpt4 key购买 nike

HTML/CSS 初学者。在一个简单的网页上工作。到目前为止,我已经插入了一个侧边导航栏,但是我尝试将登录表单置于页面中心的所有尝试都失败了。唯一有效的边距值是“自动”,它将我的表单固定在页面顶部。我对任何边距属性所做的任何更改都会导致我的导航栏完全困惑。我希望它位于页面的中心,而不是如图所示的导航栏。

当前:![enter image description here ] 1

    @import url('http://fonts.googleapis.com/css?family=Open+Sans');
body {
font-family: 'Open Sans', Arial, sans-serif;
background-color: #ccf;
}

nav {
position: fixed;
width: 200px;
height: 100%;
background-color: #036;
}

nav ul {
list-style: none;
margin-top: 50px;
}

nav ul li a {
text-decoration: none;
display: block;
text-align: center;
color: #ccf;
padding: 30px 0;
font-size: 30px
}

nav ul li a:hover {
color: #fff;
}

.login {

height:100px;
width:170px;
margin:auto;
border:1px #CCC solid;
padding:10px;
background-color:#E9E9E9
}

input {
background: #E1FFE1;
border:1px #CCC solid;
padding:5px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Project</title>
<link rel="stylesheet" href="reset.css">
<link rel="stylesheet" href="style.css">

</head>
<body>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>

</nav>

<div class="login">
<input type="text" placeholder="Username" id="username">
<input type="password" placeholder="Password" id="password">

<a href="#" class="forgot">forgot password?</a>

<input type="submit" value="Sign In">

</div>


</body>
</html>

最佳答案

将此添加到 .login风格

position:absolute; /*can also be fixed*/
left:0; right:0;
top:0; bottom:0;
margin:auto;

http://jsfiddle.net/145w1b6s/

或者如果你想把它放在200px<nav>的宽度的左边起因

position:absolute; /*can also be fixed*/
left:200px; right:0;
top:0; bottom:0;
margin:auto;

http://jsfiddle.net/145w1b6s/1/

关于html - 导航栏干扰 div - HTML/CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33087595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com