css - 如何在内容文本中对齐和水平居中?
问题描述
.port {
position: relative;
}
.element {
margin-bottom: 1rem;
cursor: pointer;
}
.element::before {
content: 'this text has to vertical and horizontal center';
position: absolute;
background-color: red;
transition: .7s;
left: 0;
width: 300px;
height: 300px;
}
<div class="front port">
<div class="element">
<img src="https://via.placeholder.com/300" alt="">
</div>
</div>
JSFiddle:https ://jsfiddle.net/xac2kpo3/7/
我必须将此内容文本居中。但我不应该打扰这个结构,我不能添加额外的 div。
有什么办法吗?如果你帮助我,我会很高兴。谢谢
解决方案
推荐阅读
- c# - 使用SharpAVI录屏,为什么我提高FPS后播放的.avi文件好像加速了?
- javascript - 排序 ng-table(空值和自定义排序)
- javascript - FlowJS - 无法识别可选字段何时有值
- unix - 在字符串中查找负数
- python - 什么相当于 Python 3.x 中的“bwlabeln(具有 18 和 26 连接的邻域)”?
- python - 从另一个 Python 脚本导入函数时,如何确保导入的模块正常工作?
- python - 如何操作 Google Ads API 的 Enum 类的对象 - python
- c# - 如何使用 .NET Core 在 href 上设置特定路由
- typescript - 在 Node.js 上的 typescript 文件之间拆分 Actions-on-Google 意图
- r - 在 macos 上的 R 图中使用 texlive 字体