恨到弹窗都需要实现垂直水平居中的功能,知道宽高可以用绝对定位,加上设置margin为负值,大小为宽高的一半即可

1 #demo{
2     position: absolute;
3     width: 200px;
4     height: 200px;
5     top: 50%;
6     left: 50%;
7     margin-left: -100px;
8     margin-top: -100px;
9 }

如果不知道宽高怎么来垂直居中呢?其实很简单,只要加上transform: translate(-50%, -50%);就可以了

1 #demo{
2     position: absolute;
3     top: 50%;
4     left: 50%;
5     transform: translate(-50%, -50%);
6 }
7                     

 

相关文章:

  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
  • 2021-06-22
  • 2021-12-01
猜你喜欢
  • 2022-12-23
  • 2021-11-05
  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
相关资源
相似解决方案