absolute position affects width?

后端 未结 3 1414
执念已碎
执念已碎 2020-12-06 10:12

I am new to css. I am wondering why when I change the positioning of the div element to absolute, the width of the div element changes? Tried it out in Chrome v25.0.1364.17

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 10:43

    Because absolutely positioned elements do not behave as block level elements and do not flow after each other like normal a

    does.

    You will need to set a width and a height for a div that is absolutely positioned, depending what it contains.

    Your absolutely positioned element will position relative to the first parent element it is in. So, a simple example:

    A simple 'gotcha' is not setting the parent element to have position: relative;

    
    
    I'm positioned absolutely to my parent.

提交回复
热议问题