117.info
人生若只如初见

如何让div垂直居中(23种方法总结)

  1. 使用flexbox布局,在父元素上设置display: flex;和align-items: center;属性。

  2. 使用position和transform属性,将子元素的top和left设置为50%,然后使用transform: translate(-50%, -50%);将子元素居中。

  3. 使用position和margin属性,将子元素的top和left设置为50%,然后使用margin-top和margin-left将子元素居中。

  4. 使用display: table;和display: table-cell;属性,将父元素设置为table,子元素设置为table-cell,并使用vertical-align: middle;将子元素垂直居中。

  5. 使用display: grid;和place-items: center;属性,将父元素设置为grid,并使用place-items: center;将子元素居中。

  6. 使用position属性,将父元素设置为relative,子元素设置为absolute,并使用top: 50%;left: 50%;transform: translate(-50%, -50%);将子元素居中。

  7. 使用display: flex;和justify-content: center;属性,将父元素设置为flex,并使用justify-content: center;将子元素水平居中。

  8. 使用display: flex;和align-self: center;属性,将父元素设置为flex,并在子元素上使用align-self: center;将子元素垂直居中。

  9. 使用display: inline-block;和vertical-align: middle;属性,将父元素设置为inline-block,并使用vertical-align: middle;将子元素垂直居中。

  10. 使用display: flex;和margin: auto;属性,将父元素设置为flex,并使用margin: auto;将子元素居中。

  11. 使用display: table;和display: table-cell;属性,将父元素设置为table,子元素设置为table-cell,并使用text-align: center;将子元素水平居中,使用vertical-align: middle;将子元素垂直居中。

  12. 使用position属性,将父元素设置为relative,子元素设置为absolute,并使用top: 0;bottom: 0;left: 0;right: 0;margin: auto;将子元素居中。

  13. 使用display: flex;和align-content: center;属性,将父元素设置为flex,并使用align-content: center;将子元素垂直居中。

  14. 使用display: flex;和align-items: center;属性,将父元素设置为flex,并使用align-items: center;将子元素垂直居中。

  15. 使用display: flex;和justify-items: center;属性,将父元素设置为flex,并使用justify-items: center;将子元素水平居中。

  16. 使用display: flex;和place-content: center;属性,将父元素设置为flex,并使用place-content: center;将子元素居中。

  17. 使用display: flex;和place-items: center;属性,将父元素设置为flex,并使用place-items: center;将子元素居中。

  18. 使用display: flex;和align-self: center;属性,将父元素设置为flex,并在子元素上使用align-self: center;将子元素垂直居中。

  19. 使用display: flex;和justify-self: center;属性,将父元素设置为flex,并在子元素上使用justify-self: center;将子元素水平居中。

  20. 使用display: flex;和align-content: center;属性,将父元素设置为flex,并使用align-content: center;将子元素垂直居中。

  21. 使用display: flex;和place-content: center;属性,将父元素设置为flex,并使用place-content: center;将子元素居中。

  22. 使用display: flex;和place-self: center;属性,将父元素设置为flex,并在子元素上使用place-self: center;将子元素居中。

  23. 使用display: flex;和align-items: center;属性,将父元素设置为flex,并使用align-items: center;将子元素垂直居中。

未经允许不得转载 » 本文链接:https://www.117.info/ask/fe132AzsLBAJQAlU.html

推荐文章

  • document.getElementById介绍

    document.getElementById()是一个JavaScript方法,用于通过给定的id值来获取HTML文档中具有该id的元素。
    语法:
    document.getElementById(id)
    参...

  • AFNetworking介绍

    AFNetworking是一个开源的iOS和OSX网络库,它提供了一套简单易用的API来处理网络请求和管理网络连接。该库建立在Foundation框架之上,为开发者提供了一种简单、直...

  • AFNetworking介绍

    AFNetworking是一个开源的iOS和OSX网络库,它提供了一套简单易用的API来处理网络请求和管理网络连接。该库建立在Foundation框架之上,为开发者提供了一种简单、直...

  • SurfaceFlinger是什么东西

    SurfaceFlinger是安卓操作系统中的一个重要组件,也被称为显示引擎。它负责管理和渲染图形窗口,将应用程序和系统界面显示在屏幕上。SurfaceFlinger使用双缓冲机...

  • 关于android:当我们需要重写Handler的handleMessage()方法时

    当我们需要重写Handler的handleMessage()方法时,通常是因为我们希望在主线程中处理消息。
    Handler是Android中用于处理消息和线程间通信的一个类。它可以用...

  • 如何使用EnableWindow()禁用窗口并将其显示为灰色

    要使用EnableWindow()函数禁用窗口并将其显示为灰色,需要按照以下步骤进行操作: 包含Windows.h头文件:在代码文件的开头添加#include ,以包含Windows API所需...