【问题标题】:How can I make my css :hover work?我怎样才能让我的 css :hover 工作?
【发布时间】:2010-09-12 10:51:50
【问题描述】:

Bellow 是我正在使用的 CSS。除了悬停之外,带有 largebutton 类的 div 可以正常工作。我希望它改变它的背景颜色,但不知道为什么它不起作用。有什么想法吗?

edit - 我现在在 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%;
}

【问题讨论】:

  • 这在哪些浏览器上不起作用?
  • 在 IE6 中 :hover 仅适用于锚点
  • 那么在这种情况下,sn-p 没有任何问题。您的问题可能出在其他地方。
  • 易 - 不知道还能在哪里。我附上了 HTML 和 CSS。
  • @Justin:见:jsfiddle.net/4DZUH。它在受控环境中工作。你一定遗漏了什么。您还应该减少此处的大多数选择器,样式过于重复,并且您还需要定义 font-family 后备以防 @font-face 字体无法加载

标签: css hover


【解决方案1】:
div.top div.bottombar div.largebutton:hover
{
    background-color: #9999FF;
}

我认为这是 Firefox 中的一个错误。有时,当您为嵌套类添加 CSS 而不指定它们应用到哪些元素时,浏览器会发疯。您的代码在其他浏览器中运行良好,所以从技术上讲这不是您的错,而是 FF 的 ;)

【讨论】:

  • 这适用于我的 HTML。我还注意到我忘记了一个文档类型。添加它使其无需更改即可工作。 ttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" rel="nofollow" target="_blank">w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  • 那么可能是 FF 怪癖模式奇怪;)
【解决方案2】:

我建议这个解决方案:

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

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

阿米特

【讨论】:

    【解决方案3】:

    设置链接样式的关键概念有以下几个步骤:

    1. 您必须声明 4 种不同条件的样式,它们是 a:linka:visiteda:hovera:active
    2. 您必须小心订单。因为这很重要。链接>访问>悬停>活动。 (尤其是有 :hover 和 :visited 工作...)
    3. 尽管您不需要为一个或多个条件设置样式,但仍要为它们设置样式。

    如果您注意这些,您可能拥有完美样式的链接。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2013-07-22
      • 2021-01-22
      • 2011-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-28
      • 2016-07-26
      • 1970-01-01
      相关资源
      最近更新 更多