1

As the title says -

Here I have a link which contains img tag:

<a href="#">
  <img src="somthng.jpg" />
</a>

I have to style this link, there is no class in the image or the link so don't suggest me to add a class. Further I don't want the styling of this link with any other link such as :

<a href="#">
  <div>...</div>
</a>

So I'm trying to trigger the link by css a img {...}, but that would style the image not the anchor.

Suraj
  • 932
  • 5
  • 23
  • 43

4 Answers4

2

selectors? http://www.w3.org/TR/CSS2/selector.html

You could also use js to target the image file src and then use that to append a class to the link

Michael Guild
  • 808
  • 9
  • 8
1

The only thing you can do in this situation without resorting to javascript is look for anything that all anchors that contain images have in common. Or anything that all anchors that don't contain images have in common. Are they all nested in the same div structure with a specific class? Could you target them like this div#content div.inner div.someArbitraryClass a for example? Could you style all links the way you want them when they're around images and then find a way to override this style for other links, if they all have something in common? Sometimes you have to think outside the box.

punkrockbuddyholly
  • 9,675
  • 7
  • 36
  • 69
  • If that was the case I wouldn't have asked this question. :) – Suraj Oct 18 '11 at 15:15
  • This is the right answer to me, as it implicitly says that it may not be possible with CSS only. Pointing tot the w3 selectors reference (answer above) sound like a joke :) – Javier Rey Nov 23 '20 at 17:58
0

... so you have to style the a tag only a {}, if you're using Firebug, get the CSS Path to that a tag, that's the only way you can get to it if at all. Assuming that's doable your like

some tag and another nested tag a{}

vector
  • 7,334
  • 8
  • 52
  • 80
0

If you want to give padding, margin, width or height to link (i.e: a). Don't forgot to apply display-inline-block; to link.

SiriusKoder
  • 341
  • 2
  • 4
  • 12
  • Actually the comment by @animuson was enough! :) Clearly javascript is to be used as per now because CSS hasn't introduced a selector for this stuff! Thanks btw, I don't really need this. – Suraj Oct 29 '11 at 17:20