Position absolute top property based on the parent width

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

Having the following HTML

This is a text

and the following CSS

.child-of-         


        
相关标签:
2条回答
  • 2021-01-21 04:29

    try to add position: relative for the parent element.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题