1

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?

Community
  • 1
  • 1
markzzz
  • 44,504
  • 107
  • 265
  • 458

4 Answers4

3

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

Joseph Marikle
  • 68,672
  • 14
  • 103
  • 120
2

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

Aziz Shaikh
  • 15,104
  • 9
  • 55
  • 73
2

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.

js-coder
  • 7,488
  • 8
  • 38
  • 59
1

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

Joe
  • 73,764
  • 18
  • 123
  • 142