1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to set a custom link style within a single div?

Discussion in 'CSS' started by diddl14, Feb 12, 2010.

  1. #1
    Hi,

    I'm facing a beginner issue with CSS :confused:

    In the following sample, how can I have link1 use the style in #main and link2 use the style from div2?

    <html>
    <head>
    <style>
    #main a { color:red; }
    .div2 a { color:green; }
    .div2 a:hover { color:blue; }
    </style>
    </head>
    <body>
    <div id="main">
    <div class="div1"><a href='/'>link1</a></div>
    <div class="div2"><a href='/'>link2</a></div>
    </div>
    </body>
    </html
    Code (markup):
    >

    I'm actually trying to customize a site that already includes the "#main a". I've embedded a new HTML component within a div section that requires custom formatting of links. Ideally without changing anything to existing html/css.

    Any insights on what I'm missing here is highly appreciated!

    Frans
     
    diddl14, Feb 12, 2010 IP
  2. pmek

    pmek Guest

    Messages:
    101
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It's a simple fix, you just aren't being specific enough with your css. If you change it to this it will work:

    <style>
    #main a { color:red; }
    #main .div2 a { color:green; }
    #main .div2 a:hover { color:blue; }
    </style>

    Hope this helps.
     
    pmek, Feb 12, 2010 IP
  3. diddl14

    diddl14 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes that did it.

    THANKS! :)
     
    diddl14, Feb 12, 2010 IP