html - 在 figcaption 绝对位置中,字幕尾随图像下方
问题描述
我正在尝试在图像的底部放置一个标题,它正在使用position absolute
它bottom 0
正在做的事情,但是 g 和 y 字母区域的尾部悬垂在图像边缘下方。这是预期的行为吗?我只需要稍微调整一下标题的位置吗?
这是代码:
.article-image,
figure {
margin: 1.5em 0;
}
figure {
margin-block-start: 0em;
margin-block-end: 0em;
margin-inline-start: 0px;
margin-inline-end: 0px;
position: relative;
}
figcaption {
position: absolute;
bottom: 0;
width: 100%;
background-color: rgba(255, 255, 255, .6);
}
cite {
font-size: 0.85em;
}
<figure>
<img class="aside-image" src="images/grayson-perry.jpg">
<figcaption>I've moved out just as Walthamstow is becoming gentrified. My work is done.</figcaption>
</figure>
<cite>- Graysen Perry</cite>
我不希望 g 和 y 的尾部垂在图像边缘下方。
解决方案
制作图像display:block
,如果您不希望文字从图像的右侧流出,请制作图形inline-block
.article-image,
figure {
margin: 1.5em 0;
}
figure {
margin-block-start: 0em;
margin-block-end: 0em;
margin-inline-start: 0px;
margin-inline-end: 0px;
position: relative;
display:inline-block;
}
figcaption {
position: absolute;
bottom: 0;
width: 100%;
background-color: rgba(255, 255, 255, .6);
}
cite {
display:block;
font-size: 0.85em;
}
.aside-image {
display:block;
}
<figure>
<img class="aside-image" src="https://www.fillmurray.com/300/300">
<figcaption>I've moved out just as Walthamstow is becoming gentrified. My work is done.</figcaption>
</figure>
<cite>- Graysen Perry</cite>
推荐阅读
- c++ - 这个错误是什么意思 ?警告:null 传递给需要非 null 参数的被调用者 [-Wnonnull]
- amazon-web-services - 有没有办法将 aws freertos sdks 与本机反应一起使用?
- mathml - 语音规则引擎 3.2 中的行为变化?
- amazon-web-services - AWS CloudWatch 日志订阅过滤器不会为每个 Cloudwatch 事件调用 Lambda 函数
- java - 无法启动活动 ComponentInfo:二进制 XML 文件行 #10 错误
- android - 在开发过程中删除/隐藏我的主题中没有的 Android 模拟器附加功能
- apache-spark - 如何在不运行 spark 作业的情况下对 Hadoop 运行 spark sql 查询
- flutter - 如何设置从导航器到全局的变量以在颤振应用程序的所有页面中可用?
- android - 我想将数据从活动传递到片段
- python - Python从一个巨大的字符串中提取电子邮件地址