views:

1557

answers:

5

I have the following markup,

<ul id="menu">              
    <li><a href="#">Something1</a></li>
    <li><a href="#">Something2</a></li>
    <li><a href="#">Something3</a></li>
    <li><a href="#">Something4</a></li>
</ul>

The <li> is a bit big, with a small image on its left, I have to actually click on the <a> to activate the link. How can I make a click on the <li> activate the link?

Edit1:

ul#menu li
{
    display:block;
    list-style: none;
    background: #e8eef4 url(images/arrow.png) 2% 50% no-repeat;
    border: 1px solid #b2b2b2;
    padding: 0;
    margin-top: 5px;
}

ul#menu li a
{

    font-weight: bold;
    text-decoration: none;
    line-height: 2.8em;
    padding-right:.5em;
    color: #696969;
}
+9  A: 
#menu li { padding: 0px; }
#menu li a { margin: 0px; display: block; width: 100%; height: 100%; }

It may need some tweaking for IE6, but that's about how you do it.

MiffTheFox
This is how I would do it. It expands the link to the size of the <li> tag.
Austin Hyde
Its working, but the text(link) is sticking to the right border, when I gave a padding-right: .5em the <a> is going out of <li>
San
Keep tweaking and you'll get it looking perfect. Check for negative margins and padding, something probably isn't adding up and its collapsing. Also, make sure you don't have an errant text-align: right; stuck in there.
Curtis Tasker
I gave the text(link) a right padding by actually giving the the <li> a padding-right:0.5em and having the <li> and <a> having the same background color. But now that .5em right part of <li >is not click able, but that's fine.
San
A: 

You could try an "onclick" event inside the LI tag, and change the "location.href" as in javascript.

You could also try placing the li tags within the a tags, however this is probably not valid HTML.

Marineio
In my experience, faking links through Javascript almost always results in a poor user experience.
Chuck
It is simply one option for him to consider, after all it is his website. And he could keep the normal <a> link there, and it would function as normal even if Javascript were turned off (just not if the li were clicked).
Marineio
+1  A: 

As Marineio said, you could use the onclick attribute of the <li> to change location.href, through javascript:

<li onclick="location.href='http://example';"&gt; ... </li>

Alternatively, you could remove any margins or padding in the <li>, and add a large padding to the left side of the <a> to avoid text going over the bullet.

Eric
A: 

The following seems to work:

ul#menu li a {
    color:#696969;
    display:block;
    font-weight:bold;
    line-height:2.8;
    text-decoration:none;
    width:100%;
}
Sinan Ünür
A: 

How to make the HTML link activated by clicking on the <li> ?

By making your link as big as your li: just move the instruction

display: block;

from li to a and you are done.

That is:

#menu li
{
    /* no more display:block; on list item */

    list-style: none;
    background: #e8eef4 url(arrow.gif) 2% 50% no-repeat;
    border: 1px solid #b2b2b2;
    padding: 0;
    margin-top: 5px;
}

#menu li a
{
    display:block; /* moved to link */
    font-weight: bold;
    text-decoration: none;
    line-height: 2.8em;
    padding-right:.5em;
    color: #696969;
}

Side note: you can remove "ul" from your two selectors: #menu is a sufficient indication except if you need to give weight to these two rules in order to override other instructions.

Felipe Alsacreations