<ul>
<li><div style="background-color: red; width: 10px; height: 10px; display: inline"></div>aaa</li>
<li>bbb</li>
<li>ccc</li>
</ul>
why in this example div is not visible? How can i add box with background-color in list?
Because it is empty. It becomes visible if you add some text inside.
<ul>
<li><div style="background-color: red; width: 10px; height: 10px; display: inline">test</div>aaa</li>
<li>bbb</li>
<li>ccc</li>
</ul>
display: inline
will not display unless it contains some kind of contents. You'd need to either
display: inline-block;
or
<div style="background-color: red; width: 10px; height: 10px; display: inline"> </div>
First of all there's no text in your <div>
so you should do it like this :
You need to place the word aaa
between your <div>
tags
<li><div style="background-color: red; width: 10px; height: 10px; display: inline">aaa</div></li>
moreover you don't need any display: inline;
property here you can simply do it like this :
And if you need all the <li>
elements inline than you need to give display: inline;
to your <li>
and display: inline-block;
to your <div>
element also like this : My fiddle
According to the W3C validator div inside list is perfectly fine. You have to give some text in div. So that you can view the div.