The inline-flex element is experiencing alignment issues

I have 3 elements (with yellow background) that display monetary amounts.

Each counter is animated whenever the amount changes, so there is specific HTML/CSS code for each counter to handle the animation. Changing the underlying CSS will disrupt the animation functionality.

The problem I'm facing is aligning the counter elements with the yellow background properly. I want them to be centered just below the corresponding label for each counter. The labels have a style of padding-bottom:2px;

The first two counters are currently not positioned correctly in relation to the label above.

https://i.sstatic.net/cf1cp.png

The desired alignment of the elements can be seen here:

https://i.sstatic.net/sgdH5.png

This is the basic structure of the DOM (full HTML available at the provided link):

<div id="account_monitor">
    <div class="account-monitor">
        <div class="account-monitor-label">label</div>
        <div class="amount counter" style="height: 21px">value</div>
    </div>
    <div class="account-monitor">
        <div class="account-monitor-label">label</div>
        <div class="amount counter" style="height: 21px">value</div>
    </div>
    <div class="account-monitor">
        <div class="account-monitor-label">label</div>
        <div class="amount counter" style="height: 21px">value</div>
    </div>
</div>

#account_monitor{
    display:flex;
    gap:30px;
    padding:10px;
}

.account-monitor{
    min-width:130px;
    text-align:right;
}

.account-monitor-label{
    padding-bottom:2px;
    text-align:center;
    font-size:11px;
}

.counter{
    display:inline-flex;
    flex-direction:row-reverse;
    align-items:flex-end;
    overflow-y:hidden;
    background:yellow;
}

.amount{
    font-family:arial;
    font-weight:bold;
    font-size:15px;
    text-align:right;
}

You can access the full HTML code through this link:

https://jsfiddle.net/a18Lmpfh/1/

Answer №1

I'm not entirely clear on the specific alignment you're looking to achieve and your ultimate objective here. It seems like it might be beyond the scope of your query and my response.

Solution

Let's review the code snippet below.

I made the following adjustments to .counter-wheel:

  • position: relative;
  • flex-direction: column-reverse; (which I changed to column)

In .counter:

  • align-items:flex-end; is no longer necessary.

Note: I commented out overflow-y:hidden; so you can see how the alignment functions more clearly.

It seems like you might want a different order for the numbers in a column. If this is the case, consider reordering them in your HTML document once the provided solution works for you.

Potential Additional Assistance

Check out this Comprehensive Guide to Flexbox


P.S.: As a general guideline, try to avoid overly rigid positioning of items
(such as top:0px; top:42px; top:189px; etc...)
There's likely a better way to align items according to your requirements.
Such precise positioning is commonly seen when crafting CSS art, which would justify such specificity.

#account_monitor {
  display: flex;
  gap: 30px;
  padding: 10px;
}

.account-monitor {
  min-width: 130px;
  text-align: right;
  border: 1px solid black;
}

.account-monitor-label {
  padding-bottom: 2px;
  text-align: center;
  font-size: 11px;
}

.counter {
  display: inline-flex;
  flex-direction: row-reverse;
  /* align-items:flex-end; */
  /*    overflow-y:hidden; */
  background: yellow;
}

.counter.direction-negative {
  align-items: flex-start;
}

.counter-wheel {
  /* position:relative; */
  display: flex;
   /* flex-direction: column-reverse; */
  flex-direction: column;
  text-align: center;
}

.counter-wheel.direction-negative {
  flex-direction: column;
}

.counter-wheel-void {
  visibility: hidden;
}

.amount {
  font-family: arial;
  font-weight: bold;
  font-size: 15px;
  text-align: right;
}
<div id="account_monitor">
...
</div>

Answer №2

#user_panel{
  display: flex;
  justify-content: space-evenly;
  gap:30px;
  padding:10px;
}
.counter_box{
  background: yellow;
}

It appears that this code snippet is all you need to align the elements correctly.

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

Innovative method for inserting HTML content into the user's clipboard across multiple browsers

If Stackoverflow decided to implement a simple "Copy link to this question" feature. Upon clicking this link on What is your best programmer joke?, it would automatically copy the following HTML code to your clipboard: <a href="https://stackoverflow.co ...

What is the reason the BODY tag does not supersede the properties of the HTML tag?

After applying this css to my html file: html { background-color: red; } body { background-color: yellow; } The page's background actually turns out to be red instead of yellow. Since the body comes after html in the code, it should override t ...

Implementing a full-width search bar within the Bootstrap navbar

I'm trying to create a navbar using Bootstrap 3.7.7 with a logo on the left, links on the right in two rows, and a large search bar in the center. I've managed to align the logo and links correctly, but I'm struggling with sizing the search ...

