"Utilize Tailwind to effortlessly place a single item at the center

Looking for a way to align a row of items with one item centered in the div and the others positioned on either side while maintaining their original order?

Check out this code snippet:

<div className="flex mx-auto justify-center items-center">
  <Circle selected={selected === ActionOptions.NONE} onClick={e => setSelected(ActionOptions.NONE)} title="None" />
  <Circle selected={selected === ActionOptions.ICON} onClick={e => setSelected(ActionOptions.ICON)} title="Icon">
    {Icon(Icons.CHECK, selected === ActionOptions.ICON ? 'w-20 h-20' : 'w-8 h-8')}
  </Circle>
  <Circle selected={selected === ActionOptions.EMOJI} onClick={e => setSelected(ActionOptions.EMOJI)} title="Emoji">
    {Icon(Icons.SMILE, selected === ActionOptions.EMOJI ? 'w-20 h-20' : 'w-8 h-8')}
  </Circle>
  <Circle selected={selected === ActionOptions.TIMER} onClick={e => setSelected(ActionOptions.TIMER)} title="Timer">
    <ClockIcon className={selected === ActionOptions.TIMER ? 'w-20 h-20' : 'w-8 h-8'} />
  </Circle>
</div>

function Circle({
  selected,
  children,
  onClick,
  title,
}: PropsWithChildren<{ selected: boolean; onClick: (e) => void; title: string }>) {
  return (
    <div className="flex flex-col items-center justify-center cursor-pointer">
      <div
        onClick={onClick}
        className={`rounded-full flex justify-center items-center ${
          selected ? 'w-32 h-32 border-4' : 'w-14 h-14 border-2'
        } mx-2  border-white bg-white/10`}
      >
        {children}
      </div>
      <span className="text-xs">{title}</span>
    </div>
  );
}

Does anyone have suggestions on how to achieve this layout design?

Answer №1

It seems like there may be some confusion about your request, but one possible solution could involve adjusting the flex-order in the following way:

const Shapes = [
  { name: 'Square', size: BoxOptions.SMALL, alignment: 1 },
  { name: 'Circle', size: BoxOptions.MEDIUM, alignment: 1 },
  { name: 'Triangle', size: BoxOptions.LARGE, alignment: 3 },
  { name: 'Hexagon', size: BoxOptions.XLARGE, alignment: 3 },
]

export default function Container() {
  const [selectedShape, setSelectedShape] = useState<BoxOptions>();

  return (
    <div className="flex mx-auto justify-center items-center transition-all duration-1000">
      {Shapes.map(({ name, size, alignment }) => {
        return (
          <Shape
            key={name}
            selected={selectedShape === size}
            onClick={() => setSelectedShape(size)}
            name={name}
            alignment={alignment}
          >
            <div>{size}</div>
          </Shape>
        );
      })}
    </div>
  );
}

export function Shape({ selected, children, onClick, name, alignment }) {
  return (
    <div
      className={`item flex flex-col items-center justify-center cursor-pointer ${
        selected ? `order-2` : `order-${alignment}`
      }`}
    >
      <div
        onClick={onClick}
        className={`rounded-full flex justify-center items-center ${
          selected ? 'w-32 h-32 border-4' : 'w-14 h-14 border-2'
        } mx-2  border-black bg-white/10`}
      >
        {children}
      </div>
      <span className="text-xs">{name}</span>
    </div>
  );
}

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 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 ...

Is there a way to programmatically remove row selection in a materialUI table?

