You can "shrink-wrap" each li
's content with a combination of float
and clear
, as in this answer.
li {
white-space: pre;
background: blue;
float:left;
clear:left;
min-width:100%;
}
The last line is from koala_dev's answer. It forces shorter-content elements to have full-width background.