A style that will make the entire cell "clickable" in a Menu

Here's a quick tip for the Menu control.  I'm pretty sure there were some good reasons why this wasn't the default but I just can't think of them at the moment. [EDIT: I just remembered one of them, this won't work perfectly with ItemSpacing...]

If you want to make the entire cell clickable (and not just the text), try using a style "display:block; width:100%".  You'll only want to apply this to the <A> inside the cells. 

Here's an example:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

html xmlns="http://www.w3.org/1999/xhtml" >
head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .smis a { width:100%; display:block; }
    <form id="form1" runat="server">
        <asp:Menu ID="Menu1" runat="server" BackColor="Green" Width="200px">
                <asp:MenuItem Text="ItemA" Value="A"></asp:MenuItem>
                <asp:MenuItem Text="ItemB" Value="B"></asp:MenuItem>
            <StaticHoverStyle BackColor="#FF8080" />
            <StaticMenuItemStyle CssClass="smis" />


(ps. Thanks to Pete for helping me figure this out)

Comments (4)
  1. ON says:

    Is this possible with a treeview control? I’d like to get a highlight/click feature working for all the children of a parent node but there’s always a small space on the left of the LeafNode that I can’t get rid of

  2. Thanks Danny – this works perfectly.

  3. dannychen says:


     I don’t think so.  As I said in this post, the does not work in every situation.  This only makes the link (with it’s hover style) expand to the size of it’s encapsulating container (a <TD>).  If the area you want to hover/click consists of more than a single TD, you’re out of luck.  In the case of the TreeView, you’re running into the border between TDs.  



  4. You are voted (great) – Trackback from Web Development Community

Comments are closed.

Skip to main content