Empty div (with style: height) will not display

前端 未结 7 1214
独厮守ぢ
独厮守ぢ 2020-12-29 21:06

Incredibly simple piece of HTML - but not displaying how I would expect.

I\'m trying to create an empty div that displays as whitespace on the top of the p

7条回答
  •  忘掉有多难
    2020-12-29 21:17

    So I threw your code into my editor and added a black background like below...

    and it showed up fine for me. I am not sure what you were expecting to see, but you can get some seemingly weird results with 'position: absolute'.

    • Absolute means that the element is positioned relative to its first positioned ancestor element.
    • For general use 'position: relative', more often than not, will return desired results. Relative basically means that the element is positioned relative to its normal position, so you can move it via left:20px or right: 20px; It's likley to go where you want it to better. The other thing to consider is the div elements display property. I noticed you did not set it, and you are having trouble with the way the div is displaying. Usually a div element is set to 'display: block;', though not always. I always make sure to define the display property with div elements because I have found that if you don't an object will simply not display at all when you attempt to render it in the browser, or it could display in an undesirable way.

提交回复
热议问题