I have 4 images in a container. When I set the images to occupy 50% of the container, 2 stacks on top and 2 stacks on the bottom and it perfectly matches the edge on the container like I want. The problem occurs when I add margin. The images stack in one line meaning the margin made in too big for the container so they stack in one line
So I begin experimenting with decimals
I made the width of the images 49.5% and I set margin-right to 0.5%. The problem is the images on the right don't align with the container edge perfectly. There is still space on the edge and I cant add any more margin or width or else it stacks in one line because I am over 50%. Look at the blue part in the image.
My question I guess is how do I get the images to fit my container accurately. am I using the wrong units?
Picture of what I am talking about
.section1{
width: 100%;
height: 95vh;
background-color:;
}
.section1 .wrapper{
width: 94%;
height: 600px;
background-color: royalblue;
}
.section1 .card{
float: left;
width: 49.47%;
height: 300px;
margin-right: 0.53%;
color:white;
}
.pizza{
background: url(./img/main\ 1.jpg)no-repeat;
width:100%;
height: 100%
}
.burger{
background: url(./img/main\ 2.jpg)no-repeat;
width: 100%;
height:100%;
}
.pasta{
background: url(./img/main\ 3.jpg)no-repeat;
width: 100%;
height: 100%
}
.salad{
background: url(./img/main\ 4.jpg)no-repeat;
width:100%;
height: 100%;
}
<div class="section1">
<div class="wrapper">
<div class="card">
<div class="pizza">
<div class="itembox1">
<h1>PIZZA</h1>
</div>
</div>
</div>
<div class="card">
<div class="burger">
<div class="itembox1">
<h1>BURGERS</h1>
</div>
</div>
</div>
<div class="card">
<div class="pasta">
<div class="itembox1">
<h1>PASTA</h1>
</div>
</div>
</div>
<div class="card">
<div class="salad">
<div class="itembox1">
<h1>SALAD & FIT</h1>
</div>
</div>
</div>
</div>
</div>