Skip to content Skip to sidebar Skip to footer

Minimum Height For Div Or Span With Empty Element

When I enclose within span or div a string that happens to be an empty string or includes only white spaces, that part does not have any height, and when that span or div is furthe

Solution 1:

Your span element needs to become a block element if you want to set its height. So set the style display: block or display: inline-block as appropriate.

span.item {
  display: inline-block;
}

To set the height of an empty span, I've found it best to simply inject a   rather than set a min-height. (UPDATE: per @sawa, rather than using a non-breaking space character, perhaps a more suitable character would take up no space, i.e. the unicode ZERO WIDTH SPACE character, \200b.)

span.item:empty::before {
  content: "\200b"; /* unicode zero width space character */
}

This will work for whatever the font size may be, and it avoids problems with the baseline not lining up with adjacent text. Look at the line that says "Huh?" below:

how baseline fails

http://plnkr.co/edit/GGd7mz?p=preview

(See similar question: https://stackoverflow.com/a/29354766/516910)

Solution 2:

Your code isn't right: you don’t need enclosing quotes ("") around values in CSS.

Either use:

min-height: 1em; /* I am not sure if one can use em with height properties */

Or use:

min-height: 12px;

Post a Comment for "Minimum Height For Div Or Span With Empty Element"