I am trying to add a width to a div
, but I seem to be running into a problem because it has no content.
Here is the CSS and HTML I have so far, but it is
You add to this DIV's CSS position: relative
, it will do all the work.
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";
}
There are different methods to make the empty DIV with float: left
or float: right
visible.
Here presents the ones I know:
width
(or min-width
) with height
(or min-height
)padding-top
padding-bottom
border-top
border-bottom
::before
or ::after
with:
{content: "\200B";}
{content: "."; visibility: hidden;}
inside DIV (this sometimes can bring unexpected effects eg. in combination with text-decoration: underline;
)Either use padding
, height
or  
for width to take effect with empty div
EDIT:
Non zero min-height
also works great
Try to add display:block;
to your test1
a div usually needs at least a non-breaking space ( ) in order to have a width.