#border #header-wrapper #header-wrapper-upper #social-top a {
float: left;
background: url('../images/social_media.png') no-repeat;
height: 35px;
text-decoration: none;
width: 35px;
}
#border #header-wrapper #header-wrapper-upper #social-top a.twitter {
background-position: 0 0;
}
#border #header-wrapper #header-wrapper-upper #social-top a.twitter:hover {
background-position: 0 - 35;
}
#border #header-wrapper #header-wrapper-upper #social-top a.facebook {
background-position: -35 0;
}
#border #header-wrapper #header-wrapper-upper #social-top a.facebook:hover {
background-position: -35 - 35;
}
#border #header-wrapper #header-wrapper-upper #social-top a.be {
background-position: -70 0;
}
#border #header-wrapper #header-wrapper-upper #social-top a.be:hover {
background-position: -70 - 35;
}
这是我的css代码,但是当我查看页面时,它只显示a.twitter,当我悬停时没有任何反应,它只是保持a.twitter。对于a.facebook,它也显示了a.twitter e.c。
这是html代码 -
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>index</title>
<link rel="stylesheet" href="css/stylesheet.css" />
</head>
<body>
<!-- Header background starts -->
<div id="header"></div>
<!-- Header Background ends -->
<!-- Middle content starts -->
<div id="border">
<!-- Header Wrapper starts -->
<div id="header-wrapper">
<!-- Header upper Part starts -->
<div id="header-wrapper-upper">
<img src="images/logo.png" alt="Season Logo" title="Season logo" id="logo" />
<div id="social-top">
<a href="#" class="twitter"> </a>
<a href="#" class="facebook"> </a>
<a href="#" class="be"> </a>
</div>
</div>
<!-- Header upper Part ends -->
</div>
<!-- Header Wrapper Ends -->
</div>
<!-- Middle Content ends -->
</body>
</html>
任何线索?第一次使用精灵,所以我不太确定。控制台中没有任何东西显示出来。
JSfiddle - http://jsfiddle.net/kEQUw/
答案 0 :(得分:3)
将'px'添加到背景位置
离。
答案 1 :(得分:0)
在CSS中,减号和35之间是否真的有空格?你在验证器中检查了CSS和HTML吗?
答案 2 :(得分:0)
仅供记录。因为构建your sprite的方式(图标之间有空格),您可以使用spritecow online tool来获取精灵每个元素的正确值。
所以你的正确代码应该是:
#border #header-wrapper #header-wrapper-upper #social-top a {
float: left;
background: url('../images/social_media.png') no-repeat;
height: 32px; /* not 35 */
width: 32px;
text-decoration: none;
display: block; /* NEW */
}
#border #header-wrapper #header-wrapper-upper #social-top a.twitter {
background-position: -2px -3px;
}
#border #header-wrapper #header-wrapper-upper #social-top a.twitter:hover {
background-position: -2px -38px;
}
#border #header-wrapper #header-wrapper-upper #social-top a.facebook {
background-position: -52px -2px;
}
#border #header-wrapper #header-wrapper-upper #social-top a.facebook:hover {
background-position: -52px -37px;
}
#border #header-wrapper #header-wrapper-upper #social-top a.be {
background-position: -103px -2px;
}
#border #header-wrapper #header-wrapper-upper #social-top a.be:hover {
background-position: -103px -37px;
}