Ensure that the final item in the flexbox is centered, rather than the initial one

Is there a way to align the last element in the center without affecting the first one?

The code snippet below demonstrates how this can be achieved:

.impress-profiles {
    .flex() //less mixin for flexbox
    flex-flow: row wrap;
    justify-content: center;

    li {
        flex-shrink: 0;
    }
}

The corresponding HTML code is a simple list as shown below:

<ul class="impress-profiles">
    <li>...</li>
    <li>...</li>
    <li>...</li>
</ul>

This is what the layout looks like:

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

Answer №1

To center the last item in a list, you can apply margin: 0 auto; to it.

.special-list {
    .displayFlex() //scss mixin for flexbox
    flex-flow: row wrap;
    justify-content: center;

    li {
        flex-shrink: 0;
    }

    li:last-child {
        margin: 0 auto;
    }
}

Check out this example on JSFiddle: https://jsfiddle.net/abc123/

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

Trouble with applying position absolute to pseudo element in Firefox version 12 and higher

I seem to be running into an issue with the positioning of a pseudo element in Firefox version 12 or higher (possibly even earlier versions). Despite having position:relative on the anchor tag, the element appears to be relative to the entire page. Any ide ...

Creating an SVG element that adjusts to the size of its parent container: tips and tricks

I'm attempting to achieve the following: Displaying an SVG square (with a 1:1 aspect ratio) inside a div element. When the width of the div is greater than its height, the square should adjust to fit within the container based on the height (red box ...

developing a responsive website that can effortlessly adjust to any screen size, whether big or small

As I develop a website on my 13-inch MacBook, I encountered an issue with the background image being too large for my screen. Is there a way to maintain the aspect ratio while designing so that it looks consistent when scaled up or down? I tried using the ...

"Developing with create-react-app can be frustrating due to its sluggish performance and tendency

As I delve into the world of React, my lack of experience becomes evident. Each time I attempt to start a new project using the create-react-app command, I find myself waiting for what seems like an eternity. Discovering CodeSandbox was a game-changer - ...

The element is not displaying the correct width percentage value

When I try to style an element in HTML using Sass, setting the width using percentages doesn't seem to work. I wonder if this issue is related to me using "content-max" to set the parent element's width and height? Here is a simplified version ...

What is the best way to resize a div to fit its content if 'clear:both' and 'float:left' are not working as desired?

I've been struggling to find a solution for an issue with my HTML. I have three 'divs' that need to display different information in their own line, enclosed in a parent element with a centered border. Despite trying solutions like inline-bl ...

Guide to choosing and unchoosing a div / button using angularJs

I am attempting to create a functionality where items are displayed in a div instead of a list. When an item is clicked, the background color of the div changes and the item is added to a column. Clicking on the item again will revert it back to its origin ...

Find the div element that wraps around the currently selected radio button

Take a look at this code snippet: <div class="paymentOption"> <input type="radio" name="paymentOption" value="1" /> <span class="marginLeft10">1-time payment using a different credit card</span> </div> Is it feasible ...

elevate and descend div

I am looking to create a div with interchangeable content items. After doing some research on Google, I came across this helpful link: http://jsfiddle.net/RrbzM/4/. In the fiddle, each number can be clicked to move the content up and down. However, I only ...

Developing an animated feature that displays a dynamic count up to the current size of the browser window

I have a script that's able to determine the height and width of my browser window. However, I am facing a challenge in creating a way for these dimensions to count up from zero to their current values upon loading. The desired functionality would be ...

In Internet Explorer 7, there appears to be a white box that covers up the content on our website beyond a

I'm feeling stuck and frustrated trying to solve this issue. I have a Mac and no access to an IE7 machine, so I've been using browserlab (which is slow) to make any changes and see if they help. Unfortunately, I haven't been able to fix the ...

The Bootstrap data-target and aria-controls attributes are failing to activate the designated id element

I have implemented various elements to toggle the display of information on my HTML website. While I've successfully created buttons, nav-tabs, and modals, clicking on the trigger element doesn't reveal the associated content. I've even doub ...

Ways to bypass or replace the overflow:hidden property of the parent container even when unable to modify its CSS styling

I'm encountering an issue. I'm currently developing a widget to showcase certain elements on a webpage. I have created a fiddle, please take a look: .wrapper { width: 300px; display: block; position: relative; overflow: hidden; back ...

"Restricting the height of a DIV container based on the size

Struggling with CSS as I try to get my #wrapper DIV to adjust its size based on its contents. I've experimented with 100% height and min-height, but nothing seems to work. Could it be related to relative versus absolute positioning? Here's a snip ...

Does the Android 4.3 Internet browser not support @font-face declarations?

After my Samsung Galaxy S3 phone recently updated from Android 4.1.3 to Android 4.3, I noticed that some of the websites I designed are not displaying the fonts correctly. These sites were tested on the Android internet browser and use @font-face. How can ...

What is required to create a basic application that can function offline while featuring an HTML/CSS user interface?

Newbie inquiry: I am interested in creating a small application that can run offline on a desktop computer. The amount of data to be saved is minimal, so I have the option to use a file or some type of database. However, my main question is: What languag ...

Incorporating shadow effects along the right border of alternating table cells: a step-by-step guide

How can I set a proper shadow border for alternating td elements in a table? I've been experimenting with the code below. While the shadow effects work, they are getting cut off at each td junction. Can anyone provide assistance? Here is my table: ...

Achieve a bottom alignment in Bootstrap without using columns

I am looking to align the elements within a div to the end, but when I use Bootstrap's d-flex and align-items-end classes, it causes the elements to be split into columns. This is not the desired outcome. How can I resolve this issue? <link href ...

Adjust item size and move them into the panel

I am looking to create a panel that arranges items in a specific layout shown here: https://i.stack.imgur.com/qw3lS.png Below is the code I have attempted so far: import React, { useCallback, useEffect } from "react"; import { Box, Grid, Tab, T ...

Tips for adding style to a group of SVG elements:

I currently have an array of .svg icons, each with unique properties that I need to customize: <svg width="24" height="24" viewBox="0 0 24 24"> ... </svg> import styled from 'styled-components'; import Github from 'assets/git ...