【问题标题】:onhover list items change particular styling悬停列表项更改特定样式
【发布时间】:2015-05-17 13:52:19
【问题描述】:

大家好,堆垛机,

我有以下情况,我不知道该如何解决。 我有一些列表项,当悬停在某个项目上或单击时,该项目应如下所示:

我有以下 HTML 代码,但我真的不知道如何以 CSS3 的最佳方式(而不是图像)解决这个问题,因为它包含 箭头角:

<div class="select-items">
    <h4>Available items:</h4>
    <div class="select-row-item">
        <div class="select-row-item-inner">
            <div class="selectableRow" style="float: left;">First Item</div>
            <img class="arrowRight" src="images/right-arrow.png">
        </div>
    </div>              
    <div class="select-row-item">
        <div class="select-row-item-inner">
            <div class="selectableRow" style="float: left;">Second Item</div>
            <img class="arrowRight" src="images/right-arrow.png">
        </div>
    </div>                        
    <div class="select-row-item">
        <div class="select-row-item-inner">
            <div class="selectableRow" style="float: left;">Third Item</div>
            <img class="arrowRight" src="images/right-arrow.png">
        </div>
    </div>                       
</div>

希望有人可以帮助我。

【问题讨论】:

    标签: jquery html css jquery-hover


    【解决方案1】:

    演示:http://jsfiddle.net/murid/wv107qgo/

    我获得了一些关于尺寸和颜色的创意许可,您应该可以按照自己的意愿进行修复,但效果很好。右边的三角形是用纯 CSS 完成的。

    .select-items {
        width: 300px;
        border: 1px solid #eee;
        color: #444;
        font-family: Helvetica, Arial, 'sans-serif';
        padding: 10px 20px;
    }
    
    ul {
        padding: 0;    
    }
    
    ul li {
        list-style: none;
    }
    
    ul li a {
        text-decoration: none;
        color: #444;
        display: block;
        padding: 10px;
        font-size: 12px;
        position: relative;
        height: 16px;
    }
    
    ul li a:after {
        content:"";
        width:0;
        height:0;
        border-top:18px solid transparent;
        border-bottom:18px solid transparent;
        border-left:18px solid #fff;
        position: absolute;
        right: -18px;
        top: 0;
    }
    
    ul li a:hover {
        background-color: #69a0ff;
        color: #fff;
    }
    
    ul li a:hover:after {
        border-left:18px solid #69a0ff;
    }
    
    ul li a i.arrow {
        width: 6px;
        height: 10px;
        display: inline-block;
        float: right;
        background: url('http://s7.postimg.org/ze62pveef/arrow.png') right top no-repeat;
        background-size: 6px 20px;
    }
    
    ul li a:hover i.arrow {
        background-position: right bottom;
    }
    

    <div class="select-items">
        <ul>
            <li>
                <a href="">First Item <i class="arrow"></i></a>
            </li>
            <li>
                <a href="">Second Item <i class="arrow"></i></a>
            </li>
            <li>
                <a href="">Third Item <i class="arrow"></i></a>
            </li>
        </ul>
    </div>
    

    【讨论】:

      【解决方案2】:

      您应该选择“select-row-item-inner”类并在悬停时更改其背景。

      .select-row-item-inner:hover {
      
          background-color: blue;
      
      }
      

      【讨论】:

        【解决方案3】:

        只需使用:hover。例如:

        .selectableRow:hover{
            background-color: lightblue;
        }
        

        您还可以更改箭头的图像,如下所示:

        .selectableRow:hover .arrowRight {
           content: url("images/right-arrow-hover.png");
        }
        

        【讨论】:

        • @Ramirez 你可以通过交换图像来做到这一点。我已经更新了答案。
        • OP 想要在没有图像的情况下做到这一点
        • @aequalsb OP 发布的 html 中有图片。要进行悬停,需要替换图像。
        【解决方案4】:

        *{
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        
        ul{    
            max-width: 250px;   
            background: #FDFDFD;    
            margin: 25px auto;
            list-style: none;
        }
        ul li{
            padding-right: 20px;
        }
        ul li a{
            display: block;
            padding: 10px 15px;    
            color: #555;
            text-decoration: none;   
            position: relative;
        }
        
        ul li a:hover{
            background: #5CA5FF;
            color: #fff;
        }
        ul li a::before{
            content: '>';
            position: absolute; top: 50%; right: 5px;
             -webkit-transform: translate(0,-50%);
            -ms-transform: translate(0,-50%);
                transform: translate(0,-50%);
        }
        
        
        ul li a:hover:after {
            content: ''; 
            position: absolute; right: -38px; top: 50%; 
            border: 19px solid transparent;	
            border-left: 19px solid #5CA5FF;
            -webkit-transform: translate(0,-50%);
            -ms-transform: translate(0,-50%);
                transform: translate(0,-50%);
        }
        <ul>
            <li><a href="#">item 1</a>
             <li><a href="#">item 2</a>
             <li><a href="#">item 3</a>
        </ul>

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-12
          • 2018-09-04
          • 1970-01-01
          • 2021-09-02
          相关资源
          最近更新 更多