-1

I am a complete newbie and I posted another question to help me out to get a DIV with a LIST inside and then make the entire DIV clickable/link-able with when hover over it, it changes color.

I messed it up with all kinds of stunts and now I am looking forward to know what's the best way to do this.

Thanks a lot.

Sourabh
  • 8,243
  • 10
  • 52
  • 98
bgree
  • 39
  • 1
  • 2
  • 9
  • Welcome to Stack Overflow Simon! At Stack Overflow, we don't write code for you. This site is for help with trying to fix your code, not giving you code. If you want people to help you, then you are going to need to show some evidence of research – Cody Guldner May 27 '13 at 22:29
  • Hi Cody, here is my evidence of research... http://stackoverflow.com/questions/16776332/make-an-entire-div-linkable-when-a-module-is-loaded-inside-to-it – bgree May 27 '13 at 23:14

4 Answers4

0

It can be done fairly simply with CSS.

To make the "clickable area" of the link take up the whole div add display:block to the CSS for that link.

Colour changing on mouse hover can also be done with CSS, like this:

a:hover {
    background-color:green;
}

My understanding is that you're looking to make an entire list into a single link. It seems a little odd, but all it takes is putting the <a> tags on the outside of the <ul> or <ol> tags, like this:

<a href="yourlink.html">
<ul>
    <li>List Item 1</li>
    <li>List Itme 2</li>
</ul>
</a>

Check out http://www.w3schools.com for excellent beginner web development tutorials.

Kyle G.
  • 870
  • 2
  • 10
  • 22
0

Try this:

HTML

<div class="clickable">
<ul>
    <li>hello</li>
    <li>world</li>
</ul>

CSS:

.clickable {
background-color: #ddd;
}

.clickable:hover {
    background-color: #8F8
}

Test:

http://jsfiddle.net/guPan/

If you want to act this like a link, you better just use a link tag and set display: block css for it

Jakub Matczak
  • 15,341
  • 5
  • 46
  • 64
0

a few things you need to know:

  1. you can make an anchor (<a>) that acts like a <div> by setting:

    a{display:block;}

  2. to make the link background change color on hover use:

    a:hover {background:red;}

  3. you can add an ordered list inside (valid in HTML5) like this:

    <a title="My Link" href="http://www.somelinkurl.com">
      <ol>
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
      </ol></a>
    
Yotam Omer
  • 15,310
  • 11
  • 62
  • 65
0

Set width and height for the anchor tag and to declare it display:block.

<!DOCTYPE HTML>
<html>
    <head>
        <title></title>
        <style type="text/css">
            #link {
                width:300px;
                height:300px;
            }
            #link a {
                width:300px;
                height:300px;
                display:block;
                background-color:orange;
            }
            #link a:hover {
                background-color:red;
            }
        </style>
    </head>
    <body>
        <div id="link">
            <a href="#">I am a Link</a>
        </div>
    </body>
</html>
Touhid Rahman
  • 2,455
  • 21
  • 22