Is there a way to position right and left divs within a content div on the same top-level?

#textblock{ width: 260px; height: 100%; position; border: 1px solid #999999; padding: 0 5px; float: right; font-size: 95%; background-color: #FEF4CC; } #brevillestandard{ padding: 8px 0 0 5px; ...

Is it just me or does this radio button in IE11 look like a pair of googly eyes?

Recently, I noticed a strange issue on a website I'm working on with radio buttons. While everything looks fine in most browsers, in IE11 some of the radio buttons appear like googly eyes. Could this be a bug specific to IE11 or am I missing something ...

Showcasing Information Using AngularJS from a Json Array

My goal is to present data from a JSON array in a table using the code below. However, all the data is currently being shown in one row instead of each record appearing on separate rows with alternating colors - grey for even rows and white for odd rows. I ...

Boost the figures in an HTML input without affecting the letters

Dealing with a challenge where I need an input field to accept both numbers and letters, but only allow the numbers to be increased or decreased while keeping the letters intact. Essentially, users should not be able to delete the letters. The desired func ...

Avoid having Masonry load all divs simultaneously

I have experience using jQuery Masonry on Tumblr, but now I want to incorporate it into my portfolio website for displaying my photography. However, I'm struggling to find a solution that allows sets of images to load in as the user scrolls to the bot ...

Is it possible to resize background images on Safari?

Encountering an issue with Safari where the background isn't scaling properly. It functions perfectly in Firefox, Chrome, and other browsers, but Safari is presenting a problem. Here's a link to the site: This issue occurs when the resolution is ...

Steps to deactivate a textarea in angularjs based on a selected option's value meeting a specific condition

Hello, I am a newcomer to AngularJS and I am looking to disable the textarea when a specific option is selected from a dropdown menu. I attempted to use ng-disabled="(here my ng-model value)" but unfortunately, it did not work as expected. If creating a ...

"Creating Interactive Slider Bullets: A Guide to Linking them to Their Respective

I can't seem to figure out how to connect my slider bullets to my slider slides. I want bullet 1 to correspond to slide 1, bullet 2 to slide 2, and so on. It should be a simple task, but I'm struggling to make it work. I have set up a basic reset ...

Show a clear box over an HTML table row upon mouseover, without highlighting the row

I'm looking to implement a transparent box, with a button, that surrounds a table row when the user hovers over it. I've searched on Google but all the pages only talk about how to highlight rows on hover. I am currently using JavaScript to add ...

Manage a frame directly from the parent page

I am faced with a situation where I have a web page with two textboxes and a button. Unfortunately, I am unable to alter the contents of this page in any way. My goal is to find a way to automatically populate the first textbox with some text when the pag ...

I'm looking for expert tips on creating a killer WordPress theme design. Any suggestions on the best

Currently in the process of creating a custom Wordpress theme and seeking guidance on implementation. You can view the design outline here. Planning to utilize 960.gs for the css layout. My main concern is how to approach the services section (1, 2, 3...) ...

Unable to capture HTML form input in $_POST[]

I've encountered an unusual issue while transferring data from an email form (HTML5) to ajax/JSON and receiving false in order to prevent redirection to the php script after pressing the submit button. When I include commas between each data paramete ...

What could be causing my line-clamp to malfunction when using a fixed height in the Safari browser?

I have a problem with the design of my episode list on mobile devices. The list has a fixed height, and I am using the line-clamp-2 property for the episode titles that exceed two lines. While everything looks fine on my PC and even when using Dev Tools t ...

What are the steps to installing and utilizing the Chart.js package on your local machine?

I thought installing chart.js on my Raspberry Pi would be a simple task, but I seem to be struggling with it. Due to the nature of my project, I need to have it installed locally rather than relying on an online version. Following the usual steps, I navig ...

Tips for showcasing numerical values using radio buttons

Hello, I am currently working on my project and have a question about calling the ajax function when clicking a button. If(isset($_POST) && ($_POST['GET_PAYMENT'] == '1')) { $totalAmount = $_POST['GET_PAYMENT']; //Total amo ...

Orders in WooCommerce are being mysteriously created with no information provided and stuck in a pending payment state

Are you experiencing the issue of blank orders being generated in WooCommerce with no details and a pending payment status? I am utilizing the WooCommerce plugin along with the Elavon payment gateway, and although everything seems to be set up correctly, t ...

What impact does CSS scaling transform have on the flow of a document?

I'm really confused about the impact of scaling an element using CSS transforms on the document flow. Take a look at this jsbin or this codepen (since jsbin seems to be down), where I have set up the following structure: p{slipsum text} #scaled #s ...