css - 为什么我的图像隐藏了 h2?为什么导航不是水平渲染的?
问题描述
我觉得自己像个白痴,因为我知道这是一件简单的事情。我不明白为什么徽标和标语图像不在灰色容器中。我也不明白为什么我的 h2 和 ul 在我的形象之上。感谢所有帮助。这应该看起来像https://imgur.com/a/3Qx3ihp 这就是它现在呈现的方式 https://imgur.com/a/WGyYzPr
<div id="topbar">
<img src="hw8_images/logo.png" alt="Blaine and Associates logo"><img src="hw8_images/blaine-tagline.png" alt="Blaine and Associates Inc. tagline"><img src="hw8_images/architectural-tagline.png" alt="Architectural Design and Consulting">
<ul class="nav">
<li><a href="Contact.html">Contact</a></li>
<li><a href="Employment.html">Employment</a></li>
<li><a href="Projects.html">Projects</a></li>
<li><a href="Services.html">Services</a></li>
<li><a href="Company.html">Company</a></li>
</ul>
</div>
<div class="buildingimage"></div>
<div id="container">
<h2>Quick Links</h2>
<ul id="QL">
<li><a href="Free_Consultation.html">Free Consultation</a>
</li>
<li><a href="Client_List.html">Client List</a></li>
<li><a href="testimonials.html">Testimonials</a></li>
<li><a href="Open_positions.html">Open Positions</a></li>
<li><a href="news.html">Latest News</a></li>
</ul>
</div>
body {
font: normal normal normal 75%/1.3em verdana,geneva,lucida,arial,sans-serif;
text-decoration: none; background-color: #fff;
}
.topbar{
background-color: #4d4d4d;
font-color: #fff;
height: 15px;
min-width: 500px;
max-width: 950px;
}
.nav li{
font: normal normal normal 100%/2em verdana,geneva,lucida,arial,sans-serif;
text-decoration: none;
display: inline-block;
list-style: none;
text-decoration: none;
text-align: center;
float: right;
}
h1 {
font: normal normal normal 140%/1.3em verdana,geneva,lucida,arial,sans-
serif; text-decoration: none;
}
h2 {
font: normal normal normal 120%/1.3em verdana,geneva,lucida,arial,sans-
serif;
text-decoration: none;
float: left;
position: relative;
}
footer li {
display: inline-block;
list-style-type: none;
font: normal normal normal 90%/2em verdana,geneva,lucida,arial,sans-serif;
text-decoration: none;
text-align: center;
background-color: #4d4d4d;
font-color: #fff;
}
#container {
position: relative;
height: 300px;
width: 400px;
}
.buildingimage {
background-image: url(hw8_images/building.jpg);
float: left;
background-repeat: no-repeat;
position: absolute;
margin: .5em;
background-size:cover;
height: 7em;
min-width: 200px;
max-width: 250px
}
#QL {
list-style: circle;
float: left;
position: relative;
}
解决方案
“我不明白为什么标志和标语图片不在灰色容器中。”
它们在里面,但容器没有样式,因为您无法使用 .topbar 找到它,因为它是 id 而不是类。所以#topbar 会做到这一点。如果你让它大于 15px,所有元素都将显示在里面。
H2 和 ul 位于 background-img 的顶部,因为它位于绝对位置。如果将其更改为相对,图像将向左浮动,H2 和 ul 在右侧对齐。
推荐阅读
- php - 需要清除 Google OAuth 缓存?
- c++-winrt - IAsyncOperation 返回指针或对 Winrt 类型的引用
- json - 无法发送带有球衣响应的 JSON 数组,“生成不完整的 JSON 时出错”
- loops - 响应重复但计数显示为 1
- angular - Spring Security OAuth2 将 access_token 存储在 cookie 中
- django-rest-framework - 如何在 django rest 框架中从 APIView 将上下文传递给 serailizers
- laravel - Laravel Composer 安装失败,在 ubuntu 中出现错误
- docker - docker运行错误:无法访问jarfile
- sharepoint - Spfx 用于创建带有附件的新草稿电子邮件
- mysql - 连接两个表,其条件为“ON”