我在菜单上工作,这是文本合理的。为了使其正常工作,我添加了一个新行。问题是它应该是零像素。但是,它打破了布局
JS在工作中不知所措 https://jsfiddle.net/z1qsL739/1/
<div class="registration-menu">
<ul class="reg-menu-list">
<li class="active"><a href="#">some </a></li>
<li><a href="#">some</a></li>
<div class="justify-fix"></div>
</ul>
</div>
的CSS
.registration-menu{
background: white;
border-top: 4px solid green;
border-bottom: 4px solid green;
}
.reg-menu-list{
list-style: none;
display: inline-block;
text-align: justify;
width: 100%;
line-height: 0em;
color: green;
font-size: 0px;
margin: 0;
padding: 0;
.justify-fix{
width: 100%;
line-height: 0em;
height: 0;
display: inline-block;
content: ' ';
}
li{
display: inline-block;
line-height: 1em;
font-size: 18px;
&.active{
background: #fde8be;
border-top: 4px solid #ffb642;
border-bottom: 4px solid #ffb642;
margin: -4px 0 -4px 0;
}
a{
padding: 10px;
display: inline-block;
}
&:hover{
@include transition(all .4s ease);
background: #fde8be;
}
}
}
答案 0 :(得分:1)
列表中不允许div
作为直接子项。一种现代而直接的方法是使用flexbox
定位,例如
ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: row;
justify-content: space-around;
}
答案 1 :(得分:1)
你根本不需要div,使用伪元素
.registration-menu {
background: white;
border-top: 4px solid green;
border-bottom: 4px solid green;
}
.reg-menu-list {
list-style: none;
text-align: justify;
width: 100%;
line-height: 0em;
color: green;
font-size: 0px;
margin: 0;
padding: 0;
}
.reg-menu-list::after {
width: 100%;
line-height: 0em;
height: 0;
display: inline-block;
content: ' ';
}
li {
display: inline-block;
line-height: 1em;
font-size: 18px;
background: pink;
}
li.active {
background: #fde8be;
border-top: 4px solid #ffb642;
border-bottom: 4px solid #ffb642;
margin: -4px 0 -4px 0;
}
a {
padding: 10px;
display: inline-block;
}
a:hover {
@include transition(all .4s ease);
background: #fde8be;
}
<div class="registration-menu">
<ul class="reg-menu-list">
<li class="active"><a href="#">some </a>
</li>
<li><a href="#">some</a>
</li>
<li><a href="#">some</a>
</li>
<li><a href="#">some </a>
</li>
<li><a href="#">some</a>
</li>
<li><a href="#">some</a>
</li>
</ul>
</div>
答案 2 :(得分:1)
尝试将以下规则height: 46px;
添加到.registration-menu
,将padding: 4px 0;
添加到.reg-menu-list
.registration-menu {
background: white none repeat scroll 0 0;
border-bottom: 4px solid green;
border-top: 4px solid green;
height: 46px;
}
.reg-menu-list {
color: green;
display: inline-block;
font-size: 0;
line-height: 0;
list-style: outside none none;
padding: 4px 0;
text-align: justify;
width: 100%;
}
答案 3 :(得分:-2)
从display: inline-block
.reg-menu-list