Tips on aligning images of various sizes with text within a row using CSS

Looking for help aligning four different height (ranging from 160-180px) svg images with text positioned directly below each image. I want the images to be neatly aligned in a row, but I'm struggling to align the short text underneath them in a single line as shown in the screenshot.

Thank you in advance!

https://i.stack.imgur.com/RdRbY.png

Update: Apologies for any confusion, I assumed this was a common issue for those experienced in CSS. Here is my HTML and CSS code, along with my use of bootstrap rows.

    <div class="did-you-know">
    <div class="row items">
        <div class="col-lg-3 col-xs-6">
            <div class="icon">
                <img src="/img/mswa/inline-wa.svg"/>
            </div>
            <div class="title text-poppins">
                <p>We’re from WA</p>
                <p>{like you!}</p>
            </div>
        </div>
        <div class="col-lg-3 col-xs-6">
            <div class="icon">
                <img src="/img/mswa/inline-packaging.svg"/>
            </div>
            <div class="title text-poppins">
                <p>We use minimal packaging</p>
                <p>{great for the planet}</p></div>
        </div>
        <div class="col-lg-3 col-xs-6">
            <div class="icon">
                <img src="/img/mswa/inline-quality.svg"/>
            </div>
            <div class="title text-poppins">
                <p>We only choose quality</p>
                <p>{better for your health}</p></div>
        </div>
        <div class="col-lg-3 col-xs-6">
            <div class="icon">
                <img src="/img/mswa/inline-community.svg"/>
            </div>
            <div class="title text-poppins">
                <p>We love giving back</p>
                <p>{great for our community}</p></div>
        </div>
    </div>
</div>


.did-you-know {
    padding: 20px;
    text-align: center;
}

.did-you-know .items .icon {
    padding: 50px;
}
.did-you-know .items .title {
    font-size: 20px;
}

Answer №1

Here is a solution:
Please replace the images with your own images.

<!DOCTYPE html>
<html>
<head>
<style>
* {
  box-sizing: border-box;
}

.column {
  float: left;
  width: 25%;
  padding: 5px;
}

/* Clearfix (clear floats) */
.row::after {
  content: "";
  clear: both;
  display: table;
}
</style>
</head>
<body>

<div class="row">
  <div class="column">
    <img src="https://freesvg.org/img/cartoonsun.png" alt="Sun" style="width:100%">
    <p style='text-align: center;'>test1</p>
  </div>
  <div class="column">
    <img src="https://freesvg.org/img/cartoonsun.png" alt="Tree" style="width:100%">
        <p style='text-align: center;'>test2</p>

  </div>
  <div class="column">
    <img src="https://freesvg.org/img/cartoonsun.png" alt="River" style="width:100%">
    <p style='text-align: center;'>test3</p>
  </div>
  <div class="column">
    <img src="https://freesvg.org/img/cartoonsun.png" alt="Beach" style="width:100%">
    <p style='text-align: center;'>test4</p>
  </div>
  
</div>

</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is your webpage displaying unnecessary white space on smaller screens?

.main { background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab); background-size: 400% 400%; animation: gradient 15s ease infinite; height: 100vh; min-width: 100%; width: 100%; overflow-x: hidden; overflow: hidden; } Here i ...

Enhance the appearance of the standard black rectangle displaying the messages "No video source" or "No video permissions"

Is there a way to change the styling of the video element that appears as a black rectangle with a strikethrough play button when the user is prompted for permission on Safari? Does it have a specific ID, class, or tag that can be targeted? I'm curre ...

Is it possible to create a masonry-style layout with two columns that is responsive without

Is there a way to organize multiple divs of varying heights into two columns that display immediately one after the other, without relying on JavaScript or libraries like packery or masonry? I've experimented with using display: inline-block in this ...

Erase blob_over from the Wordpress menu hover effect

