style on focused parent element

This question already has an answer here:

  • Is there a CSS parent selector? 26 answers

  • There is no parent selector in css (yet). http://css-tricks.com/parent-selectors-in-css/

    You can, however, select it with jQuery:

    html

    <div class="parent">
        <input type="text" />
    </div>
    

    css

    .parent {
        /* parent styles */
    }
    .parent.active {
        /* do stuff when the input is hovered */
    }
    

    js

    // listen for a focus event on the input,
    //  and then add a class to the parent
    $('input').on('focus', function () {
        $(this).parent().addClass('active');
    });
    

    http://jsfiddle.net/M64nv/


    No. There is no parent selector in CSS, so you cannot trigger style rules on a parent element when one of its descendants is hovered (or based on any child element conditions). You need to use Javascript for this.

    链接地址: http://www.djcxy.com/p/22832.html

    上一篇: CSS3选择器:选择特定节点的父节点?

    下一篇: 关注焦点父元素的风格