简体   繁体   English

CSS Triangle Hover Border Issue

[英]CSS Triangle Hover Border Issue

Using the following code 使用以下代码

<ul id="leftNavUl"> 
    <li><a href="#">Colors</a></li>
    <li><a href="#">Typography</a></li>
    <li><a href="#">Buttons</a></li>
    <li><a href="#">Main Navigation</a></li>
    <li><a href="#">Alerts</a></li>
    <li><a href="#">Data Tables</a></li>
</ul>

I'd like the hover to show a triangle / arrow at the end of each border to the right. 我希望悬停在右边每个边框的末尾显示一个三角形/箭头。

I have implemented the following code 我已经实现了以下代码

#leftNavUl li:hover{
    display: inline-block;lock;
    position: relative;
    background: #97cce9;
    padding: 15px; width:100%;}

#leftNavUl li:after{
    content: '';
    display: block;  
    position: absolute;
    left: 100%;
    top: 0%;
    margin-top: -10px;
    width: 0;
    height: 0;
    border-top: 40px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 40px solid transparent;
    border-left: 30px solid #97cce9;
}

While the hover works, there is an extra triangle/arrow visible on the outside of the div. 悬停工作时,div外部可以看到一个额外的三角形/箭头。

箭头/边界三角形问题的图像

you should triger the after element only on the hover state. 你应该只在悬停状态下对after元素进行triger。

Like #leftNavUl li:hover:after #leftNavUl li:hover:after

And carfule you got a typo on you first class : display: inline-block; 你的头等舱上有一个拼写错误:显示:内联块; lock; 锁;

See code below : https://jsfiddle.net/d6h0xtup/2/ 请参阅以下代码: https//jsfiddle.net/d6h0xtup/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM