html - Unwanted padding space created by ul and li -


html

<ul>     <li><img src="images/yellow.gif" alt="yellow"></li>     <li><img src="images/orange.gif" alt="orange"></li>     <li><img src="images/purple.gif" alt="purple"></li>     <li><img src="images/blue.gif" alt="blue"> </li>     <li><img src="images/pink.gif" alt="pink"> </li>     <li><img src="images/green.gif" alt="green"> </li>     <li><img src="images/black.gif" alt="black"> </li>     <li><img src="images/gray.gif" alt="gray"> </li>     <li><img src="images/red.gif" alt="red"> </li> </ul> 

css

ul{     display: flex;     flex-wrap: wrap;     width: 45%;     height: 40%;     border: 1px solid red;     list-style: none;     margin: 0 auto; }  ul li{     flex: 1; } 

actual output

enter image description here

as per actual output, there left-margin on inspecting ul element, shown below,

enter image description here


there right-margin on inspecting li element, shown below

enter image description here


expected output

enter image description here

1) why these margin space exist?

2) how avoid these margin space?

the whitespace on left caused default padding on ul. remove with:

ul { padding-left: 0; } 

(note browsers may use margin instead of padding indentation.)

the whitespace on right caused flex-wrap feature. when flex items wrap, container does not recalculate width shrink-wrap new layout.

by re-sizing window horizontally , forth, you'll see right spacing come , go: demo

here more details , possible workaround: https://stackoverflow.com/a/32811002/3597276


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -