jquery - 如何使文本 float 在图像 html css 之上

标签 jquery html css css-float css-position

我有以下 html 代码使“底部”div float 在图像的顶部。我在一个表行上有 3 张图片。

<td>
     <img src="adele.jpg" alt="Adele">
     <div id="bottom">
        <h4 class="topText">ALBUM</h4>
        <h3 class ="topText">ADELE 21 COVER </br> ADELE</h3>
    </div>
</td>

这是我的CSS:

#bottom{
  position: absolute;
  display: inline-block;
  bottom: 0px;
  left:0px;

}

#positionAnchor {
   position: relative;
}

同样如您在图片中所见,顶部图片文本也未正确 float 在图片上方。

enter image description here

最佳答案

您需要使用 position:relative 来设置窗口,其中 position:absolute 将用于顶部、左侧、底部和右侧。

<td >
     <div id="positionAnchor">
     <img src="adele.jpg" alt="Adele">
     <div id="bottom">
        <h4 class="topText">ALBUM</h4>
        <h3 class ="topText">ADELE 21 COVER </br> ADELE</h3>
    </div>
    </div>
</td>

#bottom{
  position: absolute;
  display: inline-block;
  bottom: 0px;
  left: 0px;
}
#positionAnchor {
 position: relative;
 display: inline-block;
 text-align:center;
}

否则它将基于浏览器屏幕而不是父标签进行定位。

关于jquery - 如何使文本 float 在图像 html css 之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25960305/

相关文章:

html - 使用 flexbox 的水平滚动 div 问题

c# - Html.CheckBox 呈现两个复选框

javascript - jQuery:如果我在一类项目上调用 .change() ,它会被调用多少次?

javascript - 在 Textarea 中的部分文本下划线

html - 为什么标题 (h1-6) 在 HTML/CSS 中是一个单独的类别(标签)?

html - Rails - 内联显示表单

javascript - 单击 1 个按钮时同时加载 2 个不同 div 中的 2 个页面

JavaScript jQuery 提交按钮问题

jquery - div 追加带有动画的文本

html - 滚动条未出现在 SVG 元素中