I am trying to align CSS info boxes for a medical practice website at the same heightscreen shot the first two boxes appear fine except for the last one.
i want the boxes to appear align at the same height. i have tried many techniques but none of the seem to get the boxes aligned at the same height.
This is the isolated HTML code together with the css.
.box1 {
color: #314370;
border-top-right-radius: 25px;
border-bottom-right-radius: 25px;
border-bottom-left-radius: 25px;
border-top-left-radius: 25px;
height: 300px;
width: 300px;
box-shadow: 0 3px 10px darkgrey;
display: inline-block;
}
.box2 {
color: #314370;
height: 300px;
width: 300px;
box-shadow: 0 3px 10px darkgrey;
display: inline-block;
border-top-right-radius: 25px;
border-bottom-right-radius: 25px;
border-bottom-left-radius: 25px;
border-top-left-radius: 25px;
}
.box3 {
color: #314370;
height: 300px;
width: 300px;
box-shadow: 0 3px 10px darkgrey;
display: inline-block;
border-top-right-radius: 25px;
border-bottom-right-radius: 25px;
border-bottom-left-radius: 25px;
border-top-left-radius: 25px;
}
<center>
<div class="box1" id="info"><img src="images/clock.png" width="100px"><br><b style="color:#223a66">Working hours:</b><br>
<p style="color:grey">Mon-Fri 09:00 am-18:00 pm<br> Sat-Sun 10:00 am-17:00 pm<br> Public Holidays 10:00 am-17:00 pm</p>
</div>
<div class="box2"><img src="images/s3.png" width="100px"><br><b style="color:#223a66"></b>
<b>Walk ins are welcome</b><br>
<p style="color:grey">
No appointment needed<br> Open seven days a week <br>and 365 days a year
</p>
</div>
<div class="box1"><img src="images/mail.png" width="100px"><br><b>Contact Us:</b><br>
<p style="color:##223a66;"><b>[email protected]</b></p>
<p style="color:##223a66;"><b> Call: ---</p>
</b></p>
<!--<p style="color:grey;">
Make Enquiries=<br>-->
</div>
</div>
</center>
2
Answers
Flexbox
Flexbox will let you align the items next to each other. However, you will need add
flex-wrap: wrap
to allow a "linebreak" at screens smaller then 900px width. Otherwise the elements will be squished. You can apart the element from each other by using thegap
property. Overall Flexbox has the best support on browsers including deprecated IE. To cenetr the elemnts as intended you can usejustify-content: center;
:CSS Grid
Unlike Flexbox, Grid allows you to align elements in a tabular-like layout. It is fixed on those cells and do not support certain specifics such as centerign elements such as flexbox. However you could use it to occupy the space as best as possible:
Sidenote
Your CSS is repetitive. The main advantage of CSS is performance and not needing to repeat code but to reuse code for multiple elements and documents.
In your CSS all the boxes have the exact same styling. As such a common class should be used and the same style applied to all elements. You also should use syntaxes in your case. Instead of declaring every 4 corners with a border-radius of 25px, you could simply address all borders in one call and apply the same bend to it:
That alone would cut your CSS code by more than 70%.
You can get elements which are display-inline to line up in the way you want by adding