gpt4 book ai didi

css - 导航栏元素不会采用相同的行高

转载 作者:行者123 更新时间:2023-11-28 02:16:54 25 4
gpt4 key购买 nike

我在 html 中有这个导航栏:

<div class="navbar">
<p class ="logo">Vris</p>
<ul class="navitems">
<li><a href="#">Home</a></li>
<li><a href="#">About me</a></li>
<li><a href="#">My work</a></li>
<li><a href="#">Contact</a></li>

</ul>
</div>
</header>

和下面的 css 一起去:

body {
margin: 0;
font-family: 'Montserrat', sans-serif;
}

.navbar {
background: #181818;
height: 3.5em;
line-height: 1em;
}

.navitems {
float: right;
margin-right: 3em;
}

.logo {
float: left;
font-size: 1.3em;
color: white;
}

li {
font-family: 'Montserrat';
font-size: 1.3em;
text-decoration: none;
list-style-type: none;
padding-right: 2em;
float: left;
}

.navbar a {
text-decoration: none;
color: white;

}

但是导航栏中的 UL 和

元素不会采用相同的行高。为什么?我在父导航栏类中设置了行高,所以

和 child 应该继承它,对吗?

最佳答案

如果你想垂直居中,你需要使用与高度相同的行高。

body {
margin: 0;
font-family: 'Montserrat', sans-serif;
}

.navbar {
background: #181818;
height: 3.5em;
line-height: 3.5em;
}

.navitems {
float: right;
margin-right: 3em;
}

.logo {
float: left;
font-size: 1.3em;
color: white;
}

li {
font-family: 'Montserrat';
font-size: 1.3em;
text-decoration: none;
list-style-type: none;
padding-right: 2em;
float: left;
}

.navbar a {
text-decoration: none;
color: white;

}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="navbar">
<p class ="logo">Vris</p>
<ul class="navitems">
<li><a href="#">Home</a></li>
<li><a href="#">About me</a></li>
<li><a href="#">My work</a></li>
<li><a href="#">Contact</a></li>

</ul>
</div>
</header>
</body>
</html>

关于css - 导航栏元素不会采用相同的行高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48428066/

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