Tips for aligning flex items based on the previous item in a flex container

Place 'text1' beneath the number 1 (so that the 't' character is under the 1), and 'text2' beneath the number 5 (with the '2' character under the number 5)

This should be done dynamically to adjust to a varying number of elements. The goal is to display content under the first and last corresponding numbers. Using Angular, I have access to the count of numbers in the component. The spacing between the numbers remains constant and does not change. If the text is too long, it can be wrapped within a specified maximum width.

An example has been provided below to demonstrate how this functionality should work, but it needs to be customized to accommodate different arrays of numbers

    .container {
      display: flex;
      flex-direction: column;
      width: 300px;
    }

    .container .numbers {
      display: flex;
      justify-content: center; 
      gap: 10px;
    }

    .container .numbers span {
      width: 30px;
      border: solid;
    }

    .container .text {
      display: flex;
      justify-content: center;
      gap: 144px;
    }
    
    span {
      border: solid;
    }
<div class='container'>
  <div class='numbers'>
    <span>1</span>
    <span>2</span>
    <span>3</span>
    <span>4</span>
    <span>5</span>
  </div>
  <div class='text'>
    <span>text1</span>
    <span>text2</span>
  </div>
</div>

Answer №1

I think you're trying to create a rating system...

To achieve the desired effect, simply update the justify-content: center; in both the .container .text and .container .number classes to justify-content: space-between;. This way, even if the numbers increase, text1 and text2 will remain aligned in their respective positions. You can also experiment with adjusting the widths for further customization.

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

Unable to retrieve the value of an option element within a select tag using Selenium

I am having difficulty in choosing an option from a dropdown menu while using Selenium with Python. Displaying below is the HTML code snippet: <select class="hm-input hm-dropdown" type="text" id="HME-10-widget_calendar_1" ...

Resetting JavaScript Input based on certain conditions

I have been attempting to reset the input fields for a login when the loginDiv display is set to none, but unfortunately it does not seem to be working as expected. My goal is for the input fields to reset whenever the login button is clicked and the logi ...

error occurs when trying to update angular-cli

XYZ$ sudo npm install -g angular-cli@latest npm WARN deprecated <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="62010e07150c01024d030c0930514f514f514c020415014f53594f52">[email protected]</a>: angular-cli has been ...

What is the process for submitting a record to a table following the activation of a JavaScript link or button

I am working on creating a like-unlike button below each post for registered users to interact with. I have successfully created the button itself, but now I need to figure out how to store records when a user clicks the button. My idea is to utilize a tab ...

Troubleshooting Safari compatibility with CSS transitions: a first attempt

Greetings everyone, I am a complete beginner here so please bear with me. After looking at some examples, I have managed to create a start/stop slowdown feature. Here is the JSFiddle link for reference .small-wheel, .big-wheel{ transition: all 2s ease ...

Position the text alongside the thumbnail rather than in the center

In the current setup, my username text is positioned in the center of the view. I want to reconfigure it so that it displays directly to the right of the thumbnail. However, removing the alignItems: 'center', property from the item disrupts the e ...

Creating a responsive navigation bar with Bootstrap步 is simple and effective

Thank you for taking the time to review my current code. The main issue I am encountering pertains to the responsiveness of the navbar. Whenever I zoom in or out, certain elements tend to lose their alignment and aesthetic appeal. Specifically, the navbar ...

Improving the layout and size of text within input fields

How can we adjust the input text positioning to the right so it's not directly against the edge? Is there a way to move 'searching' 5px to the right? ...

Can someone assist me in successfully incorporating a web font into a template?

After downloading a Wordpress template, I found the font used for h1 and h2 text to be difficult to read due to its slim design - Century Gothic. However, I prefer using Noteworthy, a font available on my Mac. I converted Noteworthy from OTF to web-font st ...

The cursor image fails to function when entering a specific area within the image

I have implemented a custom cursor using the code snippet below. $("div").css('cursor','url(../graphics/system/mybg.cur),auto'); However, I am experiencing an issue where the cursor reverts to the default pointer when hovering over a ...

Modify the base URL with JavaScript

Is it possible to dynamically change the href using JavaScript? I attempted to make this change with the code below in my HTML file, but unfortunately, it didn't work: <base href="/" /> <script type="text/javascript"> function setbasehr ...

Interacting between two occurrences of the identical Angular component

Within a Razor view, I include an angular component: <my-widget id="myWidget" isfullscreen="false" class="some-class"></my-widget> Upon clicking the 'Popup' button, a popup appears in an iframe and the s ...

unable to clear form fields after ajax submission issue persisting

After submitting via ajax, I am having trouble clearing form fields. Any help in checking my code and providing suggestions would be greatly appreciated. Here is the code snippet: jQuery(document).on('click', '.um-message-send:not(.disabled ...

Images in CSS not copied to the output directory when using Webpack

Using Webpack to bundle various javascript and css files on a website includes bundling bootstrap.css and chosen.css as part of the bundles. To achieve this, there is a main.js file serving as an entry point for importing all necessary files. The process i ...

Add the item to the array and then use the *ngFor directive to iterate

Whenever the addRoom button is clicked, I want to add an object to an array. The problem is that the data in my array keeps getting repeated. Please excuse any language errors in my explanation. Feel free to ask me for clarification in the comments below. ...

Furnish an item for a particular service

I am currently attempting to utilize a service created by another individual (github). This particular service requires a configuration to be passed to it. As stated in the repository: To configure Neo4jSettings in your bootstrap: provide('Neo4jSet ...

Troubleshooting: The reason behind my struggles in locating elements through xpath

There is a specific element that I am trying to locate via XPath. It looks like this: <span ng-click="openOrderAddPopup()" class="active g-button-style g-text-button g-padding-5px g-margin-right-10px ng-binding"> <i class=&quo ...

How about: "Loop through an array of objects fetched from an observable and initiate an HTTP request for each object's ID?"

Using Angular routing, in the component's ngOnInit method, I retrieve a genre ID through an observable. Within this observable, a service method is called that makes an HTTP request. this.movies: Movie[]; ngOnInit() { this.route.paramMap.sub ...

What is the best way to iterate through a list of values stored in a form group's array?

I am facing an issue with my form group declaration. Below is the code snippet: this.secondFormGroup = this._formBuilder.group({ nested: this._formBuilder.group({ arr1: [], arr2: [], arr3: [], arr4: [] }), }) After the user fi ...

Angular - utilizing subscription within a for-loop to determine completion

Below is the code I am using to generate sticky notes: update() { this.tab3Service.updateStickyNote(this.stickyNoteUserConnection.stickyNote).subscribe(response => { const updatedStickyNote: StickyNote = response; for(let i = 0; i < this.stickyNo ...