开发者

Can I declare a CSS of a parent? [duplicate]

开发者 https://www.devze.com 2023-04-12 00:29 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Is there a CSS parent selector?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Is there a CSS parent selector?

I have this code :

<div class="main_parent">
    <a href="www.google.it">
        <img src="/path/image.jpg" alt="image" />
    </a>
</div>

and I'd like to set the attribute text-decoration:none; to the link that contains an image.

So, somethings like :

.main_parent img <开发者_开发技巧 a
{
    text-decoration:none;
}

but of course it doesnt works. How can I do it with CSS 2?


Simply put, you can't. CSS can only traverse the DOM downwards. If javascript/jQuery is an option for you, you could use that.


Nope, this is not possible. Some smart people also wrote about this: http://css-tricks.com/7701-parent-selectors-in-css/

You read CSS selectors from left to right. So there is no real syntax for this right now.


I think this is not possible via CSS. You would have to use JavaScript and assign the style via DOM manipulation.


You can even do it with CSS3. There is no parent selector unfortunately.

0

精彩评论

暂无评论...
验证码 换一张
取 消