将鼠标悬停在文本 link 上会更改图像的 z-index
Hover on text link changes z-index of an image
我有一个项目列表作为常规文本 links 和一组疯狂和偏移堆叠在一起的图像,它们应该重叠一点但不会完全覆盖彼此。它们要么放置在固定位置,要么随机放置在每个负载上,以更容易的方式放置。每个文本 link 应该 "connected"(不是 linked!)到这些图像之一。当您将鼠标悬停在其中一个文本 link 上时,"connected" 图像应该会弹出到最前面。
我尝试了几个教程并查看了几十个示例,实际上设法让基本代码正常工作,但现在我的图像完全重叠在一起,而我希望它们稍微移动一下.
我不知道如何解决这个问题,尽管我很确定它很容易解决。 :(
这是我的 HTML:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="stylesheet2.css">
<title>TEST</title>
</head>
<body>
<div id="switcher-wrapper">
<ul>
<li><a id="eins" href="#"><span>projekt 1</span></a></li>
<li><a id="zwei" href="#"><span>projekt 2</span></a></li>
<li><a id="drei" href="#"><span>projekt 3</span></a></li>
</ul>
</div>
</body>
</html>
这是我的 CSS:
#switcher-wrapper {
width:1000px;
height:600px;
margin:20px 20px;
border:1px solid black;
position:relative;
}
#switcher-wrapper a {
display:block;
width:250px;
height:250px;
position:absolute;
top:0;
left:0;
}
#eins {
background:url(01.jpg);
top:300px;
}
#zwei {
background:url(03.jpg);
}
#drei {
background:url(04.jpg);
}
#switcher-wrapper a span {
position:absolute;
}
#eins span {
left:0;
bottom:-135px;
}
#zwei span {
left:0;
bottom:-155px;
}
#drei span {
left:0;
bottom:-175px;
}
#switcher-wrapper a:hover {
z-index:1;
}
这是我在 jsfiddle 上的代码:http://jsfiddle.net/5gcwofmk/
我可以在您的代码中看到您正在尝试更改 #eins
元素的 top
在您为 #switcher-wrapper a
声明规则之后 .您需要遵守您使用规则创建的 scope/precedence。您可以在 article.
中阅读有关特异性的信息
因为#eins
是一个a
标签; #switcher-wrapper a
实际上优先于 #eins
,即使 #eins
声明为 after #switcher-wrapper a
.
您可以通过在 id
之前添加 a
标签来更正此问题,如下所示:
a#eins {
/* rules */
}
看看这个 fiddle。我有一些 'shifted' 图片,但不确定您希望它们看起来如何,所以它只是随机的。
#switcher-wrapper {
width:1000px;
height:600px;
margin:20px 20px;
border:1px solid black;
position:relative;
}
#switcher-wrapper a {
display:block;
width:250px;
height:250px;
position:absolute;
top:0;
left:0;
}
a#eins {
background:url(http://i.imgur.com/qBuL8TO.jpg);
left: 40px;
top: 20px;
}
a#zwei {
background:url(http://i.imgur.com/ddZrGHK.jpg);
left: 20px;
top: 20px;
}
a#drei {
background:url(http://i.imgur.com/39TnFyv.jpg);
}
#switcher-wrapper a span {
position:absolute;
}
#eins span {
left:0;
bottom:-135px;
}
#zwei span {
left:0;
bottom:-155px;
}
#drei span {
left:0;
bottom:-175px;
}
#switcher-wrapper a:hover {
z-index:1;
}
<title>TEST</title>
</head>
<body>
<div id="switcher-wrapper">
<ul>
<li><a id="eins" href="#"><span>projekt 1</span></a></li>
<li><a id="zwei" href="#"><span>projekt 2</span></a></li>
<li><a id="drei" href="#"><span>projekt 3</span></a></li>
</ul>
</div>
</body>
</html>
我有一个项目列表作为常规文本 links 和一组疯狂和偏移堆叠在一起的图像,它们应该重叠一点但不会完全覆盖彼此。它们要么放置在固定位置,要么随机放置在每个负载上,以更容易的方式放置。每个文本 link 应该 "connected"(不是 linked!)到这些图像之一。当您将鼠标悬停在其中一个文本 link 上时,"connected" 图像应该会弹出到最前面。
我尝试了几个教程并查看了几十个示例,实际上设法让基本代码正常工作,但现在我的图像完全重叠在一起,而我希望它们稍微移动一下.
我不知道如何解决这个问题,尽管我很确定它很容易解决。 :(
这是我的 HTML:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="stylesheet2.css">
<title>TEST</title>
</head>
<body>
<div id="switcher-wrapper">
<ul>
<li><a id="eins" href="#"><span>projekt 1</span></a></li>
<li><a id="zwei" href="#"><span>projekt 2</span></a></li>
<li><a id="drei" href="#"><span>projekt 3</span></a></li>
</ul>
</div>
</body>
</html>
这是我的 CSS:
#switcher-wrapper {
width:1000px;
height:600px;
margin:20px 20px;
border:1px solid black;
position:relative;
}
#switcher-wrapper a {
display:block;
width:250px;
height:250px;
position:absolute;
top:0;
left:0;
}
#eins {
background:url(01.jpg);
top:300px;
}
#zwei {
background:url(03.jpg);
}
#drei {
background:url(04.jpg);
}
#switcher-wrapper a span {
position:absolute;
}
#eins span {
left:0;
bottom:-135px;
}
#zwei span {
left:0;
bottom:-155px;
}
#drei span {
left:0;
bottom:-175px;
}
#switcher-wrapper a:hover {
z-index:1;
}
这是我在 jsfiddle 上的代码:http://jsfiddle.net/5gcwofmk/
我可以在您的代码中看到您正在尝试更改 #eins
元素的 top
在您为 #switcher-wrapper a
声明规则之后 .您需要遵守您使用规则创建的 scope/precedence。您可以在 article.
因为#eins
是一个a
标签; #switcher-wrapper a
实际上优先于 #eins
,即使 #eins
声明为 after #switcher-wrapper a
.
您可以通过在 id
之前添加 a
标签来更正此问题,如下所示:
a#eins {
/* rules */
}
看看这个 fiddle。我有一些 'shifted' 图片,但不确定您希望它们看起来如何,所以它只是随机的。
#switcher-wrapper {
width:1000px;
height:600px;
margin:20px 20px;
border:1px solid black;
position:relative;
}
#switcher-wrapper a {
display:block;
width:250px;
height:250px;
position:absolute;
top:0;
left:0;
}
a#eins {
background:url(http://i.imgur.com/qBuL8TO.jpg);
left: 40px;
top: 20px;
}
a#zwei {
background:url(http://i.imgur.com/ddZrGHK.jpg);
left: 20px;
top: 20px;
}
a#drei {
background:url(http://i.imgur.com/39TnFyv.jpg);
}
#switcher-wrapper a span {
position:absolute;
}
#eins span {
left:0;
bottom:-135px;
}
#zwei span {
left:0;
bottom:-155px;
}
#drei span {
left:0;
bottom:-175px;
}
#switcher-wrapper a:hover {
z-index:1;
}
<title>TEST</title>
</head>
<body>
<div id="switcher-wrapper">
<ul>
<li><a id="eins" href="#"><span>projekt 1</span></a></li>
<li><a id="zwei" href="#"><span>projekt 2</span></a></li>
<li><a id="drei" href="#"><span>projekt 3</span></a></li>
</ul>
</div>
</body>
</html>