Reputation: 1
why when the mouse hover over the image the text do not show ? how to get the visibility of the text using visibility property in css
img{
margin-top: 110px;
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
margin-top: 50px;
position: relative;
}
.txt{
font-size: 16px;
line-height: 20px;
margin-top: 10px;
text-align: center;
margin-left: 440px;
margin-right: 440px;
visibility: hidden;
}
img:hover .txt{
cursor: pointer;
visibility: visible;
}
<div class="container">
<img src="empty-boxes.svg" style="width:520px;height:190px;">
<p class="number">404</p>
<p class="txt">When communicating via HTTP, the server is required
.</p>
</div>
Upvotes: 0
Views: 48
Reputation: 2033
Add the CSS "~
" selector.
img {
margin-top: 110px;
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
margin-top: 50px;
position: relative;
}
.txt {
font-size: 16px;
line-height: 20px;
margin-top: 10px;
text-align: center;
margin-left: 440px;
margin-right: 440px;
visibility: hidden;
}
img:hover ~ .txt {
cursor: pointer;
visibility: visible;
}
<div class="container">
<img src="empty-boxes.svg" style="width:520px;height:190px;">
<p class="number">404</p>
<p class="txt">When communicating via HTTP, the server is required .
</p>
</div>
Upvotes: 1
Reputation: 541
You can also change the opacity of the text when hover on image
.txt {
opacity: 0;
}
img:hover~ .txt{
opacity: 1;
}
I recommend you to hover on the image container instead of the image itself. You can add transition on .txt to make it good looking.
Upvotes: 0