Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Oct 2003
    Posts
    46
    Thanks
    6
    Thanked 0 Times in 0 Posts

    CSS: Different Styles for Different Links

    I have some links which I want controlled by the following CSS which I just use the normal "a href" tag.

    Code:
    a {
    	color: #1f3d63;
    	text-decoration: none;
    }
    a:visited{
    	color: #1f3d63;
    }
    a:hover {
    	text-decoration: underline;
    	color: red;
    Say I wanted some other links to just be white, with perhaps an underline on hover. How would I do this? Creating the CSS isnt the problem, but how would I ensure the link I created is not controlled by the above CSS, but by one telling it to be white with an underline hover.

  • #2
    Regular Coder Jutlander's Avatar
    Join Date
    Jun 2007
    Location
    In my own sick little world :P
    Posts
    425
    Thanks
    1
    Thanked 12 Times in 12 Posts
    You make a class. An example.

    Code:
    a.othercolor {
    color: #fff;
    }
    
    a.othercolor:hover {
    color: #fff;
    text-decoration: underline;
    }
    You then just add the class attribute:

    Code:
    <a class="othercolor" href="#">Link text</a>

  • #3
    New Coder
    Join Date
    Jun 2007
    Location
    Quebec, Canada
    Posts
    64
    Thanks
    4
    Thanked 3 Times in 3 Posts
    if the link has a parent ie. in a div, you could set your whole links inside it being red by example

    Code:
    .redlinks a { color:red }
    Code:
    <div class="redlinks">
    <a href="#">a</a>
    <a href="#">b</a>
    <a href="#">c</a>
    <a href="#">d</a>
    </div>
    Last edited by vexen; 07-02-2007 at 11:09 PM. Reason: # instead of .

  • #4
    Regular Coder Jutlander's Avatar
    Join Date
    Jun 2007
    Location
    In my own sick little world :P
    Posts
    425
    Thanks
    1
    Thanked 12 Times in 12 Posts
    That would add a div or even more to the document. Web developers talk about "div-itis" - when there are too many divs on a page.

  • #5
    New Coder
    Join Date
    Jun 2007
    Location
    Quebec, Canada
    Posts
    64
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Jutlander View Post
    That would add a div or even more to the document. Web developers talk about "div-itis" - when there are too many divs on a page.
    i was using a div as an example, he could apply it to any parent

  • #6
    New Coder
    Join Date
    Oct 2003
    Posts
    46
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thanks for that. Done well.

  • #7
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,785
    Thanks
    6
    Thanked 1,022 Times in 995 Posts
    Just noticed vexen’s use of a class name called “redlinks” and wanted to add that it’s not very semantic. You should name classes and IDs according to the function of an element, not it’s supposed look. Looks can change with a new style. The function usually stays. So better call your elements <div class="message"> if you have a couple of boxes with messages or <div id="header"> if you have an element that contains all header stuff of your page.


  •  

    Posting Permissions

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