margin-block-start

 MDN :CSS 属性定义了一个元素的逻辑块的开始边距, 是用来根据元素的书写模式(writing-mode),方向(direction)和文本方向(text-orientation)进行实际边界的衡量。

By default, you will have the following mapping:

margin-block-start = margin-top
margin-block-end = margin-bottom
margin-inline-start = margin-left
margin-inline-end = margin-right

Example:

Now if we change the writing mode, you will see that we will have a different mapping.

In the above, you will notice when using vertical-lr a mapping equal to

margin-block-start = margin-left
margin-block-end = margin-right
margin-inline-start = margin-top 
margin-inline-end = margin-bottom 

and when using vertical-rl

margin-block-start = margin-right
margin-block-end = margin-left
margin-inline-start = margin-top 
margin-inline-end = margin-bottom

摘自: html - What is the difference between margin-block-start and margin-top? - Stack Overflow 

<!DOCTYPE html>
<html>

<head>
    <title>CSS | margin-block-start Property</title>
    <style>
        div.text-center {
            width: 100%;
            height: auto;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }


        div.bg {
            background-color: yellow;
            width: 120px;
            height: 80px;
        }

        .two.bg {
            margin-top:20px;
            /* 与书写模式相关 书写模式从上到下,从左到右(writing-mode: vertical-lr),margin-block-start就相当于margin-left */
            margin-block-start: 20px;
            writing-mode: vertical-lr;
            background-color: purple;
        }
    </style>
</head>

<body>
    <div class="text-center">
        <b>CSS | margin-block-start Property</b>
        <br><br>
        <div class="one bg">GeeksforGeeks</div>
        <div class="two  bg">GFG</div>
        <div class="three  bg">GeeksforGeeks</div>
    </div>
</body>

</html>

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值