美文网首页
未知宽高垂直水平居中的方法

未知宽高垂直水平居中的方法

作者: ai_cuicui | 来源:发表于2020-04-18 17:52 被阅读0次
<div class="father">
    <div class="sun"></div>
</div>

第一种

.father{
            width: 500px;
            height: 500px;
            background-color: #cccccc;
            position: relative;
        }
        .sun{
            width: 100px;
            height: 100px;
            background-color: #ffffff;
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            margin: auto;
        }

第二种

.father{
            width: 500px;
            height: 500px;
            background-color: #cccccc;
            position: relative;
        }
        .sun{
            width: 100px;
            height: 100px;
            background-color: #ffffff;
            position: absolute;
            margin: auto;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
        }

第三种(弹性盒子)

.father{
            width: 500px;
            height: 500px;
            background-color: #cccccc;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .sun{
            width: 100px;
            height: 100px;
            background-color: #ffffff;
        }

相关文章

  • 未知高度垂直水平居中

    未知宽高的弹出框,水平垂直居中 parrent 内的元素水平垂直居中 parrent 内的元素垂直居中

  • css---各种居中垂直详解

    项目中经常会有各种居中的布局,什么垂直居中,水平居中,垂直水平居中,已知宽高和未知宽高居中,那么接下来就整体的总结...

  • 1-css的多种垂直居中的方法

    多种css垂直居中的方法 ==css3不定宽高水平垂直居中== 1:固定高宽的垂直居中 如上图,固定高宽的很简单,...

  • 水平居中和垂直居中

    本文列举了水平和垂直居中的方法,分别在已知宽高和未知宽高的情况。 从以下方法不难看出,要制造居中,大体分为位移...

  • css实现水平垂直居中的方法

    本文主要针对子元素已知宽高和未知宽高的情况下,对其进行水平垂直居中  本文假设对如下元素进行水平垂直居中方式(父元...

  • 未知宽高垂直水平居中的方法

    第一种 第二种 第三种(弹性盒子)

  • 居中布局

    水平居中 垂直居中 垂直水平居中 已知元素的宽高的居中布局 定位居中布局 盒模型居中布局 图片的垂直水平居中(利用...

  • 不定宽高的div盒子和不定宽高的盒子水平垂直居中

    让一个不定宽高的div,垂直水平居中的几种实现方式 不定宽高的div垂直居中的方式: 1、使用CSS方法: 父盒子...

  • css之水平垂直居中

    不定宽高的水平垂直居中---transform

  • css关于居中的方式

    父元素没有固定宽高 水平垂直居中 html: css: 水平居中 不确定子元素宽高 设置水平居中,先将子元素转化为...

网友评论

      本文标题:未知宽高垂直水平居中的方法

      本文链接:https://www.haomeiwen.com/subject/obyvvhtx.html