How to display an empty div in HTML using CSS

Empty div(s) collapse only if its height is not set. Thus setting height/min-height of the empty div will show it correctly.

To avoid specifying any explicit height, set the CSS min-height property as below -

min-height: 1px;

Other references/options/tricks -

1 comment:

  1. *:empty { min-height: 1px; } applies to all elements. Thanks for this!

    ReplyDelete