Position absolute top property based on the parent width

前端 未结 2 540
后悔当初
后悔当初 2021-01-21 03:54

Having the following HTML

This is a text

and the following CSS

.child-of-         


        
2条回答
  •  滥情空心
    2021-01-21 04:35

    I think you're looking for margin-top property.

    A percentage value on top/bottom padding or margins is relative to the width of the containing block.

    .child-of-body {
        position: absolute;
        margin-top: 10%;
    }
    

    JSFiddle Demo.

    Also, it's worth to take a look at Louis Lazaris' Vertical Percentages in CSS article.

提交回复
热议问题