作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
例如,我正在尝试创建背景颜色为灰色的横幅。我希望此横幅包含 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/
我是一名优秀的程序员,十分优秀!