简体   繁体   English

HTML/CSS - 将鼠标悬停在照片上时显示链接

[英]HTML/CSS - Display the link while hovering over a photo

I want to have my link displayed when I hover over the image.当我在图像上 hover 时,我希望显示我的链接。 The way I wrote the code displays the link only if I hover over the link itself(which is contained in the image div).我编写代码的方式仅在我通过链接本身(包含在图像 div 中)上 hover 时才显示链接。 Any ideas how I should go on?任何想法我应该如何 go 上?

 .image-text-wrapper { position: absolute; top: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%; text-align: center; padding-left: 100px; padding-right: 100px; font-size: 1.5em; }.image-text-wrapper.xx { transition: 1s; font-weight: 600; margin: 20px; }.image-text-wrapper.xx a { color: transparent;important. }:image-text-wrapper a:hover { color; lightseagreen:important; text-decoration: none; }
 <div class="portfolio-img-background" style="background-image:url()"> <div class="xx"> <a href="#"> Text </a> </div> </div>

This CSS class at the bottom of your code can be slightly modified to make this work.可以稍微修改代码底部的 CSS class 以使其正常工作。

.image-text-wrapper:hover a {
  color: lightseagreen !important;
  text-decoration: none;
}

This is a solution using just CSS这是仅使用 CSS 的解决方案

 #image{ width:200px; height:200px; background:black; display:flex; align-items:center; justify-content: center; } #link{ display:none; } #image:hover > #link { display:block; }
 <div id="image" class="portfolio-img-background" style="background-image:url()"> <div class="xx" id="link"> <a href="#"> Hi,, im a link </a> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM