gpt4 book ai didi

css - 相对于 Logo 图像的大小和垂直中心导航栏元素

转载 作者:行者123 更新时间:2023-11-28 01:45:49 24 4
gpt4 key购买 nike

我正在尝试调整水平导航栏左侧的导航栏 Logo 的大小,然后让其余导航栏元素占据相同的垂直空间并在空间中垂直居中。导航栏元素目前不使用完整的垂直空间。我尝试过的每个尺寸属性都产生了另一个问题。感谢所有帮助。

注意:不能使用 Bootstrap 。希望我能。

/****************************************/
/* Fixed top navbar with dropdowns */
/****************************************/
.m-navbar ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 1px solid #e7e7e7;
background-color: #f3f3f3;
}

/*.m-navbar li {
float: left;
}*/

.m-navbar-right {
float: right;
}
.m-navbar-left {
float: left;
}

.m-navbar li a, .m-menu-form {
display: inline-block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
border: none;
font-size: 100%;
font-family: "Lato", sans-serif;
}

.m-navbar li a:hover:not(.active), .m-dropdown:hover, .m-menu-form:hover {
/*background-color: #ddd;*/
background-color: #9dd0f0;
}

.m-navbar-logo-img {
padding: 3px 0px 4px 4px;
width: auto;
max-height: 33px;
position: relative;
}

.m-navbar li a.active {
color: white;
background-color: #00719c;
}

.m-navbar li.m-dropdown {
display: inline-block;
}

.m-dropdown-content {
display: none;
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<link rel="stylesheet" href="navbar.css">
<title>Navbar Problem</title>
</head>
<body>
<div class="m-outer">
<div class="m-fixed-header">
<div class="m-navbar">
<ul>
<li class="m-navbar-left"><a href="#"><img class="m-navbar-logo-img" src="bugicon.png"></img></a></li>
<li class="m-navbar-left">
<form name="idForm" method="post" action="">
<input type="submit" name="action" class="m-menu-form" value="Home">
</form>
</li>
<li class="m-dropdown m-navbar-left">
<a href="javascript:void(0)" class="m-dropbtn">Menu 1</a>
<div class="m-dropdown-content">
<a href="#">Drop 1</a><br>
<a href="#">Drop 2</a><br>
<a href="#">Drop 3</a><br>
</div>
</li>
<li class="m-dropdown m-navbar-left">
<a href="javascript:void(0)" class="m-dropbtn">Menu 2</a>
<div class="m-dropdown-content">
<a href="#">Drop 1</a><br>
<a href="#">Drop 2</a><br>
<a href="#">Drop 3</a><br>
<a href="#">Drop 4</a><br>
<a href="#">Drop 5</a><br>
</div>
</li>
<li class="m-navbar-right"><a href='#'>Logoff&nbsp;&nbsp;</a></li>
</ul>
</div>
</div>
</div>

</body>
</html>

最佳答案

你用 display:flex 试过吗?

/****************************************/
/* Fixed top navbar with dropdowns */
/****************************************/
.m-navbar ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 1px solid #e7e7e7;
background-color: #f3f3f3;
display: flex;
flex-shrink: 1;
display: -webkit-flex;
-webkit-justify-content: space-around;
justify-content: space-around;
}

/*.m-navbar li {
float: left;
}*/

.m-navbar-right {
float: right;
}
.m-navbar-left {
float: left;
}

.m-navbar li a, .m-menu-form {
display: inline-block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
border: none;
font-size: 100%;
font-family: "Lato", sans-serif;
}

.m-navbar li a:hover:not(.active), .m-dropdown:hover, .m-menu-form:hover {
/*background-color: #ddd;*/
background-color: #9dd0f0;
}

.m-navbar-logo-img {
padding: 3px 0px 4px 4px;
width: auto;
max-height: 33px;
position: relative;
}

.m-navbar li a.active {
color: white;
background-color: #00719c;
}

.m-navbar li.m-dropdown {
display: inline-block;
}

.m-dropdown-content {
display: none;}
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<link rel="stylesheet" href="navbar.css">
<title>Navbar Problem</title>
</head>
<body>
<div class="m-outer">
<div class="m-fixed-header">
<div class="m-navbar">
<ul>
<li class="m-navbar-left"><a href="#"><img class="m-navbar-logo-img" src="bugicon.png"></img></a></li>
<li class="m-navbar-left">
<form name="idForm" method="post" action="">
<input type="submit" name="action" class="m-menu-form" value="Home">
</form>
</li>
<li class="m-dropdown m-navbar-left">
<a href="javascript:void(0)" class="m-dropbtn">Menu 1</a>
<div class="m-dropdown-content">
<a href="#">Drop 1</a><br>
<a href="#">Drop 2</a><br>
<a href="#">Drop 3</a><br>
</div>
</li>
<li class="m-dropdown m-navbar-left">
<a href="javascript:void(0)" class="m-dropbtn">Menu 2</a>
<div class="m-dropdown-content">
<a href="#">Drop 1</a><br>
<a href="#">Drop 2</a><br>
<a href="#">Drop 3</a><br>
<a href="#">Drop 4</a><br>
<a href="#">Drop 5</a><br>
</div>
</li>
<li class="m-navbar-right"><a href='#'>Logoff&nbsp;&nbsp;</a></li>
</ul>
</div>
</div>
</div>

</body>
</html>

关于css - 相对于 Logo 图像的大小和垂直中心导航栏元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50190010/

24 4 0