Utilizing a materialui table, I am able to display a list of items in the following manner: <Table selectable={true} onRowSelection={(index) => this.onRowSelection(index)} className="searchable-table"> <TableHeader adjustForCheckbox={false ...

There was an issue with the SidebarController function being undefined, as it was expected to be a function

I'm encountering two issues with my demo: Error: [ng:areq] Argument 'SidebarController' is not a function, received undefined http://errors.angularjs.org/1.2.26/ng/areq?p0=SidebarController&p1=not%20aNaNunction%2C%20got%20undefined ...

Expanding the flexbox container to accommodate additional divs when they are added

I'm encountering an issue with a div not extending properly, causing two other divs to overlap. I've managed to position the divs correctly, but now I need the "100% all beef weenies" text to appear below the items. Any suggestions on how to achi ...

Styling problem arises on IOS devices due to rounded corners affecting select box

The dropdown menu I am using to "sort products" on our WordPress website is causing some styling issues specifically on IOS devices. I would like the dropdown menu to have rounded corners. It seems to display rounded corners on IOS, but it still shows the ...

Creating a new array set by utilizing the map method

How can I filter and return a new array using the map function based on 2 conditions: The array must not be empty The role should be "moderator" This is an example of my initial response: Below is a React function that utilizes the map method to proces ...

Integrate the element offset into jQuery's offset calculations

I'm new to utilizing jQuery and currently facing a challenge in determining the correct offset for a specific div element within the body. My goal is to make this particular div stick to its position as I scroll down past its designated top offset. A ...

Issue with Custom Dropdown input not triggering blur event

I've been working on a custom dropup component and have encountered some strange issues with it. The main problem is the blur event not firing when clicking outside of the input field. My goal is to hide the options elements on blur, reset the compon ...

Switching ng-Idle countdown time from seconds to minutes is possible by adjusting the configuration settings

I have implemented ng-idle in my application, where the warning popup appears after 10 seconds with the message: "Your session will be close in 10 seconds" However, I need to change this to minutes. The session should be closed in 5 minutes instead. How ...

How to eliminate arrow icons from Bootstrap Carousel

Welcome to my blog at www.lowcoupling.com. I am trying to hide the left and right arrows on the bootstrap carousel, but my code doesn't seem to be working. Here is what I have tried: .glyphicon-chevron-right{ display:none; } (I also tried the ...

Firefox experiencing issues with loading background images

The website URL: 4genderjustice.org While this layout functions properly in most browsers, notably Firefox seems to be causing issues. The question remains: why is it not functioning as expected in Firefox? The background images are configured like so: ...

Troubles with Bootstrap's column functionality causing issues

Trying to create a menu using Bootstrap, but experiencing issues with the 'col' class not working correctly. Here is the sample HTML code provided: <div class="logo col"> <a href="index.html"><img src="C ...

Troubleshooting Floating Divs in ExtJs TreePanel Component

I am currently utilizing the treepanel object in ExtJs and I am trying to implement two divs side by side within the treepanel items. Is it feasible to have one of them set with a fluid width and the other with an auto width? Despite my HTML and CSS codes ...

Embedding a TypeScript React component within another one

Currently, I'm facing an issue with nesting a TypeScript React component within another one, as it's causing type errors. The problem seems to be that all props need to be added to the parent interface? Is there a way to handle this situation wi ...

Issue with utilizing the useDisclouse() function in Chakra UI within a forEach iteration

Is there a way to use useDisclouse() in Chakra with a button within a forEach loop? Whenever I click on a Button, it seems to trigger all Buttons. const {isOpen:isOpenEdit,onOpen:onOpenEdit,onClose:onCloseEdit} = useDisclosure(); ... ...

Utilizing Array properties within a JavaScript class

I'm encountering some issues with the first property in my JavaScript class. Specifically, I'm trying to manage tokens using Firebase in a project that involves node.js and react.js. export default class NoNotificationResource { allTokens = ...

Hidden menu does not work with Jquery

As I work on creating a responsive website, I am faced with the challenge of implementing a menu that only opens on mobile devices when clicked. I came across some code on Stackoverflow that I thought would solve this issue for me. However, I seem to be en ...

Ways to troubleshoot issues with installing expo-cli

I'm facing an issue while trying to install expo-cli using npm. Even though I successfully installed it with yarn, the system still shows 'expo is not recognized as an internal or external command'. When running 'npm install expo-cli - ...

How should one correctly align various classes in a cascading manner within CSS?

Here is an interesting challenge - I want each of these buttons to have their background image change when hovered over. However, I'm struggling with the class setup in my code. I've been trying to understand how to distinguish between divs and c ...

The customized styling for Material Angular does not seem to properly apply to <md-card> elements within ui-views

I am trying to achieve a specific effect on the ui-views <md-card id="sidebar" flex="20" class="sche-card" layout-padding="true"> <div ui-view="card" autoscroll="false"></div> </md-card> However, I am facing an issue where the car ...