16
loading...
This website collects cookies to deliver better user experience
inline-block
css property.<div class='parent'>
<div class='child'>child 1</div>
<div class='child'>child 2</div>
</div>
.parent {
border: 1px solid black;
margin: 1rem;
padding: 2rem 2rem;
text-align: center;
}
.child {
display: inline-block;
border: 1px solid red;
padding: 1rem 1rem;
vertical-align: middle;
}
inline-block
property on the parent placed the two divs side by side and as this is inline-block
the text-align
feature worked here just like an inline element does.verticle-align:middle
to vertically align the divs taking their center into consideration.margin-right
to the first div and/or margin-left
to the second div.<div class="float-parent-element">
<div class="float-child-element">
<div class="red">Float Column 1</div>
</div>
<div class="float-child-element">
<div class="yellow">Float Column 2</div>
</div>
</div>
.float-parent-element
is simply the parent element that contains both .float-child-element
elements..float-parent-element {
width: 50%;
}
.float-child-element {
float: left;
width: 50%;
}
.red {
background-color: red;
margin-left: 50%;
height: 100px;
}
.yellow {
margin-left: 50%;
height: 100px;
background-color: yellow;
}
.float-child-element
a property of float left to position then side by side and a width of 50% of the parent div..float-child-element
I have added their respective colors with some height of 100px and margin to better differentiate them.<div class="flex-parent-element">
<div class="flex-child-element magenta">Flex Column 1</div>
<div class="flex-child-element green">Flex Column 2</div>
</div>
.flex-parent-element {
display: flex;
width: 50%;
}
.flex-child-element {
flex: 1;
border: 2px solid blueviolet;
margin: 10px;
}
.flex-child-element:first-child {
margin-right: 20px;
}
<div class="grid-container-element">
<div class="grid-child-element purple">Grid Column 1</div>
<div class="grid-child-element green">Grid Column 2</div
</div>
.grid-container-element {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px;
border: 1px solid black;
width: 50%;
}
.grid-child-element {
margin: 10px;
border: 1px solid red;
}