i just want to create a simple horizontal list with some divs
. Therefor i did this:
Now as you can see in the result the divs are not next to each other. But i used width of 50%. So what is wrong?
i just want to create a simple horizontal list with some divs
. Therefor i did this:
Now as you can see in the result the divs are not next to each other. But i used width of 50%. So what is wrong?
Elements with inline-block
have a little margin on the right side. You can see this with this Code:
div {
background:black;
display:inline-block;
width:20%;
}
<div>Test #1</div>
<div>Test #2</div>
To solve your problem, you can use the following:
body, html {
padding:0;
margin:0;
}
.list{
width:100%;
height: 100%;
background: black;
}
.list div{
float:left;
display: block;
width: 50%;
height: 100px;
background: red
}
<div class="list">
<div style="background: red">1</div>
<div style="background: orange">2</div>
<div style="background: yellow">3</div>
<div style="background: lightyellow">4</div>
</div>
actually, this is a problem of inline-block
so if you want to use it, you can't have whitespace between elements ;)
check your fiddle: https://jsfiddle.net/ks0t1xoy/13/
after removing all whitespaces from your .list
all elements align nicely, without touching your CSS