I made a simple example to test this out. I have one wrapper div
with two other div
elements inside it set to display: inline-block;
. The two inner div
elements fall on the same line, but how do I get them centered on the half of the main div
they belong to? For example, the blue box in the middle of the left side of the main div
and the red box in the middle of the right side of the main div
. Code and screenshot below.
Also, the inspector shows a width of 204px for the main-box
div
and even when I set padding
and margin
to 0 there's still a gap on the bottom between the blue/red boxes and the border of the main-box
. How do I get rid of the gap?
.box-test {
height: 200px;
display: inline-block;
width: 30%;
box-sizing: border-box;
}
#blue {
background-color: blue;
}
#red {
background-color: red;
}
#main-box {
text-align: center;
border: 1px solid black;
}
<div id="main-box">
<div id="blue" class="box-test"></div>
<div id="red" class="box-test"></div>
</div>