Is there a way to align a span in the center after a Font Awesome icon within a flex

In the Html structure below, there is an issue with centering the span after the Font Awesome icon in one of the divs:

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 60px;
  height: 200px;
  padding: 5px;
 }

.container span{
display: inline-block;
}

.container div{
display: flex;
 align-content: center;
 flex-direction: column;
}
<head>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
</head>
        
<div class="container">
  <div>
    <span>1</span>
    <span>1</span>
  </div>
  <div>
    <span><i class="fas fa-battery-quarter"></i></span>
    <span>2</span> <!-- this is not centered -->
  </div>
</div>

<!-- longer text shows that the icon is not center either -->
<div class="container">
  <div>
    <span>1</span>
    <span>1</span>
  </div>
  <div>
    <span><i class="fas fa-battery-quarter"></i></span>
    <span>2222</span> <!-- this is not centered -->
  </div>
</div>

The alignment issue seems to be related to the font awesome icon causing the text below it not being centered properly. How can I adjust my code to have both the icon and text centered?

Update: Upon further testing, it appears that the length of the text also affects the centering of the icon itself.

If align content works for the items in the first div, why doesn't it have the same effect on the second div containing the icon?

Answer №1

To align the text in the second div to the center, you can include text-align: center;

.container div {
  text-align: center;
}

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

What is the method for targeting an HTML element in PHP?

I am facing an issue with my HTML page. When clicking on a link within the page, it triggers a php function that adds an HTML table using AJAX (the php function is stored in a separate PHP file). Now, I have a button on the page that should run another ph ...

Tips for effectively utilizing the jQuery closest method

This webpage allows me to upload images to a database and then display them again. When uploading an image, a comment can be added to it using a textarea. When the images are displayed again, the comments are shown and editable as well. Recently, I added a ...

Guide to retrieving IDs of images on a canvas during drag and drop functionality

I've developed a finite state machine drawing tool that includes drag-and-drop functionality for different images, such as states and arrows. Each arrow creates a div tag for the transition, with unique ids assigned to every state, arrow, and transiti ...

a rare form of data presentation on a webpage

I came across this on a website. I'm curious if there's a specific tool for this or if it was customized. <!-- Name :: ABCD123 AnotherName :: ErrorArray :: ARRAY[2 * 120] [1] [0:ErrorCode]{ } [1:ArrayIndex]{ } ErrorArray2 :: ARRAY[3 ...

Choose a tag using $(this)

Here is the code snippet I am working with: $("#accordian h3").click(function(){ $("#accordian ul ul").slideUp(); if(!$(this).next().is(":visible")) { $(this).next().slideDown(); ...

Troubleshooting problem with jQuery attribute value assignment

I am currently working with text boxes that store data in local storage upon saving. $(".formFieldUserData").each(function () { var key = $(this).attr("name"); var value = $(this).attr("value"); localStorage.setItem(key, value); } However, I have c ...

Altering the hexadecimal code to adjust the color of a string

I have come across several posts like this one, but none of them have been able to solve my issue. const HexPattern = /(#[0-9a-f]{6})(\s*[\w,]+\s*)/gi function parseColors(str) { return str.replace(HexPattern, (s, g0, g1) => `<span ...

Transferring MySQL information to web pages using hyperlinks within a table

We have encountered a challenge while working on our game shop website, specifically related to the purchase link. The link is displayed within a mysql table and currently directs users to the same page. Our goal is to optimize efficiency by adding new gam ...

Switch between dropdowns with jQuery

Issue at Hand: In the scenario illustrated below, there is a side navigation bar containing options that reveal a toggled section upon clicking. Specifically, if you select the third item labeled "Dolar" from the menu, a dropdown with three additional cho ...

AngularJS directive for Ionic Leaflet - Utilizing Service to switch tileLayer from side menu

I am currently experimenting with developing an ionic app for the leaflet-angularjs-directive. Unfortunately, there are not many demos available for me to test out. The specific demo I am using is called ionic-leafletjs-map-demo by calendee on GitHub whic ...

Placing an image on a three.js cube using overlay does not function properly

I attempted to superimpose an image onto a cube by utilizing code from GPT chat and Blackbox AI, but in both cases, I encountered a black screen. I saved the code in a file named test.html and tested it on Google Chrome and Opera GX browsers, only to be me ...

the overflow issue with Summernote's dropdown menu

I am currently working on a 2 columns layout within 2 divs that have different margins set. In the left column, I have integrated a bootstrap datetimepicker and summernote. While the datetimepicker dialog overflows outside the internal div, I am wondering ...

When utilizing CKEDITOR, the default TEXTAREA is obscured, and CKEDITOR does not appear

I am trying to incorporate CKEDITOR into my project. I have added the ckeditor script in the footer and replaced all instances of it. <script src="<?= site_url('theme/black/assets/plugins/ckeditor/ckeditor.min.js') ?>" type="text/javasc ...

What technology does Spotify use to ensure that its music streaming service is not easily downloadable?

As I work on a website that will showcase some music tracks, I am aware that downloading music streams can be done through various tools like Chrome's Developer Tools or Firebug. Soundcloud is one such platform where this method of downloading streams ...

Form comments in Bootstrap are causing rows to shift

Currently, I am working on an Angular-powered horizontal form that utilizes various bootstrap components. However, I have encountered an issue with a "Comment field" that is causing the adjacent columns to shift downwards. I initially suspected the problem ...

What could be the reason behind the discrepancy in functionality between two identical jsfiddles?

I am currently in the process of trying to create a map where each subsection will highlight when hovered over. After conducting some research, I came across imagemapster as the recommended method to achieve this functionality. Surprisingly, the first link ...

Creating Dynamic Buttons in Laravel with AJAX and jQuery

Hello, I need help creating dynamic buttons as I am not familiar with ajax or jquery. I currently have a dynamic button running, but I want to create another dynamic button after I add another form. Here is my code. Please take a look at my image, as I am ...

Centering a table horizontally using CSS when its position is set to absolute

I currently have 5 HTML pages with identical code. The code snippet looks like this: <div id='generic'> </div> All 5 pages are linked to an external CSS file that contains the following styling: <style> #generic { ...

Saving users' dark mode preference on my website

I recently implemented a dark mode feature on my website. However, I noticed that when I enable dark mode and then refresh the page or navigate away, the preference resets. To address this issue, I am looking to store the user's preference as a cookie ...

Troubleshooting problems with CSS affecting the placement of HTML <div> elements

Can you help me with this website? I'm trying to make the divs align next to each other with some spacing in between horizontally. Basically, I want them displayed side by side rather than on top of each other. body { background-image:url('wild ...