代码之家  ›  专栏  ›  技术社区  ›  Rod

单击后仍保留css样式

  •  1
  • Rod  · 技术社区  · 15 年前

    我有一个简单的测试页面,带有一个样式化的按钮。当你将鼠标悬停在按钮上时,我使用的是:hover。但是,当您单击按钮时,a:悬停样式将保留,直到我单击其他内容。我该如何解决这个问题?为什么会发生这种情况?

    谢谢,

    <asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    
        <% using (Ajax.BeginForm(new AjaxOptions { }))
           { %>
        <div id="detailActions">
            <a href="#">Delete User</a>
        </div>
        <% } %>
    </asp:Content>
    

    我的CSS:

    #detailActions
    {
        margin-bottom: 7px;
        padding: 3px 0px 5px 0px;
    }
    #detailActions
    {
        padding: 1px 7px 1px 7px;
        margin: 0px 5px 0px 0px;
        border: solid 1px gray;
        background-color: #ADD8E6;
        cursor: pointer;
        width: auto !important;
        font-weight: bold;
        text-decoration: none;
        color: #003366;
        font-size: 1.2em;
    }
    
    #detailActions a:hover, #detailActions a:active, #detailActions a:focus
    {
        color: White;
        background-color: #00008B;
    }
    
    1 回复  |  直到 15 年前
        1
  •  3
  •   Deniz Dogan    15 年前

    这是最重要的 a:focus 这让它看起来像 a:hover 规则已激活。

    拆下 a:聚焦 规则和它应该是罚款。