Grow your CSS skills. Land your dream job.

CSS to style "jump to" links differently than other links?

  • # July 1, 2009 at 8:36 pm

    Hello. I’m a web design newbie and was happy to discover this site because I love the idea of CSS and am having fun figuring out how to employ it appropriately. I am hoping that some more experienced designers can help me apply a specific style to a specific kind of link. To allow users to jump to a specific page section- let’s call it Leeroy Jenkins- I am currently using

    Code:
    a href=#section1>jump to: Leeroy Jenkins

    at the top of the page and

    Code:
    a name=”#section1″>Leeroy Jenkins

    where the section starts.

    My style.css page styles links as

    Code:
    #main a { color: #CC3300; text-decoration: underline; font-weight: bold }

    .
    I would like the jump to links at the top of the page and the links at the beginning of each section to NOT be underlined. I understand that there is a way to do this with id or class attributes, but I can’t figure out what goes in the html & where and what goes in my style sheet & where.

    What I have tried is adding

    Code:
    a.jumpto {text-decoration:none;}

    to my style sheet and using

    to create the link at the top of the page. This results in the non-underlined style I want for the first link, but the link at the beginning of the section, which is currently

    is still underlined.

    I would greatly appreciate your feedback and suggestions. As I’m rather new to this, I’m afraid that I need someone to spell out very specifically what goes where (add ABC to the style sheet, use XYZ where you’re currently using [my code]).

    My CSS:

    Code:
    body
    {
    margin: 0;
    padding: 0;
    background: #FFF;
    font-family: “arial”, “verdana”, “tahoma”, “times new roman”;
    font-size: 90%;
    color: #444;
    }

    #headercont
    {
    margin: 0 auto;
    width: 100%;
    height: 150px;
    background: #333 url(‘../images/background-headercont.png’) repeat-x;
    }

    #header
    {
    margin: 0 auto;
    width: 800px;
    height: 150px;
    }

    #header h1
    {
    text-align: right;
    margin: 0;
    padding: 52px 0 0 0;
    font-size: 275%;
    color: #CC3300;
    letter-spacing: -2px;
    font-weight: normal;
    }

    #header h1 span
    {
    color: #FFF;
    font-weight: bold;
    }

    #menucont
    {
    margin: 0 auto;
    width: 100%;
    height: 40px;
    background: #CC3300 url(‘../images/smithbackground-menucont.png’) repeat-x;
    }

    #menu
    {
    margin: 0 auto;
    width: 800px;
    height: 40px;
    }

    #menu ul
    {
    float: right;
    margin: 0;
    padding: 0;
    list-style-type: none;
    font-weight: bold;
    }

    #menu ul li
    {
    display: inline;
    }

    #menu ul li a
    {
    float: left;
    padding: 12px 15px;
    text-decoration: none;
    color: #FFF;

    }

    #menu ul li a.active
    {
    background: #333 url(‘../images/smithbackground-menucont-active.png’) repeat-x;
    }

    #menu ul li a:hover
    {
    background: #333 url(‘../images/background-menucont-hover.png’) repeat-x;
    }

    #maincont
    {
    margin: 0 auto;
    width: 100%;
    background: #FFF url(‘../images/background-maincont.png’) repeat-x;
    line-height: 150%;
    }

    #main
    {
    margin: 0 auto;
    width: 800px;
    padding: 40px 0 15px 0;
    }

    #main h1, h2, h3, h4, h5
    {
    margin: 0 0 15px 0;
    padding: 0;
    font-size: 200%;
    color: #CC3300;
    letter-spacing: -2px;
    font-weight: bold;
    }
    h2 {
    font-size:175%;
    font-weight: normal;
    }

    h3 {
    font-size:150%;
    font-weight: normal;
    }

    #main p
    {
    margin: 0 0 15px 0;
    padding: 0;
    }

    #main img
    {
    float: right;
    margin: 0 0 10px 10px;
    border: 1px solid #AAA;
    }

    #main a
    {
    color: #CC3300;
    text-decoration: underline;
    font-weight: bold;
    }

    #main a:hover
    {
    color: #333;
    text-decoration: underline;
    font-weight: bold;
    }

    .vcenter {
    min-height: 12em;
    display: table-cell;
    vertical-align: middle;
    }

    #footercont
    {
    margin: 0 auto;
    width: 100%;
    line-height: 150%;
    font-size: 85%;
    font-weight: bold;
    }

    #footer
    {
    margin: 0 auto;
    width: 800px;
    border-top: 1px solid #CCC;
    padding: 0 15px;
    color: #999;
    }

    #footer p
    {
    margin: 0;
    padding: 0;
    }

    #footer a
    {
    color: #CC3300;
    text-decoration: none;
    }

    #footer a:hover
    {
    color: #333;
    text-decoration: none;
    }

    #footerleft
    {
    float: left;
    width: 250px;
    padding: 15px 0;
    }

    #footerright
    {
    float: left;
    width: 550px;
    padding: 15px 0;
    text-align: right;
    }

    And some sample code:

    Code:
    jump to: Leeroy Jenkins
    jump to: I Love CSS

    Leeroy Jenkins

    Here is some stuff about Leeroy Jenkins.

    I Love CSS

    Here is some stuff about why I Love CSS.

    My objective in all this is to differentiate the "jump to" links and their destinations from the other links on my site.
    Thanks in advance,
    Melissa

    # July 2, 2009 at 3:26 am

    Wow. That’s a hell of an explanation for a very simple request. :D

    Just add the class "jumpto" to all the links that you don’t want underlined.

    # July 2, 2009 at 10:53 am
    Code:
    .jumpto {text-decoration: none;}

    Leeroy Jenkinds

    should do the trick

    # July 2, 2009 at 12:48 pm

    Thanks for the responses.

    To get it to work, I ended up having to use

    Code:
    #main a.jumpto {text-decoration: none;}

    instead of the suggested

    Code:
    .jumpto {text-decoration: none;}

    I am assuming that this is okay since it validates and does what I want it to do?

    I could not get

    to validate, so I am using

    but that’s an XHTML thing, I suppose.

    Thanks again for the quick and helpful suggestions.

    # July 2, 2009 at 4:14 pm

    No, it would actually be incorrect to put the "id" in like that.

    I think you might have the "name" and "href" mixed up.

    <a href="#jiggins" class="jumpto">Check out the Jiggins</a> (note how it’s still a ‘href’)

    will link to:

    <a name="jiggins"></a>This is where your content for the Jiggins section will be. (note how this is ‘name’)

    Because you were putting name="#xxxxx" is probably why it wasn’t validating.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".