I have this HTML that displays icons on the left, and summary on the right. I wrapped the icons and the summary using a bootstrap class col-sm-3 col-md-3
. I did this because I wanted to display only four icons per row.If there are more than four icons, then the icons need to move the next row. I put the summary in col-sm-3 col-md-3
class because I want the text to be next to the icons.
However, I no longer want to use bootstrap, so I am looking at ways to achieve what I want with just CSS.
Here is the HTML:
<div class="coreStuff">
<div class="col-sm-3 col-md-3">
<i class="fa-solid fa-globe"></i>
<i class="fa-solid fa-globe"></i>
<i class="fa-solid fa-globe"></i>
<i class="fa-solid fa-globe"></i>
<i class="fa-solid fa-globe"></i>
<i class="fa-solid fa-globe"></i>
<i class="fa-solid fa-globe"></i>
<i class="fa-solid fa-globe"></i>
<i class="fa-solid fa-globe"></i>
</div>
<div class="col-sm-3 col-md-3">
<p>Global warming can result in many serious alterations to the environment, eventually impacting human health. It can also cause a rise in sea level, leading to the loss of coastal land, a change in precipitation patterns, increased risks of droughts and floods, and threats to biodiversity.</p>
</div>
</div>
I think I got it to partially work with CSS grid, but let’s say there is only one icon, or two icon, in that case this CSS won’t work because it creating a wide gap between the icon(s) and the summary. Is there a way to make the summary responsive and dynamically adjust with respective to the icons?
CSS:
.theIcons{
display: grid;
grid-template-columns: repeat(4, 1fr);
}
.theSummary{
width: 25%;
}
2
Answers
Hope this helps.
CSS :
(the borders are just to give visual feedback, you can style as per your needs. Also, you might have to tweak the solution based on your own design and layout)
Do you mean there is an icon for each summary? If that is true you have to change your HTML to be like this
and your css It could be like this :