How to make a div with no content have a width?

Use CSS to add a zero-width-space to your div. The content of the div will take no room but will force the div to display

.test1::before{
   content: "\200B";
}

Use min-height: 1px; Everything has at least min-height of 1px so no extra space is taken up with nbsp or padding, or being forced to know the height first.


a div usually needs at least a non-breaking space ( ) in order to have a width.


Either use padding , height or &nbsp for width to take effect with empty div

EDIT:

Non zero min-height also works great