I am building a website for a law firm and I am trying to implement a CSS grid like in the image below.
I have issues adding icons and padding in each grid to deal with as well.
.grid-column {
float: left;
width: 31%;
padding: 10px;
height: 300px; /* Should be removed. Only for demonstration */
margin: 10px;
font-family: Arial, Helvetica, sans-serif;
}
/* Clear floats after the columns */
.grid-row:after {
content: "";
display: table;
clear: both;
}
/* Wrap text within columns */
.grid-column h2, .grid-column p {
max-width: 80%; /* Adjust as needed */
white-space: wrap;
}
<div class="grid-row">
<div class="grid-column" style="background-color:#aaa;">
<h2>Corporate & Security</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus luctus nec ullamcorper mattis</p>
</div>
<div class="grid-column" style="background-color:#bbb;">
<h2>Medical & Health Care</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus luctus nec ullamcorper mattis</p>
</div>
<div class="grid-column" style="background-color:#ccc;">
<h2>Pensions & Benefits Law</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus luctus nec ullamcorper mattis</p>
</div>
</div>
<div class="grid-row">
<div class="grid-column" style="background-color:#aaa;">
<h2>Home Credit Law</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus luctus nec ullamcorper mattis</p>
</div>
<div class="grid-column" style="background-color:#bbb;">
<h2>Life Insurance Law</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus luctus nec ullamcorper mattis</p>
</div>
<div class="grid-column" style="background-color:#bbb;">
<h2>E-Commerce Law</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus luctus nec ullamcorper mattis</p>
</div>
</div>
2
Answers
As @Temani Afif suggested you can use css grid layout for this.
<div>
for rowsgrid-template-columns
using CSSrepeat
withauto-fit
andminmax