absolute vs relative position width & height

前端 未结 1 1959
旧巷少年郎
旧巷少年郎 2020-11-27 03:35

i know what is absolute & relative position but some points are still not cleared to me. for reference

css:

.rel{
    position:relative;
    back         


        
相关标签:
1条回答
  • 2020-11-27 04:19
    1. Setting position:absolute removes the element in question from the normal flow of the document structure. So unless you explicitly set a width it won't know how wide to be. you can explicitly set width:100% if that is the effect you're after.

    2. An element with position:relative on the whole behaves in the same way a normal position:static element does. Therefore, setting height:100% will have no effect unless the parent element has a defined height. In contrast absolute positioned elements are removed from the document flow so are free to adjust to whatever height their containing element currently has.

    3. This is probably something to do with the parent elements in your HTML but I can't help further unless you provide the full HTML and CSS of your page.

    4. The default value of the top and left properties is auto. This means the browser will calculate these settings for you and set them to where the element would be rendered if it didn't have position:absolute.

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