I've created a unique style for the Donate button on this website, but I'm struggling to remove the hover effect. Any suggestions on where to start? Website URL: This is my Custom Class CSS: .donate { background:#4A1383; padding:0px 10px 0px 1 ...

Choosing each item from a lineup, one by one

Currently, I am in the process of developing a small website with multiple pages. The main requirement for this project is to have a vertical menu on the home page. Implementing the menu was relatively easy. I successfully added a hover effect to the vert ...

How can you easily ensure your React web app is responsive?

As I delve into building a web app using reactjs, one particular challenge I encounter is ensuring its responsiveness. An issue arises when the browser size changes, causing my components to overlap and lose alignment. Is there an easy solution to preven ...

JavaScript event listener 'click' not functioning properly

I'm facing an issue with a click event in a script that is associated with a specific div id. When I move the mouse within the div area and click (the cursor remains unchanged), the event listener does not activate. How can I make the div area clickab ...

jQuery Toggle and Change Image Src Attribute Issue

After researching and modifying a show/hide jQuery code I discovered, everything is functioning correctly except for the HTML img attribute not being replaced when clicked on. The jQuery code I am using: <script> $(document).ready(function() { ...

Tips for showcasing boxed numerical characters on a website

Currently, I am tackling a project that involves converting a PDF into HTML. The original .ai file shows some numeric characters inside a box: Even though I am aware that the font used in the file is GothicMB101Pro DeBold-83pv-RKSJ-H, unfortunately, I do ...

Submit form only if the field value is valid

I created a form with an input field that captures the user's mobile number and validates it to ensure it begins with '0'. The validation process is functioning correctly, but I am encountering a problem when submitting the form. Even if the ...

When hovering over the alternating rows of a table, the shadow effect does not appear

I'm encountering an issue with CSS. I have a table and when hovering on the table's tr, there's a CSS property for box-shadow. The problem is that this box-shadow isn't fully visible for the even rows. https://i.sstatic.net/9uSjO.png ...

A layout featuring nested buttons and links within a card element, utilizing the power of Link in NextJs

After extensive searching on S.O., I have been unable to find a solution that works flawlessly. The issue at hand involves a card component in a NextJs application that is encompassed within a <Link> tag. Additionally, there is another <Link> t ...

Methods to Maintain Consistent HTML Table Dimensions utilizing DOM

I am facing an issue with shuffling a table that contains images. The table has 4 columns and 2 rows. To shuffle the table, I use the following code: function sortTable() { // Conveniently getting the parent table let table = document.getElementById("i ...

Clearing Up CSS Height Definitions

Based on my observations from other posts, it seems that to establish the height of an element in percentages or pixels, etc., the parent element's height also needs to be explicitly defined. This implies that the height settings must be specified all ...

The behavior of a fixed position in Flexbox varies when comparing Chrome to Safari and Firefox

In Chrome, the following code works as expected, with the list element positioning itself at the very left of the .PageContainer when scrolling down. However, in Safari and Firefox, the list element positions itself just after the logo. Are there any CSS r ...

Leveraging CSS to automatically number nested sections

Assume we have an example HTML or XML document structured like this: <body> <section> <h1>This should be numbered 1</h1> <section> <h1>This should be numbered 1.1</h1> <p>blah& ...

Concealing a hyperlink within a DIV by removing or hiding it

I am looking to temporarily hide or remove a specific link (team.aspx) within a drop-down menu, with the intention of adding it back in later. Here is my current code: <div id="nav_menu"> <ul id="nav"> <li class="current"><a href= ...

Hover effects can be applied to CSS tabs

There seems to be a CSS issue on Chrome where the background image is not hiding when clicking on next tabs. I have used the following code: .paymentBank ::after { content: " "; } You can view the live code [here][1] and I have also attached a scree ...

Ways to position two images in the center

A website has been created by me and now I am looking to center text on the two images in the header. Here is the relevant code snippet: <div class="header"> <img src="css/title578145459.png" class="headerImage left&qu ...

What is the best way to vertically align Bootstrap Columns to ensure they have consistent heights?

I'm currently in the process of building a website that features multiple images and content organized into columns using Bootstrap as the framework. I'm wondering if there's a way to automatically adjust all the columns to the height of th ...