我在网站上使用背景色(不透明度0.2)进行导航。我想为列表链接菜单创建一个单独的背景,并使带有徽标的导航左侧部分与背景一起浮动,直到下一个div。我尝试了很多方法,但是它们似乎都不完美。徽标背景的左侧仅占据文本下的空间,而不是我需要的整个div。
这里是例子:
$('.navigation ul li a').on('mouseover', function() {
$(this).parent().addClass('navigation-hover');
}).on('mouseout', function() {
$(this).parent().removeClass('navigation-hover');
})
.navigation {
font-size: 3em;
height: 70px;
position: fixed;
right: 0;
left: 0;
}
.navigation-logo {
float: left;
background-color: rgba(0, 0, 0, 0.2);
}
.navigation ul {
display: inline;
}
.navigation ul li {
float: right;
font-size: 0.5em;
line-height: 60px;
height: 70px;
display: inline-block;
text-align: center;
padding-left: 10px;
color: #ffffff;
padding-left: 10px;
background-color: rgba(0, 0, 0, 0.2);
}
.navigation-hover {
background: transparent !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<div class="navigation">
<div class="navigation-logo">
<a class="navigation-logo">logo</a>
</div>
<div>
<ul>
<li><a href="">link1</a></li>
<li><a href="">link2</a></li>
<li><a href="">link3</a></li>
<li><a href="">link4</a></li>
</ul>
</div>
</div>
答案 0 :(得分:0)
/* Styles go here */
.navigation {
font-size: 3em;
height: 70px;
justify-content: space-between;
margin: 0 8px;
width: calc(100% - 16px);
display: flex;
left:0;
position:fixed;
flex-direction: row;
}
.navigation-logo {
background-color: rgba(0, 0, 0, 0.2);
}
.navigation ul {
display: inline;
}
.navigation ul li {
float: right;
font-size: 0.5em;
line-height: 60px;
height: 70px;
display: inline-block;
padding-left: 10px;
text-align: center;
color: #ffffff;
background-color: rgba(0, 0, 0, 0.2);
}
.navigation-hover {
background: transparent !important;
}
here is plunkr for the above changes
http://plnkr.co/edit/0PY5IPExNYVwQPsOVyXS?p=preview