gpt4 book ai didi

html - 如何将 Logo 和菜单选项设置在同一级别?

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

例如,我正在尝试创建背景颜色为灰色的横幅。我希望此横幅包含 Logo 和菜单选项。

我认为我必须有三个 div,但是当我将 Logo 和菜单选项放入其中时,我得到的是三个独立的东西,而不是一个容器中的两个东西。

此外,如果有人愿意批评我的代码,我将不胜感激,因此我会改进。

提前谢谢你。

div.header_container {
font-family: tamarillo-jf, sans-serif;
font-style: normal;
font-weight: 400;
border: solid blue 10px;
}

div.logo_container {
border: solid red;
float: left;
}

h1.logo {
padding: 10px;
margin: 0;
color: forestgreen;
font-family: tamarillo-jf, sans-serif;
font-style: normal;
font-weight: 400;
}

div.nav_container {
border: solid pink;
float: right;
overflow: auto;
margin: 0;
}

li.option {
display: inline;
padding: 10px;
list-style-type: none;
font-size: 25px;
margin: 0;
}

a {
text-decoration: none;
color: forestgreen;
}
<!DOCTYPE HTML>

<html>

<head>
<title>Home | Business</title>
<link rel = "stylesheet" href = "style.css">
<!--fonts-->
<script src="https://use.typekit.net/yhm2vpr.js"></script>
<script>try{Typekit.load({ async: true });}catch(e){}</script>
</head>

<body class = "home_page">

<!-- "banner" with logo and navigation options -->
<div class = "header_container">

<div class = "logo_container">
<h1 class="logo">Business Name</h1>
</div>

<div class = "nav_container">
<ul class = "nav_ops">
<li class = "option"><a href="#about us">about us</a></li>
<li class = "option"><a href="#classes">classes</a></li>
<li class = "option"><a href="#services">services</a></li>
<li class = "option"><a href="#get involved">get involved</a></li>
<li class = "option"><a href="#contact us">contact us</a></li>
<li class = "option"><a href="#donate">donate</a></li>
</ul>
</div>

</div>

<p>Hello, there!</p>
</body>
</html>

最佳答案

我可以看到你有两个选项

选项 1 - 在 header_container 中的 nav_container 之后添加此选项

//html
<br class='clear'/>

//Styles
.clear {
clear: both;
}

选项 2 - 从 logo_container 和 nav_container 中删除 float 并在 header_container 上使用 flex 属性

.header_container {
display:flex;
justify-content: space-between;
align-items: center;
}

关于html - 如何将 Logo 和菜单选项设置在同一级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39864435/

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