gpt4 book ai didi

html - 在导航栏中对齐多个 div 的更优雅的方式?

转载 作者:搜寻专家 更新时间:2023-10-31 08:26:52 26 4
gpt4 key购买 nike

我几周前才开始接触 HTML 和 CSS,希望能得到一些帮助。我正在寻找一种优雅的方式来对齐标题中的多个元素。

我不熟悉使用网格。我尝试使用 display: inline-block 和 display: table 但我没有让它按照我喜欢的方式工作。所以我不得不使用 float ,这很有效,但我觉得它是被迫的。

我也希望内容显示在与 .nav-content 相同的范围内,但我猜 55% 的容器将不同于 55% 的标题?

无论如何,这是代码:

* {
box-sizing: border-box;
}
.container {
max-width: 100%;
height: 100%;
}
/******************************************
Header / Navbar
*******************************************/

.navigation {
width: 100%;
border-bottom: solid 1px #eee;
position: fixed;
Z-Index: 500;
font-size: 14px;
box-sizing: border-box;
font-weight: 400;
font-style: normal;
line-height: 1.6;
min-height: 65px;
padding-top: 10px;
}
.nav-content {
width: 55%;
margin: 0 auto;
overflow: hidden;
position: relative;
}
.nav-logo,
.navigation li {
float: left;
}
.nav-right,
.nav-btn {
float: right;
}
.nav-left {
font-size: 26;
padding-left: 1%;
padding-top: 0.5%;
}
.nav-left li {
margin-right: 1%;
margin-left: 1%;
}
.navigation ul {
list-style: none;
margin: 0;
padding: 0;
}
.nav-right {
padding-right: 1%;
margin-top: -25px;
}
<head>
<meta charset="UTF-8">
<meta name="description" content="We are medium. We write about startups.">
<meta name="keywords" content="Medium, blogging, startups, entrepreneurship, Unternehmer, Gründung, Unternehmensgründung, gründen, Venture Capital, Business Angel, Investor, Wagniskapital, Risikokapital">
<meta name="author" content="William Middendorf">
<meta name="robots" content="index, follow">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>Medium</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic|Montserrat:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
<link rel="icon" href="img/favicon.ico" type="image/x-icon">
</head>

<body>
<div class="container">
<div class="navigation">
<!--Navigation-->
<div class="nav-left">
<ul>
<li><i class="fa fa-bars"></i>
</li>
<li><i class="fa fa-search"></i>
</li>
</ul>
</div>
<div class="nav-content">
<div class="nav-logo">Blogger</div>
<div class="nav-btn">
<button class="wrt-btn">Schreib' einen Artikel</button>
</div>
</div>
<div class="nav-right">
<ul>
<li><a href="#" style="cursor: auto;">Log In</a>
</li>
<li><a href="#" style="cursor: auto;">Register</a>
</li>
</ul>
</div>
</div>
<!--End of Navigation / Header-->

</div>
<!--End of Container-->
</body>

最佳答案

Float 不是去这里的好方法。如果需要,您以后将无法在移动 View 中将它们居中。

使用 display: inline-block; 并且不要在按钮之间留空格或换行是 html 代码,以避免它们之间出现间隙。

关于html - 在导航栏中对齐多个 div 的更优雅的方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33020205/

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