gpt4 book ai didi

css - 背景颜色未填满整个 li

转载 作者:太空宇宙 更新时间:2023-11-04 02:02:16 25 4
gpt4 key购买 nike

我制作了一个菜单,想为其中一个菜单项添加背景颜色。添加背景颜色后,左侧有一个小空间没有被颜色覆盖。有谁知道我怎样才能填满整个空间?

这是一个 fiddle :https://jsfiddle.net/9crtzv6s/1/

.slider ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 1px solid black;
width: 480px;
margin: 0 auto;
}
.slider li a {
display: block;
text-align: center;
padding: 16px;
text-decoration: none;
}
.slider li {
display: inline-block;
border-right: 1px solid black;
text-transform: uppercase;
font-size: 13px;
font-family: 'textaw00-heavyregular', 'AvenirNextLTW01', 'Helvetica Neue', 'Helvetica', 'Arial', 'sans-serif';
text-transform: uppercase;
letter-spacing: 1px;
font-weight: normal;
-webkit-font-smoothing: antialiased;
}
.slider li:last-child {
border-right: none;
}
.slider-3 {
background-color: green;
}
<div class="slider">
<ul>
<li><a href="#" class="slider-1">Menu</a>
</li>
<li><a href="#" class="slider-2">Menu</a>
</li>
<li><a href="#" class="slider-3">Menu</a>
</li>
<li><a href="#" class="slider-4">Menu</a>
</li>
</ul>
</div>

最佳答案

内联元素,如列表项,对代码中的空格敏感,因此要么删除空格,要么不将显示设置为内联 block ,而是将列表项向左浮动。

.slider ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 1px solid black;
width: 480px;
margin: 0 auto;
}
.slider li a {
display: block;
text-align: center;
padding: 16px;
text-decoration: none;
}
.slider li {
float: left;
border-right: 1px solid black;
text-transform: uppercase;
font-size: 13px;
font-family: 'textaw00-heavyregular', 'AvenirNextLTW01', 'Helvetica Neue', 'Helvetica', 'Arial', 'sans-serif';
text-transform: uppercase;
letter-spacing: 1px;
font-weight: normal;
-webkit-font-smoothing: antialiased;
}
.slider li:last-child {
border-right: none;
}
.slider-3 {
background-color: green;
}
<div class="slider">
<ul>
<li><a href="#" class="slider-1">Menu</a>
</li>
<li><a href="#" class="slider-2">Menu</a>
</li>
<li><a href="#" class="slider-3">Menu</a>
</li>
<li><a href="#" class="slider-4">Menu</a>
</li>
</ul>
</div>

或者

.slider ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 1px solid black;
width: 480px;
margin: 0 auto;
}
.slider li a {
display: block;
text-align: center;
padding: 16px;
text-decoration: none;
}
.slider li {
display: inline-block;
border-right: 1px solid black;
text-transform: uppercase;
font-size: 13px;
font-family: 'textaw00-heavyregular', 'AvenirNextLTW01', 'Helvetica Neue', 'Helvetica', 'Arial', 'sans-serif';
text-transform: uppercase;
letter-spacing: 1px;
font-weight: normal;
-webkit-font-smoothing: antialiased;
}
.slider li:last-child {
border-right: none;
}
.slider-3 {
background-color: green;
}
<div class="slider">
<ul>
<li><a href="#" class="slider-1">Menu</a>
</li><li><a href="#" class="slider-2">Menu</a>
</li><li><a href="#" class="slider-3">Menu</a>
</li><li><a href="#" class="slider-4">Menu</a>
</li>
</ul>
</div>

关于css - 背景颜色未填满整个 li,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41555276/

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