gpt4 book ai didi

带有 "brand"的 HTML 和 CSS 水平导航栏

转载 作者:行者123 更新时间:2023-11-28 06:23:12 26 4
gpt4 key购买 nike

我正在尝试为我正在进行的新元素制作一个导航栏

我希望 navbar 包含网站标题,即 h1 和菜单项,但是当我尝试这样做时,它并没有h1ul 在同一行。

我希望导航栏元素和导航栏“标题”在同一高度和同一行上对齐,而不是不能放在一起的不同 block 。

html, body {
width: 100 % ;
padding: 0;
margin: 0;
font - family: 'Roboto',
sans - serif;
}

h1, h2, h3, h4, h5 {
margin: 0;
padding: 0;
}

.main - title {
text - align: center;
margin - top: 20 px;
margin - bottom: 2 px;
}

header {
border - bottom: 2 px solid grey;
}

ul {
padding: 0;
margin: 0;
}

.nav - ul {
list - style - type: none;
float: right;
margin - right: 50 px;
display: inline - block;

}

.navbar - title > h1 {
text - align: center;
margin - top: 20 px;
}

.nav - ul > a: visited, a: link {
text - decoration: none;
color: black;
font - size: 1.5e m
}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Raspberry pi projects</title>
<link rel="stylesheet" href="assets/css/main.css">

<!-- JQUERY CDN -->
<script type="text/javascript" src="http://cdn.jsdelivr.net/jquery/3.0.0-beta1/jquery.js"></script>

<!-- LOADING SCREEN SCRIPT -->
<!--<script type="text/javascript" src="assets/js/load.js"></script>-->

<!-- ROBOTO FONT -->
<link href='https://fonts.googleapis.com/css?family=Roboto:400,900,100italic,300italic,500,300,700,400italic,700italic,500italic,100&subset=latin,greek-ext,latin-ext' rel='stylesheet' type='text/css'>

</head>

<body>
<nav>
<div>
<div class="nav-brand">
<a href="#" class="navbar-title"><h1>Raspberry pi projects</h1></a>
</div>

<div class="nav-list">
<ul class="nav-ul">
<li class="nav-item">
<a href="#">Submit a project</a>
</li>

</ul>

</div>
</div>
</nav>


<script src=""></script>
</body>

</html>

最佳答案

h1 标签默认为 display:block,这意味着它们占据 100% 的宽度。您可以通过将 display:inline-block 添加到 .nav-brand.nav-list 来更改此设置:

html, body {
width: 100%;
padding: 0;
margin: 0;
font-family: 'Roboto', sans-serif;
}

h1,h2,h3,h4,h5 {
margin: 0;
padding: 0;
}

.main-title {
text-align: center;
margin-top: 20px;
margin-bottom: 2px;
}

header {
border-bottom: 2px solid grey;
}

ul {
padding: 0;
margin:0;
}

.nav-brand, .nav-list {
display:inline-block;
}

.nav-ul {
list-style-type: none;
float:right;
margin-right: 50px;
display: inline-block;

}

.navbar-title > h1 {
text-align: center;
margin-top: 20px;
}

.nav-ul > a:visited, a:link {
text-decoration: none;
color: black;
font-size: 1.5em
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Raspberry pi projects</title>
<link rel="stylesheet" href="assets/css/main.css">

<!-- JQUERY CDN -->
<script type="text/javascript" src="http://cdn.jsdelivr.net/jquery/3.0.0-beta1/jquery.js"></script>

<!-- LOADING SCREEN SCRIPT -->
<!--<script type="text/javascript" src="assets/js/load.js"></script>-->

<!-- ROBOTO FONT -->
<link href='https://fonts.googleapis.com/css?family=Roboto:400,900,100italic,300italic,500,300,700,400italic,700italic,500italic,100&subset=latin,greek-ext,latin-ext' rel='stylesheet' type='text/css'>

</head>

<body>
<nav>
<div>
<div class="nav-brand">
<a href="#" class="navbar-title"><h1>Raspberry pi projects</h1></a>
</div>

<div class="nav-list">
<ul class="nav-ul">
<li class="nav-item">
<a href="#">Submit a project</a>
</li>

</ul>

</div>
</div>
</nav>


<script src=""></script>
</body>
</html>

关于带有 "brand"的 HTML 和 CSS 水平导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35443147/

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