Results 1 to 3 of 3

Thread: how to separate anchor link and anchor hover img in CSS

  1. #1
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    118
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default how to separate anchor link and anchor hover img in CSS

    Hi

    I have a current coding problem. I currently have the below code as follows for all links related to anchor elements.

    Code:
    a:hover  {
      background-color:#a4cf4f;
      color:#FFFFFF;
      padding-bottom:1px;
      padding-left:3px;
      padding-right:3px;
      padding-top:1px;
      text-shadow:1px 1px 0 #0964A0
    }
    The problem is that this also applies itself by default to all image tags within an anchor tag.

    Code:
    <p><a href="http://www.madchaos.com.au/image.jpg"><img src="http://www.madchaos.com.au/" /></a></p>
    I need to be able to have CSS treat images within anchor tags differently to text within anchor tags. This is also through a Wordpress framework so I have no real control over the mark-up in which images are displayed.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You can be more specific with your css.

    Code:
    a:hover  img {
    to target a link with an image tag within it that is being hovered over. If all your fields had spans in them you could do

    Code:
    a:hover  span {
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    118
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default

    I actually tried that method but still, the underlying anchor tag still activates its styles no matter whether the image has styles attached.

    Is there a parent child selector method available to pick say every anchor tag of an image

    Code:
    a:link < img
    simply put, i want to apply a style to every anchor tag except anchor tags with images nested within the anchors.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •