【发布时间】:2021-07-29 03:18:32
【问题描述】:
我张贴了一张照片,让你看看我到底有什么问题。我不明白为什么样式不适用于 ul 和 li。我将背景样式应用于导航容器,所以我认为应该将其应用于每个元素,对吗?
我可以使用一些帮助和一些解释来理解这件事。
header {
background-image: url('Logos\ and\ Assets/cover.jpg');
height: 100vh;
background-size: cover;
background-position: center;
}
.nav-container {
display: flex;
justify-content: space-between;
padding: 10px 10%;
background-color: rgba(153, 217, 140, 0.3);
}
.nav-ul-2 {
list-style-type: none;
}
.nav-ul-2 li {
display: inline-block;
padding: 0% 20px;
}
.nav-ul-1 {
list-style-type: none;
}
.nav-ul-1 li {
transition: all 0.3s ease 0s;
}
.nav-ul-1 li:hover {
color: yellowgreen;
}
.nav-ul-2 li {
[enter image description here][1] transition: all 0.3s ease 0s;
}
.nav-ul-2 li:hover {
color: yellowgreen;
}
<header>
<nav class="nav-container">
<ul class="nav-ul-1">
<li>Acasa</li>
</ul>
<ul class="nav-ul-2">
<li>Servicii</li>
<li>Despre Noi</li>
<li>Contact</li>
</ul>
<div>
<img src="Logos and Assets/roFlag.svg" class="flag" alt="ro-flag">
<img src="Logos and Assets/englFlag.svg" class="flag" alt="eng-flag">
</div>
</nav>
</header>
【问题讨论】:
-
将背景色应用到包含的 div 会将其应用到该 DIV 并填充到内部元素占用的空间
-
不要将背景颜色应用到
.nav-container,而是应用到.nav-ul-1&.nav-ul-2元素 -
您的minimal reproducible example 没有说明问题。我怀疑您有额外的 CSS 将背景应用于列表。
标签: html css flexbox css-selectors html-lists