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

如何使我的css:hover工作?

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

    下面是我正在使用的CSS。带的分区 大按钮 它上的类可以工作,但悬停除外。我想改变它的背景色,但不知道为什么它不起作用。有什么想法吗?

    编辑 -我现在在FF工作。我不想在IE6中寻求支持,也可能不是IE7。

    .top .bottombar .largebutton
    {
        position: relative;
        float: left;
        height: 100%;
        width: 195px;
        font-size: 13px;
        letter-spacing: 1px;
        text-transform:uppercase;
        line-height: 33px;
        text-align: right;
        background-color: #99CCFF;
        margin-left: 5px;
        padding-right: 5px;
        overflow: hidden;
        cursor: pointer;
    }
    
    .top .bottombar .largebutton:hover
    {
        background-color: #9999FF;
    }
    

    编辑 -完整文件

    HTML

    <html>
        <head>
            <link rel="StyleSheet" href="css/LCARS.css" type="text/css" media="screen">
        </head>
        <body>
            <div class="top">
                <div class="content">
                </div>
                <div class="leftbuttonbox">
                    <div class="button">
                    Label
                    </div>
                    <div class="largebutton">
                    Label
                    </div>
                    <div class="button">
                    Label
                    </div>
                </div>
                <div class="bottombar">
                    <div class="button">
                    Label
                    </div>
                    <div class="largebutton">
                    Label
                    </div>
                    <div class="button">
                    Label
                    </div>
                    <div class="label">
                        This is a label, it grows as large as it needs to
                    </div>
                </div>
                <div class="cap">
                    <div class="capinner">
                    </div>
                </div>
            </div>
        </body>
    </html>
    

    CSS

    @font-face {
        font-family: "LCARS";
        src: url('../FONT/lcars.ttf');
    }
    
    body
    {
        font-family: "LCARS";
        position: relative;
        background-color: black;
        padding: 0px;
        margin: 0px;
    }
    
    .top
    {
        position: relative;
        height: 220px;
        min-width: 100px;
        margin-top: 5px;
        margin-left: 5px;
        margin-right: 5px;
        background-color: #6666FF;
        -moz-border-radius-bottomleft: 50px;
    }
    
    .top .content
    {
        position: absolute;
        top: 0px;
        right: 0px;
        left: 100px;
        bottom: 25px;
        background-color: black;
        -moz-border-radius-bottomleft: 25px;
    }
    
    .top .leftbuttonbox
    {
        position: absolute;
        top: 0px;
        left: 0px;
        width: 100px;
        bottom: 60px;
        background-color: black;
        overflow: hidden;
    }
    
    /*
     * the button is 1/2 the size of the large button
     * the button box can hold 4 buttons or 2 large
     * buttons or any combination of equal size
     */
    .top .leftbuttonbox .button
    {
        position: relative;
        height: 35px;
        width: 95px;
        font-size: 13px;
        letter-spacing: 1px;
        text-transform:uppercase;
        line-height: 53px;
        text-align: right;
        background-color: #99CCFF;
        margin-bottom: 5px;
        padding-right: 5px;
        overflow: hidden;
        cursor: pointer;
    }
    
    .top .leftbuttonbox .button:hover
    {
        background-color: #9999FF;
    }
    
    .top .leftbuttonbox .largebutton
    {
        position: relative;
        height: 75px;
        width: 95px;
        font-size: 13px;
        letter-spacing: 1px;
        text-transform:uppercase;
        line-height: 133px;
        text-align: right;
        background-color: #99CCFF;
        margin-bottom: 5px;
        padding-right: 5px;
        overflow: hidden;
        cursor: pointer;
    }
    
    .top .leftbuttonbox .largebutton:hover
    {
        background-color: #9999FF;
    }
    
    .top .bottombar
    {
        position: absolute;
        bottom: 0px;
        height: 25px;
        left: 200px;
        padding-right: 5px;
        background-color: black;
        overflow: hidden;
    }
    
    .top .bottombar .button
    {
        position: relative;
        float: left;
        height: 100%;
        width: 95px;
        font-size: 13px;
        letter-spacing: 1px;
        text-transform:uppercase;
        line-height: 33px;
        text-align: right;
        background-color: #99CCFF;
        margin-left: 5px;
        padding-right: 5px;
        overflow: hidden;
        cursor: pointer;
    }
    
    .top .bottombar .button:hover
    {
        background-color: #9999FF;
    }
    
    .top .bottombar .largebutton
    {
        position: relative;
        float: left;
        height: 100%;
        width: 195px;
        font-size: 13px;
        letter-spacing: 1px;
        text-transform:uppercase;
        line-height: 33px;
        text-align: right;
        background-color: #99CCFF;
        margin-left: 5px;
        padding-right: 5px;
        overflow: hidden;
        cursor: pointer;
    }
    
    .top:hover .bottombar:hover .largebutton:hover
    {
        background-color: #9999FF;
    }
    
    .top .bottombar .label
    {
        position: relative;
        float: left;
        height: 100%;
        min-width: 50px;
        font-size: 22px;
        letter-spacing: 1px;
        font-variant: small-caps;
        padding-left: 5px;
        padding-right: 5px;
        background-color: #CC99CC;
        margin-left: 5px;
        cursor: default;
    }
    
    .top .cap
    {
        position: absolute;
        height: 25px;
        width: 20px;
        right: 0px;
        bottom: 0px;
        padding-left: 5px;
        padding-right: 5px;
        background-color: black;
        cursor: default;
    }
    
    .top .cap .capinner
    {
        position: relative;
        height: 100%;
        width: 100%;
        background-color: #6666FF;
        cursor: default;
        -moz-border-radius-topright: 50%;
        -moz-border-radius-bottomright: 50%;
    }
    
    3 回复  |  直到 15 年前
        1
  •  1
  •   mingos    15 年前
    div.top div.bottombar div.largebutton:hover
    {
        background-color: #9999FF;
    }
    

    我认为这是火狐的一个漏洞。有时,当您为嵌套类添加CSS而不指定这些类应用于哪些元素时,浏览器会变得疯狂。您的代码在其他浏览器中工作正常,所以从技术上讲,这不是您的错,而是FF的错;)

        2
  •  1
  •   Amit    15 年前

    我建议这个解决方案:

    .top .largebutton:hover
    {
        background-color: #9999FF; /* make this whatever color it was before */
    }
    

    当我用你的完整代码尝试它时,这对我很有用。 希望它对你有用:)

    阿米特

        3
  •  0
  •   scaryguy    15 年前

    设计链接样式的关键概念指向以下步骤:

    1. 您必须声明4种不同条件的样式 a:link , a:visited , a:hover , a:active .
    2. 你得小心点。因为这很重要。链接>已访问>悬停>活动。(尤其是有:悬停和:参观过的工作…)
    3. 尽管你不需要一个或多个条件的样式,但是,所有的样式。

    如果你注意这些,你可能有完美的风格链接。

    希望能有所帮助。

    推荐文章