Align list item span to the center

I have encountered an issue with creating a match list using li and ul tags. Despite applying the center span to a fixed width and the team spans to the remaining space, the widths still appear different. How can I ensure that the team spans have the same width and the time span is always centered?

.matches {

    width: 100%;

}

.match-list {
    
padding: 0px;
display: block;
list-style-type: disc;


    
}

.list-item {
  list-style: none;
  margin-bottom: 10px;
  display:flex;
  direction:row;
  border-bottom: 1px dotted #DDDDDD;
  padding-bottom: 10px;
}

.list-item .image-col {
     order:1;
    width: 50px;

    float: left;
    
}

.list-item .empty-col {
    order:5;
    width: 50px;
    text-align: right;
    float: left;
    
}

.list-item .time-col {
 order:3; 
    width: 50px;
    text-align: center;
    float: left;
    
}

.list-item .first-team {
order:1;
flex-grow:2;
text-align: right;
float: left;
background-color: #343533;
}

.list-item .second-team {
order:4;
flex-grow:2;
float: left;
text-align: left;
  background-color: #444444;
}
<div class="matches">
    <ul class="match-list">
        <li class="list-item">
            <span class="image-col">img</span>
            <span class="first-team">First team teeest</span>
            <span class="time-col">12:00</span>
            <span class="second-team">Second team</span>
            <span class="empty-col">lol</span>
        </li>
        
                <li class="list-item">
            <span class="image-col">img</span>
            <span class="first-team">First team</span>
            <span class="time-col">12:00</span>
            <span class="second-team">Second team</span>
            <span class="empty-col">lol</span>
        </li>
        
        
    </ul>
    
    
</div>

Answer №1

When you specified a flex-grow without a flex-basis, the elements grew from a different basis, their natural width.

.matches {
    width: 100%;
}

.match-list {
    padding: 0px;
    display: block;
    list-style-type: disc;
}

.list-item {
    list-style: none;
    margin-bottom: 10px;
    display:flex;
    direction:row;
    border-bottom: 1px dotted #DDDDDD;
    padding-bottom: 10px;
}

.list-item .image-col {
    order:1;
    width: 50px;
    float: left;
}

.list-item .empty-col {
    order:5;
    width: 50px;
    text-align: right;
    float: left;
}

.list-item .time-col {
    order:3; 
    width: 50px;
    text-align: center;
    float: left;
}

.list-item .first-team {
    order:1;
    flex-grow:2;
    text-align: right;
    float: left;
    background-color: #343533;
    flex-basis: 0;
}

.list-item .second-team {
    order:4;
    flex-grow:2;
    flex-basis: 0;
    float: left;
    text-align: left;
    background-color: #444444;
}
<div class="matches">
    <ul class="match-list">
        <li class="list-item">
            <span class="image-col">img</span>
            <span class="first-team">First team teeest</span>
            <span class="time-col">12:00</span>
            <span class="second-team">Second team</span>
            <span class="empty-col">lol</span>
        </li>
        
        <li class="list-item">
            <span class="image-col">img</span>
            <span class="first-team">First team</span>
            <span class="time-col">12:00</span>
            <span class="second-team">Second team</span>
            <span class="empty-col">lol</span>
        </li>
    </ul>
</div>

Answer №2

Are you satisfied with this layout?

            .matches {

    width: 100%;

}

.match-list {
    
padding: 0px;
display: block;
list-style-type: disc;


    
}

.list-item {
  list-style: none;
  margin-bottom: 10px;
  display:flex;
  direction:row;
  border-bottom: 1px dotted #DDDDDD;
  padding-bottom: 10px;
}

.list-item .image-col {
     order:1;
    width: 50px;

    float: left;
    
}

.list-item .empty-col {
    order:5;
    width: 50px;
    text-align: right;
    float: left;
    
}

.list-item .time-col {
 order:3; 
    width: 50px;
    text-align: center;
    float: left;
    
}

.list-item .first-team {
order:1;
flex-grow:2;
text-align: right;
float: left;
background-color: #343533;
}

.list-item .second-team {
order:4;
flex-grow:2;
float: left;
text-align: left;
  background-color: #444444;
}
.list-item span{color: white;width:40%}
.list-item .time-col{color:gray}
<div class="matches">
    <ul class="match-list">
        <li class="list-item">
            <span class="image-col">img</span>
            <span class="first-team">First team teeest</span>
            <span class="time-col">12:00</span>
            <span class="second-team">Second team</span>
            <span class="empty-col">lol</span>
        </li>
        
                <li class="list-item">
            <span class="image-col">img</span>
            <span class="first-team">First team</span>
            <span class="time-col">12:00</span>
            <span class="second-team">Second team</span>
            <span class="empty-col">lol</span>
        </li>
        
        
    </ul>
    

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

Using Bootstrap multiselect, you can easily control the display of a second menu based on the selection in the first menu

