SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Linking Hell

  1. #1
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Linking Hell

    I am a css newbie. I have read and followed the FAQ on different coloured links. Unfortunately I have obviously done something simple wrong, but I can't for the life of me see what it is. My setup something like that shown below:

    In the stylesheet :
    ...
    .linkclass1 a:link a:visited {
    color: #0000FF;
    background-color: #FFFccc;
    }

    .linkclass2 a:link a:visited {
    color: #DDAAFF;
    }
    ...


    In the HTML:
    ...
    <div class="linkclass1">
    <a ....>A Link</a>
    </div>

    <div class="linkclass2">
    <a ....>Another Link</a>
    <div>
    <a ...>A SUBLINK</a>
    </div>
    </div>

    <div>
    <a ....>Yet another Link</a>
    </div>

    My problem is that the link styles don't seem to limit themselves to just the links contained in the DIVs of the corresponding class. What I mean is
    1 - The DIV which has no class set seem to get affected by the styles above. I assume it shouldn't.
    2 - Only one of the DIVs which does have a class will be correct, the other seems to inhert certain atributes from the other defined link style.
    3 - The link SUBLINK above looks to me like it should be of style linkclass2 but it is not styled at all.

    The way in which the styles get affected seems to be dependant on the order in which the styles appear in the stylesheet, the browser seems to be 'hanging on' to the last style it finds and applying it al over the place. It does the same thing in Firefox and IE.

    Anyone seen anything like this before? One thing that occured to me - could this be cause by me getting my DIV tags out of sync, e.g. missing a </DIV>?

    Any help will be greatly appreciated and will probably prevent further hairloss.

    Luke.

  2. #2
    SitePoint Wizard bronze trophy Tyssen's Avatar
    Join Date
    Oct 2005
    Location
    Brisbane, QLD
    Posts
    4,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should be .linkclass1 a:link, .linkclass1 a:visited etc.

  3. #3
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!

    Out of interest can you use IDs instead? e.g.:

    #linkID1 a:link, #linkID1 a:visited {
    ...
    }

  4. #4
    SitePoint Wizard bronze trophy Tyssen's Avatar
    Join Date
    Oct 2005
    Location
    Brisbane, QLD
    Posts
    4,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use IDs but if the style is applied to more than one link, then it needs to be a class. IDs can only be used once per page.


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
  •