html - 有没有办法将 html 元素绝对定位但仍将其放置在页面的中心?
问题描述
.container{
position: absolute;
margin: 0 auto;// this doesn't position it in the centre anymore.
}
<div class="container">
this is a container
</div>
“这应该放在中心......但是当我将它定位为绝对时,它又回到了网页的顶部。有没有办法绕过这个。”
解决方案
这将做到:
.container{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
推荐阅读
- php - 动态拖放表格行
- c++ - 我在微控制器 stm32f373 发现中点亮 LED 时遇到问题
- libgdx - 在制作软体(球体)并在 libgdx 中平移时,很少有网格顶点粘在原点上?
- install4j - 第二次启动时的执行级别启动应用程序不会从代码中调用 main 方法
- azure - 部署时的数据库参考
- flutter - Dart 函数可以接受范围参数吗?
- c# - 获取当前活动标签
- hyperledger-fabric - Hyperledger Fabric 交易太慢
- scrapy - Scrapy:与另一端的连接丢失
- javascript - 删除部分 jQuery 后对每个元素进行验证