Remove padding
,margin
and border
from width by using calc() in CSS.
Here, margin:10px, padding:10px and border:1px;
So it both in left and right so its double
try this
width: calc(33.3% - (20px + 20px + 2px));
instead of
width: 33.3%;
That is
section{
position: relative;
width: calc(33.3% - (20px + 20px + 2px));
float: left;
margin: 10px;
padding: 10px;
border: 1px solid black;
background-color: #cccccc;
}
Remove box-sizing:border-box
because,
The box-sizing property allows us to include the padding and border in an element's total width and height.If you set box-sizing: border-box;
on an element, padding and border are included in the width and height:
box-sizing
- Defines how the width and height of an element are calculated: should they include padding and borders, or not
Working Demo
*,html{
margin: 0;
padding: 0;
}
section{
position: relative;
width: calc(33.3% - (20px + 20px + 2px)) !important;
float: left !important;
margin: 10px;
padding: 10px;
border: 1px solid black;
background-color: #cccccc;
}
<section>section1</section>
<section>section2</section>
<section>section3</section>