0
我想在HTML中的鼠標懸停在CSS中的一個元素上,更改多個標籤(身體的背景顏色,.text
類的文本顏色和.url
的url鏈接出現)。CSS:在懸停上更改多個標籤
下面的代碼不起作用(URL標籤出現,但背景顏色和.text
顏色不會改變)。
body {
background-color: #f1f1f1;
}
div {
height: 200px;
width: 400px;
text-align: center;
position: fixed;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -200px;
}
.text {
color: blue;
}
.url {
z-index: 100;
position: absolute;
color: black;
font-size: 24px;
font-weight: bold;
left: 150px;
top: 100px;
visibility: hidden;
opacity: 0;
}
.img {
position: relative;
display: block;
top: 50%;
left: 50%;
}
.img:hover > body {
background-color: black;
}
.img:hover > .url {
visibility: visible;
opacity: 1;
}
.img:hover > .text {
color: white;
}
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="index.css">
</head>
<body>
<div>
<h1 class="text"> Neon Cabbage </h1>
<h2 class="text"> 2nd Website </h2>
<div class="img">
<a href="main.html"><img src="images/cabbage.jpg" id="cabbage" width="200" height="200" onmouseover="this.src='images/cabbage2.jpg';" onmouseout="this.src='images/cabbage.jpg';"></a>
<a href="main.html" class="url">click!</a>
</div>
</div>
</body>
</html>