[英]How to eliminate the overlap border using CSS only
I'm creating a sidebar menu and I encounter this overlap border problem. 我在创建侧边栏菜单时遇到此重叠边框问题。
HTML & CSS: HTML和CSS:
SCSS: ul { list-style: none; width: 300px; margin: 0; padding: 0; background: #F9F9F9; li { position: relative; width: 300px; border-top: 1px solid transparent; border-bottom: 1px solid transparent; border-left: 1px solid transparent; a { display: block; padding: 5px; } span { display: none; position: absolute; z-index: 1; top: 0; right: 0; } &:last-child { border-bottom: 1px solid transparent; } &:hover { border-top: 1px solid #DDD; border-bottom: 1px solid #DDD; border-left: 1px solid red; span { display: block; background: red; } } &.active { border-top: 1px solid #DDD; border-bottom: 1px solid #DDD; background: #FFF; } } }
HTML: <ul> <li><a href="#">list one</a> <span><a href="http://www.google.com" target="_blank">hidden</a></span> </li> <li class="active"><a href="#">list two</a> </li> <li><a href="#">list three</a> </li> <li><a href="#">list four</a> </li> <li><a href="#">list five</a> </li> </ul>
JSFiddle: https://jsfiddle.net/7xjpqf2m/ JSFiddle: https ://jsfiddle.net/7xjpqf2m/
This is tricky only because you have an .active
concept going that is messing with the :hover
concept. 这仅是棘手的,因为您正在使用的
.active
概念与:hover
概念混淆了。 When something active is right next to something hovering, you get two borders right? 悬停的东西旁边有活动的东西时,您会得到两个边界吗? I haven't played with this but maybe this will work
我没有玩过,但是也许可以
a.active + a:hover {
border-top-color: transparent
}
a:hover + a.active {
border-top-color: transparent
}
The idea being it's kinda like an if-statement. 这个想法有点像if语句。 If the thing being hovered has a sibling just before it which is active, then lets not do the border top on the think hovering (that's the first rule from above).
如果要悬停的事物在活动之前有一个同级兄弟,则不要在思考悬停时在边界上方做这件事(这是上面的第一个规则)。 Again, haven't tried, it's just a thought
再说一次,没有尝试过,这只是一个想法
Simple is you just add in SASS: 很简单,您只需添加SASS:
ul > li{ margin:-1px } ul> li {margin:-1px}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.