CSS selector :active not working on child element

2019-07-07 05:36发布

I have the following HTML structure:

<div id="ctr__Wrapper" class="wrapper">
    <div id="ctr" class="control clickable">
        <img src="logo.png">
    </div>
</div>

And the following CSS for this:

.control
{
    border: 1px solid #000;
    background-color: #666;
    padding: 20px;
}

.control:active
{
    background-color: #bbb;
}

When I click on the element "ctr", I see the background color changing, but when I click on the image itself, it doesn't. This works fine in Firefox, but not in IE8. Is there something I can do to solve this in CSS.

The working example can be seen here: http://jsfiddle.net/miljenko/DNMPd/

2条回答
劫难
2楼-- · 2019-07-07 06:15

because < ie9 don't support :active on anything other than anchor elements. here's your fiddle, that should work in ie8 http://jsfiddle.net/jalbertbowdenii/DNMPd/12/

查看更多
Juvenile、少年°
3楼-- · 2019-07-07 06:26

You could use a background image instead of a real image.

html:

<div id="ctr__Wrapper" class="wrapper">
    <div id="ctr" class="control clickable">
    </div>
</div>

css:

.control
{
    border: 1px solid #000;
    background-color: #666;
    height: 40+height-of-logopx;
    background-image:url(logo.png); background-repeat:no-repeat;
    background-position:20px 20px;
}

.control:active
{
    background-color: #bbb;
}
查看更多
登录 后发表回答