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.

Can a div or span be an actual link?

Discussion in 'CSS' started by le007, Oct 3, 2007.

  1. #1
    As question or is LI the only element like this to be a linkable?

    I want something thats has maybe 6 lines of text inside a div that when the div is hovered it changes background colour and or maybe is a link itself...
     
    le007, Oct 3, 2007 IP
  2. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If it weren't for IE 6, you could make a whole div or whatever do something on :hover. If you want, you can use whatever: hover and make IE6 obey.

    Without Js, you'd have to make an anchor around all the text. It would have to be a link which you might not want.

    Something like

    <div> (if needed)
    <a class="box" href="somewhere over the rainbow">Here's a bunch of text etc blah blah</a>
    </div>

    Css:
    a.box {
    style stuff
    }

    a.box:hover {
    stuff for hover
    }

    But if it's not a link, use Js.
     
    Stomme poes, Oct 3, 2007 IP
  3. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    What about hover? Can a div have a separate value for hovering? Change of background etc like opacity for an image?
     
    le007, Oct 3, 2007 IP
  4. Crimsonc

    Crimsonc Peon

    Messages:
    616
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if you set your link to display as a block you can do the same as with a div, background, border what have you

    display: block;
     
    Crimsonc, Oct 3, 2007 IP
  5. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    Ok thanks, I'll give it a go
     
    le007, Oct 3, 2007 IP
  6. Arnold9000

    Arnold9000 Peon

    Messages:
    241
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    That is exactly correct, and it couldn't be easier. IE is not a problem at all.
     
    Arnold9000, Oct 3, 2007 IP
  7. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #7
    The only problem is, you can't have other separate links inside that?
    EG
    Link1

    Link2

    inside a link set to 100px height, 300px width - display: block;

    or can you?
     
    le007, Oct 3, 2007 IP
  8. Arnold9000

    Arnold9000 Peon

    Messages:
    241
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #8

    Well it sounds to me that you don't want links within links as this is impossible and it would be silly anyway. What you want is a color change of the general area on hover, with no linking, and then multiple individual links within that. But why do you want to even change the color of the larger area, that contains the multiple links, when it's hovered over, when the larger area doesn't represent a link? So there is something more that I need to know before I can answer you because something doesn't make sense to me.
     
    Arnold9000, Oct 3, 2007 IP
  9. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #9
    Yes you've got it in 1 - but I just want the are highlighted to emphasise is more, say its section "New Articles" or something like that, yes I just want an area that background changes on hover
     
    le007, Oct 3, 2007 IP
  10. Arnold9000

    Arnold9000 Peon

    Messages:
    241
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Do you want it to change when any of the links inside are hovered over? Do you want the larger area to be a different color depending on which link is hovered over? Do you want the specific area around the specific link to change color also so that the larger area changes color and the area around the link you mouse over changes too? What I'm doing is to try and understand better and get you to visualize what you might be asking for, because from a usability pov, it doesn't seem to make any sense. So I apologize, but I still must not be understanding you correctly. Sorry if I'm thick.
     
    Arnold9000, Oct 3, 2007 IP
  11. MetaTitan

    MetaTitan Peon

    Messages:
    141
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Something like this should do what you're looking for I think...
    <div onmouseover="this.style.backgroundColor='#e7e7e7';" onmouseout="this.style.backgroundColor='#ffffff';">test</div>
    Code (markup):
     
    MetaTitan, Oct 3, 2007 IP
  12. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #12
    Absolutely no problem! I would like:

    1) main larger area to change bg colour when hovered
    2) links maybe underlined when hovered

    Thats it - the rest I can add if necessary
     
    le007, Oct 3, 2007 IP
  13. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #13
    MetaTitan thanks for the input buddy but I was looking for a css way - but actually that works well too!!! Is that js?
     
    le007, Oct 3, 2007 IP
  14. MetaTitan

    MetaTitan Peon

    Messages:
    141
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Yes, onmouseover/out events are JavaScript.
     
    MetaTitan, Oct 3, 2007 IP
  15. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #15
    Ok thanks for that - I may use it sometime
     
    le007, Oct 3, 2007 IP
  16. Arnold9000

    Arnold9000 Peon

    Messages:
    241
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Well if you care about IE6, you'll have to use the javascript method. Firefox supports the hover psuedo class for other elements besides the <a> tag, but IE6 (and maybe 7) does not.
     
    Arnold9000, Oct 3, 2007 IP
  17. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #17
    Ok so thats it? I was toying around with a div inside the <a href> it was actually working! I'm not sure yet what to use...
     
    le007, Oct 3, 2007 IP
  18. Arnold9000

    Arnold9000 Peon

    Messages:
    241
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #18
    I'd like to see the code
     
    Arnold9000, Oct 3, 2007 IP
  19. codyrockx

    codyrockx Peon

    Messages:
    33
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #19
    I'd go with a :hover pseudo class in your css. Supporting IE6 is great and all, but in the long run, doing so only to provide small emphasis on a link is too much work IMO to support IE6 by throwing a mess of JS in there that no other browser needs.
     
    codyrockx, Oct 3, 2007 IP
  20. Arnold9000

    Arnold9000 Peon

    Messages:
    241
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Good point. I hate IE too. But suppose he's doing this at a professional level for a client? Do you think his client wants to hear people with IE tell him there's weird things about his website? Do you think his client is going to want to tell his customers not to use IE? I've heard this before, but unfortunately, it isn't acceptable for professional websites. And, if you look at the suggested javascript code, it is one very simple line using a mouseover event instead a hover psuedo class. This isn't really going to get in the way. But maybe he has figured something else out, which is why I'd like to see what he might have found out or what he's working on. He says he has something that works, and I guess he means in IE as well when he says it works. So this makes me curious.
     
    Arnold9000, Oct 3, 2007 IP