css - 绝对定位拆分标题和描述
问题描述
在本页面:
https://www.joshungerdesign.com/packed
我有一个 3 图像马赛克设置。我希望标题位于每张图片的顶部,而描述位于每张图片的底部。有没有办法通过编写 css 来同时处理高图像和短图像来实现这一点?
我尝试了以下方法:
.Index-gallery-item-content-heading {
position: absolute;
bottom: 190px;
}
这为小图像提供了所需的结果,但不适用于高图像。我希望所有图像看起来都像较短的图像,标题在顶部,描述在底部。
解决方案
不推荐使用“幻数”,因此尽可能避免使用特定的像素值。使用 ems、% 和 vw/vh 是响应式设计的必要条件。
但是在这种情况下,您可以只使用top: 0;
在顶部bottom: 0;
浮动一个绝对元素并在底部浮动一个绝对元素(只要父position:relative;
级当然是)
.Index-gallery-item-content-heading,
.Index-gallery-item-content-description {
position: absolute;
}
.Index-gallery-item-content-heading {
top: 0;
}
.Index-gallery-item-content-description {
bottom: 0;
}
推荐阅读
- json - 从 RestController Spring,Java 8 使用 SOAP Web 服务
- javascript - 如何使 3D 对象跟随网页中的光标?
- context-free-grammar - 使用 CFG 示例在 Agda 中调试约束满足错误
- java - 为什么这不反转二叉树?
- android - 如何从 Android Studio 中的数据类中获取数据
- sql - 如何添加到 sql 表中的现有值
- android - 升级后 CameraX 预览不起作用
- python - 如何在 Networkx 中使用节点标签搜索特定路径并返回节点 ID?
- javascript - 在 ReactJS 中设置输入时出错,标签已覆盖/覆盖输入集的值,使用 material.ui
- python - 不能禁止用户名中包含字母字符的数字