我设法创建了一个伪 :before 元素以添加到菜单项中,该元素按我的意愿工作,但是当我向父 div(底部导航)添加背景颜色/图像时,伪元素似乎坏了,任何人都可以摆脱一些光?
注意我正在使用 fomantic UI (semantic UI fork)
.bottom-nav {
background-color: #000;
.menu {
margin-bottom: 30px;
.toggle-sidebar {
margin-top: 25px;
color: #2f2f2f;
}
.ui.dropdown {
margin-top: 25px;
}
.item {
font-family: Open Sans;
font-size: 14px;
font-weight: 700;
color: #fff;
padding: 10px;
}
.item:before {
content: '';
opacity: 1;
position: absolute;
border-radius: 2px;
height: 20px;
transform: translate(-50%, 0);
background-color: #cd2122 !important;
overflow: hidden;
width: 0%;
left: 50%;
z-index: -1;
transition: 0.3s ease;
}
.item:hover:before {
opacity: 1;
width: 100%;
}
}
}
<!-- You MUST include jQuery before Fomantic -->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/fomantic-ui@2.8.2/dist/semantic.min.css">
<script src="https://cdn.jsdelivr.net/npm/fomantic-ui@2.8.2/dist/semantic.min.js"></script>
<div class="bottom-nav">
<div class="ui container">
<div class="ui grid">
<div class="sixteen wide column mobile hidden tablet hidden menu">
<div class="ui dropdown">
<a class="item" href="#">Link 1</a>
</div>
<div class="ui dropdown">
<a class="item " href="#">Link 2</a>
</div>
<div class="ui dropdown">
<a class="item" href="#">Link 3</a>
</div>
<div class="ui dropdown">
<a class="item" href="#">Link 4</a>
</div>
</div>
</div>
</div>
</div>