Adding additional text within the paragraph will result in the images shifting backwards when utilizing flexbox

It seems like there might be something obvious that I'm missing here, but essentially my goal is to create a footer with 2 columns and 2 rows.

In each column, there will be an icon (32x32) and 2 lines of text next to it.

The issue I'm facing is that when I use justify-items: center, the items are centered inside each column. However, if I add more text in my paragraph, the text expands in both directions, pushing the image on its left backwards (increasing the size of the parent div).

As a result, if the text sizes in those 2 lines are different, the footer items won't align properly.

body {
  display: flex;
  flex-direction: column;
  background-color: #ecf3f6;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

.footer-wrapper {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  justify-items: center;
  padding: 5px 0 5px 0;
}

.footer {
  margin-top: auto;
  background-color: #2ea2bf;
}

.footer-description {
  display: block;
  font-weight: bold;
}

.footer-item {}

footer p {
  display: inline-block;
  margin-left: 5px;
}
<body>
  <footer class="footer">
    <div class="footer-wrapper">
      <div class="footer-item">
        <img class="footer-icons" src="img/localizacao.png">
        <p>
          <span class="footer-description">Address</span> Avenue Street.
        </p>
      </div>
      <div class="footer-item">
        <img class="footer-icons" src="img/phone.png">
        <p>
          <span class="footer-description">Phone</span> +1 234 5678
        </p>
      </div>
      <div class="footer-item">
        <img class="footer-icons" src="img/email.png">
        <p>
          <span class="footer-description">Email</span> <a href="mailto:example@example.com">example@example.com</a>
        </p>
      </div>
      <div class="footer-item">
        <img class="footer-icons" src="img/clock.png">
        <p>
          <span class="footer-description">Opening Hours</span> Mon-Sat: 9am - 5pm
        </p>
      </div>
    </div>
  </footer>
</body>

Image of desired layout

Answer №1

To streamline the code, I have removed a majority of the classes. However, feel free to reintroduce them as needed.

I adjusted the grid and card width to min-content. This modification led to an unexpected wrapping issue, which was resolved by adding white-space: nowrap;.

This configuration ensures that each element will only be as wide as its content. To create intentional line breaks, utilize the <br> tag.

body {
  display: flex;
  flex-direction: column;
  background-color: #ecf3f6;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

footer {
  margin-top: auto;
  background-color: #2ea2bf;
}

.footer-wrapper {
  margin: 0 auto 0 auto;
  width: min-content;
  display: grid;
  grid-template-columns: min-content min-content;
  grid-auto-rows: auto;
  grid-column-gap: 20px;
  padding: 5px;
  white-space: nowrap;
}

.footer-wrapper div p span {
  display: block;
  font-weight: bold;
}

.footer-wrapper div {}

.footer-wrapper div p {
  display: inline-block;
  margin-left: 5px;
}
<footer>
  <div class="footer-wrapper">
    <div>
      <img class="footer-icons" src="img/localizacao.png">
      <p>
        <span>Address</span> Congeriem arce homini.
      </p>
    </div>
    <div>
      <img class="footer-icons" src="img/telefone.png">
      <p>
        <span>Phone</span> +351 211 149 501
      </p>
    </div>
    <div>
      <img class="footer-icons" src="img/email.png">
      <p>
        <span>E-Mail</span> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d8abada8a8b7aaac98abada8a8b7aaacf6bbb7b5">[email protected]</a>
      </p>
    </div>
    <div>
      <img class="footer-icons" src="img/localizacao.png">
      <p>
        <span>Address</span> Congeriem arce homini.
      </p>
    </div>
  </div>
</footer>

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

Switching up the image using a dropdown selection menu

I am struggling with updating an image based on the selection made in a dropdown menu. I am quite new to javascript, so I believe there might be a simple issue that I am overlooking. Here is my attempt at doing this: JS: <script type="text/javascript" ...

Tips for Properly Positioning Floating Pop-Up Messages Using CSS and jQuery

I was experimenting with adding a button that triggers a popup message to my website. I followed a coding tutorial using jQuery and CSS, which looks like this: Javascript : !function (v) { v.fn.floatingWhatsApp = function (e) {...} }(jQuery); CSS : .fl ...

Label text will not be wrapped in front of the label (bootstrap)

I'm struggling with some css coding. I want the text to wrap so the label is positioned on the middle right of the box, similar to this example: https://i.sstatic.net/RBIOS.png. However, currently it looks like this: http://jsfiddle.net/yuvemL1z/ and ...

I'm feeling a bit lost on how to bring my random quote generator to life

I'm attempting to add animation to my random quote generator by making it look like another card is being flipped on top of the existing one, similar to a deck of cards. With limited coding knowledge, I followed a tutorial and made some adjustments to ...

Replicate the ctrl+/- function through coding

While browsing with your browser, you have the ability to adjust the font size by using CTRL + + or CTRL + -. Is there a way to replicate this functionality through code, such as with JavaScript? I am looking to add buttons on my website that allow users ...

The alignment of h2 headings becomes disordered beyond a specific viewport width

Can someone help me with an issue I'm facing regarding the placement of my "rightside" navigation? The problem arises when the viewport width drops below 767px, causing the h2 elements in the rightnav to align themselves directly next to the #leftnav. ...

The PHP Form submit button is unresponsive

My code is functioning correctly, but when I try to submit the form, it doesn't provide any response or error message. I even attempted to change the form action attribute and save the result in a different file, but still no output was displayed. &l ...

Including a drop-down arrow or triangle next to the initial button

In the navigation bar displayed below https://codepen.io/shaswat/pen/XzpRXL Is it possible to create a down triangle or arrow next to the "home" link, which changes direction upward when hovered over? How can this be achieved without modifying any HTML e ...

Reorganize a list based on another list without generating a new list

Among the elements in my HTML list, there are items with text, input fields, and tables. I also have a specific order list like [3,1,2,0]. Is it feasible to rearrange the items in the HTML list on the page based on this order list without generating a new ...

Why is my client program not receiving a response from this socket.io server?

Currently, I am in the process of developing a trivia game where two users engage in answering questions with the winner being declared at the end. As part of this project, I have integrated socket.io to facilitate the exchange of answers. However, I have ...

Incorporate a vertical scrollbar in the tbody while keeping the thead fixed for smooth vertical scrolling

I'm seeking a solution to implement horizontal and vertical scroll for my table. Currently, the horizontal scroll is working fine, but when trying to add vertical scroll, the table header also moves along with it. Is there a way to keep the table hea ...

Tips for equalizing the height of inner DIVs within a container

Similar Question: How to maximize a floating div? Showing my HTML setup below: <div id="container"> <div id="sidebar"> left <br /><br /><br /><br /><br /><br /> ...

Issues encountered with AngularJs filter search functionality

Why am I having trouble adapting this search filter from here? This is what my code looks like: controllers.js angular.module('starter.controllers', ['starter.services']) .controller('AppCtrl', function($scope, $ionicModal ...

How come my Calendar is not showing up on the browser?

I came across a helpful guide on setting up a Calendar in HTML using JavaScript You can find it here: Unfortunately, the code I tried to use based on that guide isn't functioning as expected. <div class="row"> <div class="col-lg-4 text ...

What's the issue with my jQuery AJAX script?

I am experiencing an issue with my ajax pages using jQuery to retrieve content. Only one page seems to be working properly, even though I have multiple pages set up. How can I resolve this problem? $(document).ready(function() { $('.lazy_content& ...

Arranging Bootstrap inputs horizontally with lengthy labels

When placing two input fields in a row, such as a drop down menu, with labels of varying lengths, the alignment of the inputs can become skewed. This issue persists even when attempting to add breaks in the code due to unpredictable wrapping behavior at di ...

Placing a Div wrapper around the contents of two corresponding elements

I am currently attempting to wrap a div with the class name 'wrapped' around two other divs containing innerHTML of 'one' and 'two'. <div class='blk'>one</div> <div class='blk'>two</di ...

CSS based on conditions for 2 specific divs

Hello, I am working on an HTML page where I need to apply CSS only if certain conditions are met. The div with the id "flipbook-page3-front" will always be present on this HTML page. Sometimes, another div with the id "pagesFlipbook" may also appear on t ...

Can you guide me on how to programmatically set an option in an Angular 5 Material Select dropdown (mat-select) using typescript code?

I am currently working on implementing an Angular 5 Material Data Table with two filter options. One filter is a text input, while the other is a dropdown selection to filter based on a specific field value. The dropdown is implemented using a "mat-select" ...

Looking for a simple method to generate a text-only dropdown link in Bootstrap 4 without using a button?

Is there a simple method to create a text-only dropdown link in Bootstrap 4 without using a button? Or do I have to adjust the padding and buttons using CSS to make the "Delivery" dropdown blend in with the rest of the text? I've searched online and ...