【发布时间】:2021-12-02 05:48:05
【问题描述】:
你好,这是我目前的 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;
}
我为每个按钮使用相同的图像,这是一个偷偷摸摸的高峰:
这是页面的样子:):
如您所见,两个按钮都正确显示。主要问题是,当我将鼠标悬停在它们上方时,我希望灰色的出现......但他们没有,我不明白为什么......在我看来,我的代码很好。有人知道吗?
【问题讨论】:
-
查找背景图像的语法,例如在developer.mozilla.org/en-US/docs/Web/CSS/background-image 它有一个(或多个)图像,但没有其他设置,如无重复。也许您打算使用背景?