#id:hover { background: no-repeat url(...);} 不起作用?

#id:hover { background: no-repeat url(...);} not working?

你好,这是我目前的 html 代码:

<!DOCTYPE html>
<html lang = "fr">
    <head>
        <meta charset="utf-8"/>
        <!-[if lt IE 7]>
            <link rel="stylesheet" type="text/css" href="ie6.css"/>
        <![endif]->
        <link rel="stylesheet" type="text/css" href="tp1.css"/>
        <title>TP1::Acceuil</title>
    </head>
    <body>
        <div id = "banner"></div>
        <div id = "container">
            <div id = "header">
                <div id = "header_button_enregistrer" class = "header_button"></div>
                <div id = "header_button_identifier" class = "header_button"></div>
            </div>
            <div id = "contents"></div>
            <div class = "clearfooter"></div>
        </div>
        <div id = "footer"></div>
    </body>
</html>

它还没有完成所以别担心:) 我的问题在于 header_button div... 这是我的 CSS 代码:

html, body {
    height: 100%;
}

body {
    background: no-repeat url(background.jpg);
    background-size: cover;
    background-attachment: fixed;
    background-position: center center;
    background-color: #f2f2f2;
}

#banner {
    background: repeat url(banner_background.png) #f2f2f2;
    height: 158px;
    width: 100%;
    position: absolute;
    margin-top: -10px;
    margin-left: -10px;
    margin-right: -10px;
    z-index: 0;
}

#container {
    display: block;
    width: 980px;
    min-height: 100%;
    position: relative;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: -99px;
}
    
#footer {
    background: repeat url(footer_background.png) #f2f2f2;
    height: 99px;
    position: relative;
    margin-left: -10px;
    margin-right: -10px;
}

#header {
    display: block;
    height: 158px;
    z-index: 0;
}

#contents {
    background-color: #5c7dad;
    border: 1px solid #5c7dad;
    position: relative;
    webkit-border-radius: 5px;
    moz-border-radius: 5px;
    border-radius: 5px;
}

#header_button_enregistrer {
    background: no-repeat url(banner_button1.png);
    background-position: -135px 0px;
}
#header-button-enregistrer:hover {
    background-image: no-repeat url(banner_button.png);
    background-position: -135px -39px;
}

#header_button_identifier {
    background: no-repeat url(banner_button1.png);
    background-position: 0px 0px;
    margin-left: 20px;
}

#header-button-identifier:hover {
    background-image: no-repeat url(banner_button1.png);
    background-position: 0px -39px;
}

.clearfooter {
    height: 99px;
    clear: both;
}

.header_button {
    cursor: pointer;
    height: 39px;
    margin-top: 15px;
    width: 135px;
    float: left;
}

我为每个按钮使用相同的图像,这是一个先睹为快:

页面如下:):

如您所见,两个按钮均正确显示。主要问题是,当我将鼠标悬停在它们上方时,我希望灰色的出现……但它们没有,我也不明白为什么……在我看来我的代码很好。有人知道吗??

可能是因为您这里有错字...您在 HTML 中用下划线定义了您的 ID,在 CSS 中用“-”称呼它“