On my website, I am working with two menus. When I select Abon from the first menu, it should display all li elements under the Abon optgroup (Abon-1, Abon-2). If I uncheck block in the second menu, those elements should disappear. The code consists of Sel ...

Can a small white pop-up be triggered by clicking a button?

While exploring the website , I noticed that clicking on Availability Zones opens a small window with text on the right side of the page. Is it possible to achieve a similar feature on a leaflet map without using JavaScript? This functionality would be tri ...

Having issues with my CodePen React code and its ability to display my gradient background

I will provide detailed descriptions to help explain my issue. Link to CodePen: https://codepen.io/Yosharu/pen/morErw The problem I am facing is that my background (and some other CSS elements) are not loading properly in my code, resulting in a white bac ...

Having trouble aligning two divs horizontally on the same line in Bootstrap 4

I am facing an issue with my HTML code where I have two div elements that are supposed to be horizontally aligned, but the second div is appearing underneath the first one. To fix this, I tried using bootstrap classes for alignment. <div class="c ...

We are creating a table in JavaScript and mistakenly adding an unnecessary tbody

I am currently utilizing a combination of plain JavaScript and Jquery in order to dynamically generate a table. The issue arises when I attempt to use a for loop to iterate through the data obtained from an Ajax request, as it fails to create new rows. To ...

The HTML iframe is displaying blank content

I'm trying to embed a webpage within another webpage using an iframe. I attempted to do so with this simple code: <iframe src="http://edition.cnn.com/" id="i_frame"></iframe> JSFIDDLE However, nothing is displaying. Any thoughts on why ...

What is the best way to set a specific image as the initial image when loading 'SpriteSpin'?

I'm currently working on creating a 360-degree view using the SpriteSpin API. Everything is functioning as expected, but I have an additional request. I need to specify a specific image to be the initial landing image when the page loads. The landing ...

Convert Jupyter notebook to an executable html file

Looking for a way to export a Jupyter notebook in HTML to get an executable version? Currently, I upload the notebook to a git repository and use binder to obtain its executable form. However, I want to directly upload the notebook to my website without ha ...

Align the first div in the center horizontally alongside the other inline-block div

There are two div elements styled with display: inline-block; to place them on the same line. I am looking to horizontally center the first div and position the second div just to the right of it. Similar to the layout below: page text page text page te ...

What is the best way to adjust the size of an image within a div element using HTML?

I've created a Carousel with 5 images to display. However, I'm having an issue where only the image is showing up, and I want the text and button to appear below it. Here's how the nature image is currently displaying: What I want is for th ...

What is the best way to align a button with a title on the right side of a page?

Is it possible to align my button to the top right, at the same height as the title in my design? Here is an example: view image here This is what I have achieved so far: view image here I suspect there may be an issue with my divs. The button doesn&a ...

Cut off a string from the start

I'm using the text-overflow: ellipsis property in a div to shorten lengthy text values. Since there is no white space in the URL, I want to prevent the overflow from increasing the width of the div. What I want to achieve is to display the following: ...

Leveraging multiple ">" CSS selectors

Here is the HTML code to style: <table id="my-table"> <tr> <td> I would like to customize this </td> <td> <table> <tr> <td> Not looking to customize t ...

Is a CSS-only autoexpanding label possible within a list?

I am interested in having all the labels automatically expand to the size of the widest one. Below is the HTML structure: <div class="body"> <ul class="list"> <li> <span> <label>condition</label> ...

Bursting at the seams: concealed issues

I am currently facing an issue with a facebook like button placed in the caption section of a slideshow div, located at the far bottom right corner. The problem arises when the 'post to wall' prompt pops up below the like button, but is cut off d ...

Can SCSS be used in conjunction with Less in a backwards compatible manner?

Can scss be considered backwards compatible with less? Personally, I have my doubts. One key difference is that while less uses '@' to prefix variables, scss opts for '$'. Changing the variable prefix might not be enough, as there are l ...

Stop images from appearing transparent when placed inside a transparent div

My issue is clearly visible in this image: The div element is transparent and affecting the images inside it. Below is my HTML code: <div id="cselect" style="position: absolute; top: 99px; left: 37px; display: block;"> <div class="cnvptr"> ...

Creating a form that can identify both letters and numbers using JavaScript

Is it possible to create an <input> field that can recognize both letters and numbers while disregarding spaces and capitalization? Here is my current progress, aiming for the feedback to display as "right" when 9 H 6 U 8 f is entered in the field, ...

AngularJS allows you to toggle the visibility of a div at set intervals, creating

I am struggling with the task of showing and hiding a div that serves as an alert for my application. Currently, I am using $interval to create a continuous show and hide action on the div. However, what I aim for is to have the DIV visible for X amount o ...

Repurposing JavaScript objects after clearing their contents

Here's my issue. I'm working with a Javascript object, initialized as var stack = {}. This object is used in my project to store arrays. When the user clicks the add button, an array is added to the object with a specific key that is inputted in ...