html - 在 HTML 中将图像置于文本之上

标签 html css

我想要多张图片,当用户将鼠标悬停在每张图片上时,图片会消失,显示下面的文字。现在,图像会在悬停时消失,但文本始终保留在图像上方。

HTML

<table align="center" style="width: 90vw;margin-right: 10vw;margin-left: 10vw;">

    <tr>
        <th>
            <div class="inhabitantOne">
                <p>Test Text.  Test Text.  Test Text.  Test Text.</p>
                <img src="judas.jpg">
            </div>
        </th>
        <th>
            <div class="inhabitantTwo">
                <img src="cain.jpg">
            </div>
        </th>
        <th>
            <div class="inhabitantThree">
                <img src="Ganelon.jpg">
            </div>
        </th>
    </tr>

CSS

.inhabitantOne {
  background-color: #8592b2;
  border-radius: 2vw;
  height: 20vw;
  width: 20vw;
  text-align: center;
  overflow: hidden;
  border-style: solid;
  border-width: 2px;
  border-color: #505151;
}

.inhabitantOne img {
   height: 100%;
   width: 100%;
}


.inhabitantOne:hover img {
  opacity: 0.0;
}

最佳答案

将此添加到您的 CSS 中

p{
  text-indent: 100%;
  white-space: nowrap;
  overflow: hidden;
}
p:hover{
  text-indent: 0%;
  white-space: nowrap;
  overflow: visible;
}

或者如果你想针对每个 div 类使用这个:

.inhabitantOne p{

  text-indent: 100%;
  white-space: nowrap;
  overflow: hidden;
}
.inhabitantOne p:hover{
  text-indent: 0%;
  white-space: nowrap;
  overflow: visible;
}

关于html - 在 HTML 中将图像置于文本之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50071653/

相关文章:

html - CSS 垂直对齐基线 HTML 标题

HTML Bootstrap 导航标签

javascript - 从 JSFiddle 发出复制代码

javascript - 在html的选择元素中选择后更改所选值的字体大小

html - Sendgrid 始终发送文本电子邮件

java - 漂亮的 HTML 片段输出

jquery - 使 Sprite 图像播放/暂停图标突出显示

html - 每 "post",图标更靠左

html - 我的想法哪里错了?浏览器缩放简单的 <div> 框

html - 在 div 上使用 "stand alone" "display: table-cell;"有效;但这是允许的吗?