div嵌套居中的三种方法

div2
1
2
3
4
5
<div class="div1">
    <div class="div2">
        div2
    </div>
</div>

css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
.div1 {
    background-color: aqua;
    height: 100px;
    width: 100px;
 
    /* 方法一、三 */
    /* 子元素为绝对定位,父元素必须为相对定位 */
    /* position: relative; */
 
    /* 方法二 */
    /* display: flex;
    justify-content: center;
    align-items: center; */
}
 
.div2 {
    background-color: yellow;
    height: 50px;
    width: 60px;
 
    /* 方法一 */
    /* position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    margin: auto; */
 
    /* 方法三 */
    /* position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); */
}

  

  

posted on   itjeff  阅读(151)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2018-04-20 深入浅出HTTPS基本原理
2015-04-20 读取上传的CSV为DataTable
2015-04-20 判断sqlserver对象是否存在

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示