次の方法で共有


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" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

 

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

Comments

  • Anonymous
    April 29, 2006
    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
  • Anonymous
    April 29, 2006
    Thanks Danny - this works perfectly.
  • Anonymous
    May 01, 2006
    ON:
     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.  
    --
    Danny
     
  • Anonymous
    November 10, 2008
    You are voted (great) - Trackback from Web Development Community