Does position add: absolute to a block element makes it behave like inline?

Please refer to https://jsfiddle.net/6nyh5p40/

position: absolute;

A div is made to behave like an inline element. Remove the property, and we see that the div is behaving as it should, a block element.

My question is: is it just adding a position: absolute to a block element that makes it behave like inline?

+4
source share
5 answers

Yes, a block element element that has the full width of the parent content area will not be executed when the element is absolutely positioned.

(100% ) , postion: relative; , 100%.

+5

Mozilla Developer Network:

, . , , , ( , ) , , ( ). , .

: https://developer.mozilla.org/en-US/docs/Web/CSS/position#Notes

, , . , , .

+2

. , ,

display:inline-block;

-, , : . , . , display: block; , <p>. . : . : , float: left;

0

. div.

inline

display:inline-block;

float:left;
0

, inline.

absolute fixed . width, height.

position:absolute .

https://jsfiddle.net/6nyh5p40/1/ - , .

#x {
background: red;
height: 100px;
position: absolute;
}
span {
background: green;
height: 100px;
position: absolute;
}
<div id = "x">div 1</div>abcd

<span>Testing span</span>
Hide result
0

All Articles