为什么我的 img 悬停不起作用?
Why does my img hover not work?
我正在尝试设置为 opacity: .04;
,但是当悬停在 opacity:1;
上时,我的 img 悬停不起作用。我不确定这是为什么。有人可以帮助我了解我的问题出在哪里吗?
我的html:
.container2 {
margin: 0px;
padding: 0px;
}
.intro {
width: 100%;
position: relative;
overflow: hidden;
margin: 0;
padding-top: 0;
}
.pic1 {
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
.intro-img {
display: block;
margin: 0 auto;
min-width: 100%;
opacity: 0.4;
}
.pic1 img:hover {
opacity: 1;
}
.wrapper {
height: 200px;
min-height: 200px;
position: relative;
padding-bottom: 0;
}
.blue {
background: #22428e;
color: #fff;
}
.green {
background: #de0e00;
color: #fff;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 330px;
padding: 0 25px;
margin-left: 3em;
}
h1 {
text-transform: uppercase;
font: 700 32px/35px'Gotham SSm A', 'Gotham SSm B', Arial, Helvetica, sans-serif;
margin: 0 0 34px;
padding-top: 28px;
}
p {
margin-top: -10px;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: black;
}
@media screen and (max-width: 454px) {
.wrapper {
min-height: 100px;
position: relative;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
padding: 0 25px;
margin-left: -4px;
}
#pic1 {
display: none;
}
}
<div class="container2">
<div class="intro">
<div class="pic1">
<img class="intro-img" src="https://s23.postimg.org/94clk2prf/resources_gender_spectrum2.png">
</div>
<!-- End pic1 -->
<div class="wrapper">
<article class="blue" id="colors-content">
<div>
<a href="">
<h1> Gender
Spectrum.com </h1>
</a>
<p>I'm gone so i'me gone so long hah haha aha im bout it fuck it aiash hth as jasd ashd as ahsdjas r ajsgda uaju ashd ujawh uu ajshdhuiae</p>
</div>
</article>
<!-- End of article -->
</div>
<!-- End wrapper -->
</div>
<!-- End intro -->
</div>
<! -- End of container2 -->
我将 :hover 选择器移到了 .intro-img
.container2 {
margin: 0px;
padding: 0px;
}
.intro {
width: 100%;
position: relative;
overflow: hidden;
margin: 0;
padding-top: 0;
}
#pic1 {
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
.intro-img {
display: block;
margin: 0 auto;
min-width: 100%;
opacity: 0.4;
}
.intro-img:hover {
opacity: 1;
}
.wrapper {
height: 200px;
min-height: 200px;
position: relative;
padding-bottom: 0;
}
.blue {
background: #22428e;
color: #fff;
}
.g
<div class="container2">
<div class="intro">
<div class="pic1">
<img class="intro-img" src="https://s23.postimg.org/94clk2prf/resources_gender_spectrum2.png">
</div>
<!-- End pic1 -->
<div class="wrapper">
<article class="blue" id="colors-content">
<div>
<a href="">
<h1> Gender
Spectrum.com </h1>
</a>
<p>I'm gone so i'me gone so long hah haha aha im bout it fuck it aiash hth as jasd ashd as ahsdjas r ajsgda uaju ashd ujawh uu ajshdhuiae</p>
</div>
</article>
<!-- End of article -->
</div>
<!-- End wrapper -->
</div>
<!-- End intro -->
</div>
<! -- End of container2 -->
在 CSS 中调整您的方法。
您正在使用 .intro-img class 设置不透明度,因此您需要使用相同的 class.
img.intro-img:hover {
opacity: 1;
}
我将您的代码复制并粘贴到 "jsfiddle" 中,并更改了悬停的 CSS;它现在在鼠标悬停时变得稳定。
.intro-img:hover{
opacity: 1;
}
它不起作用,因为您使用了 # 而不是 。在 css 选择器上
<div class="pic1">
意味着你必须做
.pic1 img:hover{
opacity: 1;
}
您的图片 1 class 不是 ID 而不是 #pic1 使用 .pic1
'#pic1' in CSS select html 元素的 'id' 值为 'pic1',但 'pic1' 是 'class' 在您的第一个 html 页面中的价值...
您的代码中有两种可能性,如果您只想通过将鼠标悬停在该背景上来使背景图像的不透明度为 1,那么您的代码如下:
.container2 {
margin: 0px;
padding: 0px;
}
.intro {
width: 100%;
position: relative;
overflow: hidden;
margin: 0;
padding-top: 0;
}
#pic1 {
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
.intro-img {
display: block;
margin: 0 auto;
min-width: 100%;
opacity: 0.4;
}
#pic1 img:hover{
opacity: 1;
}
.wrapper {
height: 200px;
min-height: 200px;
position: relative;
padding-bottom: 0;
margin-left: 3em;
width: 330px;
}
.blue {
background: #22428e;
color: #fff;
}
.green{
background: #de0e00;
color: #fff;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 330px;
padding: 0 25px;
}
h1 {
text-transform: uppercase;
font: 700 32px/35px 'Gotham SSm A','Gotham SSm B',Arial,Helvetica,sans-serif;
margin: 0 0 34px;
padding-top: 28px;
}
p {
margin-top: -10px;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: black;
}
@media screen and (max-width: 454px) {
.wrapper {
min-height: 100px;
position: relative;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
padding: 0 25px;
margin-left: -4px;
}
#pic1 {
display: none;
}
}
<div class="container2">
<div class="intro">
<div id="pic1">
<img class="intro-img" src="https://s23.postimg.org/94clk2prf/resources_gender_spectrum2.png">
</div> <!-- End pic1 -->
<div class="wrapper">
<article class="blue" id="colors-content">
<div>
<a href=""> <h1> Gender
Spectrum.com </h1> </a>
<p> I'm gone so i'me gone so long hah haha aha im bout it fuck it aiash hth as jasd ashd as ahsdjas r ajsgda uaju ashd ujawh uu ajshdhuiae</p>
</div>
</article><!-- End of article -->
</div><!-- End wrapper -->
</div> <!-- End intro -->
</div> <! -- End of container2 -->
如果你想在将鼠标悬停在前面的蓝色包装上并将鼠标悬停在背景上后将背景不透明度设置为 1,则代码如下:
.container2 {
margin: 0px;
padding: 0px;
}
.wrapper:hover + div#pic1 img.intro-img {
opacity: 1;
}
.intro {
width: 100%;
position: relative;
overflow: hidden;
margin: 0;
padding-top: 0;
}
#pic1 {
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
.intro-img {
display: block;
margin: 0 auto;
min-width: 100%;
opacity: 0.4;
}
#pic1 img:hover{
opacity: 1;
}
.wrapper {
height: 200px;
min-height: 200px;
position: relative;
padding-bottom: 0;
margin-left: 3em;
width: 330px;
z-index: 9;
}
.blue {
background: #22428e;
color: #fff;
}
.green{
background: #de0e00;
color: #fff;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 330px;
padding: 0 25px;
}
h1 {
text-transform: uppercase;
font: 700 32px/35px 'Gotham SSm A','Gotham SSm B',Arial,Helvetica,sans-serif;
margin: 0 0 34px;
padding-top: 28px;
}
p {
margin-top: -10px;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: black;
}
@media screen and (max-width: 454px) {
.wrapper {
min-height: 100px;
position: relative;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
padding: 0 25px;
margin-left: -4px;
}
#pic1 {
display: none;
}
}
<div class="container2">
<div class="intro">
<div class="wrapper">
<article class="blue" id="colors-content">
<div>
<a href=""> <h1> Gender
Spectrum.com </h1> </a>
<p> I'm gone so i'me gone so long hah haha aha im bout it fuck it aiash hth as jasd ashd as ahsdjas r ajsgda uaju ashd ujawh uu ajshdhuiae</p>
</div>
</article><!-- End of article -->
</div><!-- End wrapper -->
<div id="pic1">
<img class="intro-img" src="https://s23.postimg.org/94clk2prf/resources_gender_spectrum2.png">
</div> <!-- End pic1 -->
</div> <!-- End intro -->
</div> <! -- End of container2 -->
您的 .wrapper
元素 覆盖 您的图像。这就是为什么鼠标事件不会在它后面的元素上触发的原因。
我给了 .wrapper { margin-top: 200px; }
所以你会看到它在修复后立即生效。
.container2 {
margin: 0;
padding: 0;
}
.intro {
width: 100%;
position: relative;
overflow: hidden;
margin: 0;
padding-top: 0;
}
.pic1 {
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
.intro-img {
display: block;
margin: 0 auto;
min-width: 100%;
opacity: 0.4;
}
.pic1 img:hover {
opacity: 1;
}
.wrapper {
height: 200px;
min-height: 200px;
position: relative;
padding-bottom: 0;
margin-top: 200px;
}
.blue {
background: #22428e;
color: #fff;
}
.green {
background: #de0e00;
color: #fff;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 330px;
padding: 0 25px;
margin-left: 3em;
}
h1 {
text-transform: uppercase;
font: 700 32px/35px'Gotham SSm A', 'Gotham SSm B', Arial, Helvetica, sans-serif;
margin: 0 0 34px;
padding-top: 28px;
}
p {
margin-top: -10px;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: black;
}
@media screen and (max-width: 454px) {
.wrapper {
min-height: 100px;
position: relative;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
padding: 0 25px;
margin-left: -4px;
}
#pic1 {
display: none;
}
}
<div class="container2">
<div class="intro">
<div class="pic1">
<img class="intro-img" src="https://s23.postimg.org/94clk2prf/resources_gender_spectrum2.png">
</div>
<!-- End pic1 -->
<div class="wrapper">
<article class="blue" id="colors-content">
<div>
<a href="">
<h1> Gender
Spectrum.com </h1>
</a>
<p>I'm gone so i'me gone so long hah haha aha im bout it fuck it aiash hth as jasd ashd as ahsdjas r ajsgda uaju ashd ujawh uu ajshdhuiae</p>
</div>
</article>
<!-- End of article -->
</div>
<!-- End wrapper -->
</div>
<!-- End intro -->
</div>
<! -- End of container2 -->
我正在尝试设置为 opacity: .04;
,但是当悬停在 opacity:1;
上时,我的 img 悬停不起作用。我不确定这是为什么。有人可以帮助我了解我的问题出在哪里吗?
我的html:
.container2 {
margin: 0px;
padding: 0px;
}
.intro {
width: 100%;
position: relative;
overflow: hidden;
margin: 0;
padding-top: 0;
}
.pic1 {
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
.intro-img {
display: block;
margin: 0 auto;
min-width: 100%;
opacity: 0.4;
}
.pic1 img:hover {
opacity: 1;
}
.wrapper {
height: 200px;
min-height: 200px;
position: relative;
padding-bottom: 0;
}
.blue {
background: #22428e;
color: #fff;
}
.green {
background: #de0e00;
color: #fff;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 330px;
padding: 0 25px;
margin-left: 3em;
}
h1 {
text-transform: uppercase;
font: 700 32px/35px'Gotham SSm A', 'Gotham SSm B', Arial, Helvetica, sans-serif;
margin: 0 0 34px;
padding-top: 28px;
}
p {
margin-top: -10px;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: black;
}
@media screen and (max-width: 454px) {
.wrapper {
min-height: 100px;
position: relative;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
padding: 0 25px;
margin-left: -4px;
}
#pic1 {
display: none;
}
}
<div class="container2">
<div class="intro">
<div class="pic1">
<img class="intro-img" src="https://s23.postimg.org/94clk2prf/resources_gender_spectrum2.png">
</div>
<!-- End pic1 -->
<div class="wrapper">
<article class="blue" id="colors-content">
<div>
<a href="">
<h1> Gender
Spectrum.com </h1>
</a>
<p>I'm gone so i'me gone so long hah haha aha im bout it fuck it aiash hth as jasd ashd as ahsdjas r ajsgda uaju ashd ujawh uu ajshdhuiae</p>
</div>
</article>
<!-- End of article -->
</div>
<!-- End wrapper -->
</div>
<!-- End intro -->
</div>
<! -- End of container2 -->
我将 :hover 选择器移到了 .intro-img
.container2 {
margin: 0px;
padding: 0px;
}
.intro {
width: 100%;
position: relative;
overflow: hidden;
margin: 0;
padding-top: 0;
}
#pic1 {
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
.intro-img {
display: block;
margin: 0 auto;
min-width: 100%;
opacity: 0.4;
}
.intro-img:hover {
opacity: 1;
}
.wrapper {
height: 200px;
min-height: 200px;
position: relative;
padding-bottom: 0;
}
.blue {
background: #22428e;
color: #fff;
}
.g
<div class="container2">
<div class="intro">
<div class="pic1">
<img class="intro-img" src="https://s23.postimg.org/94clk2prf/resources_gender_spectrum2.png">
</div>
<!-- End pic1 -->
<div class="wrapper">
<article class="blue" id="colors-content">
<div>
<a href="">
<h1> Gender
Spectrum.com </h1>
</a>
<p>I'm gone so i'me gone so long hah haha aha im bout it fuck it aiash hth as jasd ashd as ahsdjas r ajsgda uaju ashd ujawh uu ajshdhuiae</p>
</div>
</article>
<!-- End of article -->
</div>
<!-- End wrapper -->
</div>
<!-- End intro -->
</div>
<! -- End of container2 -->
在 CSS 中调整您的方法。 您正在使用 .intro-img class 设置不透明度,因此您需要使用相同的 class.
img.intro-img:hover {
opacity: 1;
}
我将您的代码复制并粘贴到 "jsfiddle" 中,并更改了悬停的 CSS;它现在在鼠标悬停时变得稳定。
.intro-img:hover{
opacity: 1;
}
它不起作用,因为您使用了 # 而不是 。在 css 选择器上
<div class="pic1">
意味着你必须做
.pic1 img:hover{
opacity: 1;
}
您的图片 1 class 不是 ID 而不是 #pic1 使用 .pic1
'#pic1' in CSS select html 元素的 'id' 值为 'pic1',但 'pic1' 是 'class' 在您的第一个 html 页面中的价值...
您的代码中有两种可能性,如果您只想通过将鼠标悬停在该背景上来使背景图像的不透明度为 1,那么您的代码如下:
.container2 {
margin: 0px;
padding: 0px;
}
.intro {
width: 100%;
position: relative;
overflow: hidden;
margin: 0;
padding-top: 0;
}
#pic1 {
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
.intro-img {
display: block;
margin: 0 auto;
min-width: 100%;
opacity: 0.4;
}
#pic1 img:hover{
opacity: 1;
}
.wrapper {
height: 200px;
min-height: 200px;
position: relative;
padding-bottom: 0;
margin-left: 3em;
width: 330px;
}
.blue {
background: #22428e;
color: #fff;
}
.green{
background: #de0e00;
color: #fff;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 330px;
padding: 0 25px;
}
h1 {
text-transform: uppercase;
font: 700 32px/35px 'Gotham SSm A','Gotham SSm B',Arial,Helvetica,sans-serif;
margin: 0 0 34px;
padding-top: 28px;
}
p {
margin-top: -10px;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: black;
}
@media screen and (max-width: 454px) {
.wrapper {
min-height: 100px;
position: relative;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
padding: 0 25px;
margin-left: -4px;
}
#pic1 {
display: none;
}
}
<div class="container2">
<div class="intro">
<div id="pic1">
<img class="intro-img" src="https://s23.postimg.org/94clk2prf/resources_gender_spectrum2.png">
</div> <!-- End pic1 -->
<div class="wrapper">
<article class="blue" id="colors-content">
<div>
<a href=""> <h1> Gender
Spectrum.com </h1> </a>
<p> I'm gone so i'me gone so long hah haha aha im bout it fuck it aiash hth as jasd ashd as ahsdjas r ajsgda uaju ashd ujawh uu ajshdhuiae</p>
</div>
</article><!-- End of article -->
</div><!-- End wrapper -->
</div> <!-- End intro -->
</div> <! -- End of container2 -->
如果你想在将鼠标悬停在前面的蓝色包装上并将鼠标悬停在背景上后将背景不透明度设置为 1,则代码如下:
.container2 {
margin: 0px;
padding: 0px;
}
.wrapper:hover + div#pic1 img.intro-img {
opacity: 1;
}
.intro {
width: 100%;
position: relative;
overflow: hidden;
margin: 0;
padding-top: 0;
}
#pic1 {
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
.intro-img {
display: block;
margin: 0 auto;
min-width: 100%;
opacity: 0.4;
}
#pic1 img:hover{
opacity: 1;
}
.wrapper {
height: 200px;
min-height: 200px;
position: relative;
padding-bottom: 0;
margin-left: 3em;
width: 330px;
z-index: 9;
}
.blue {
background: #22428e;
color: #fff;
}
.green{
background: #de0e00;
color: #fff;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 330px;
padding: 0 25px;
}
h1 {
text-transform: uppercase;
font: 700 32px/35px 'Gotham SSm A','Gotham SSm B',Arial,Helvetica,sans-serif;
margin: 0 0 34px;
padding-top: 28px;
}
p {
margin-top: -10px;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: black;
}
@media screen and (max-width: 454px) {
.wrapper {
min-height: 100px;
position: relative;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
padding: 0 25px;
margin-left: -4px;
}
#pic1 {
display: none;
}
}
<div class="container2">
<div class="intro">
<div class="wrapper">
<article class="blue" id="colors-content">
<div>
<a href=""> <h1> Gender
Spectrum.com </h1> </a>
<p> I'm gone so i'me gone so long hah haha aha im bout it fuck it aiash hth as jasd ashd as ahsdjas r ajsgda uaju ashd ujawh uu ajshdhuiae</p>
</div>
</article><!-- End of article -->
</div><!-- End wrapper -->
<div id="pic1">
<img class="intro-img" src="https://s23.postimg.org/94clk2prf/resources_gender_spectrum2.png">
</div> <!-- End pic1 -->
</div> <!-- End intro -->
</div> <! -- End of container2 -->
您的 .wrapper
元素 覆盖 您的图像。这就是为什么鼠标事件不会在它后面的元素上触发的原因。
我给了 .wrapper { margin-top: 200px; }
所以你会看到它在修复后立即生效。
.container2 {
margin: 0;
padding: 0;
}
.intro {
width: 100%;
position: relative;
overflow: hidden;
margin: 0;
padding-top: 0;
}
.pic1 {
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
.intro-img {
display: block;
margin: 0 auto;
min-width: 100%;
opacity: 0.4;
}
.pic1 img:hover {
opacity: 1;
}
.wrapper {
height: 200px;
min-height: 200px;
position: relative;
padding-bottom: 0;
margin-top: 200px;
}
.blue {
background: #22428e;
color: #fff;
}
.green {
background: #de0e00;
color: #fff;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 330px;
padding: 0 25px;
margin-left: 3em;
}
h1 {
text-transform: uppercase;
font: 700 32px/35px'Gotham SSm A', 'Gotham SSm B', Arial, Helvetica, sans-serif;
margin: 0 0 34px;
padding-top: 28px;
}
p {
margin-top: -10px;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: black;
}
@media screen and (max-width: 454px) {
.wrapper {
min-height: 100px;
position: relative;
}
#colors-content {
height: 200px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
padding: 0 25px;
margin-left: -4px;
}
#pic1 {
display: none;
}
}
<div class="container2">
<div class="intro">
<div class="pic1">
<img class="intro-img" src="https://s23.postimg.org/94clk2prf/resources_gender_spectrum2.png">
</div>
<!-- End pic1 -->
<div class="wrapper">
<article class="blue" id="colors-content">
<div>
<a href="">
<h1> Gender
Spectrum.com </h1>
</a>
<p>I'm gone so i'me gone so long hah haha aha im bout it fuck it aiash hth as jasd ashd as ahsdjas r ajsgda uaju ashd ujawh uu ajshdhuiae</p>
</div>
</article>
<!-- End of article -->
</div>
<!-- End wrapper -->
</div>
<!-- End intro -->
</div>
<! -- End of container2 -->