How can I align a mapped button to appear on the opposite side of the data using Tailwind CSS?

I've been struggling to find a straightforward solution to this issue for a while now.

Let me break it down - I need to display some data on the left side of a post card component with a button located right next to it. Here's an illustration:

The ellipsis icon represents the button, and my goal is to position it on the right side. However, if I use 'absolute' positioning, all buttons are fixed in place even when scrolling.

Below is the code for the two components:

import * as React from 'react';

import { Button } from '@/components/ui/button';
import {
  Card,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from '@/components/ui/card';

import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Ellipsis } from 'lucide-react';
import { PostDialog } from './PostDialog';

// Props interface

export default async function Post({
  user_id,
  avatar_url,
  first_name,
  last_name,
  connections,
  timestamp,
  content,
}: Props) {
  // Rest of the code here...

Here is a snippet of the button component:

'use client';

import * as React from 'react';
import { Ellipsis, Moon, Sun } from 'lucide-react';
import { useTheme } from 'next-themes';

import { Button } from '@/components/ui/button';
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { deletePost } from '@/lib/actions/post.actions';

// Function for handling the dialog

export function PostDialog() {
  // handleDeletePost function
  return (
    // Return statement here...
  );
}

Your attention is greatly appreciated, thank you!

Answer №1

If the parent element has a class of CardDescription with flex properties,

you can easily insert

<div className="flex-1"></div>
in between.

        <CardDescription className="flex w-full flex-row items-center">
          <Avatar className="mr-2">
            <AvatarImage src={avatar_url} />
            <AvatarFallback>NX</AvatarFallback>
          </Avatar>
          {`${first_name} ${last_name} · ${formattedConnects} · ${formattedDate}`}

          <div className="flex-1"></div> // Insert this line here

            <PostDialog /> // This represents the ellipsis button
        </CardDescription>

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

Connect to dynamically generated div on separate page

I am facing an issue with my navigation bar drop down menu that displays event titles fetched from the database. I want users to be able to click on a specific event and have the page scroll to the dynamically generated content for that event. However, it ...

"data-grid in material-ui allows for columns with flexible widths which can be set with a

Is there a way to make the material-ui data-grid (also x-grid) API allow using "flex" and "width" for column definitions? Currently, setting flex to true omits the width, but ideally I would like to be able to set flex: true and width: 250 so that the co ...

Differences in coverage thresholds between global settings and individual file settings when a single file is modified within

Currently, I am utilizing jest to test my react components and HUSKY for pre-commit checks. In my jest.config.js file, I have defined a global threshold coverage as follows: coverageThreshold: { global: { branches: 80, functions: 80, ...

Dimensions of Titles (H1, H2 etc)

I am looking to have a unique background color for my headers from h1 through h6. The width of this background should match the width of the text in the header, along with padding. Currently, the background width is matching the container instead of the te ...

Instructions on file compression using gzip within a React application

After building my react app with create-react-app, I am looking to implement file zipping using gzip. I anticipate successful gzip compression of the files. ...

Efficient method for authentication verification in Next.js using nextauth

What would be the ideal method to verify authentication and display a login component using next auth. Do you prefer directing the user to a login page or simply rendering a login component instead of the requested component? I am trying to write clean c ...

Is it possible to make the v-toolbar-title fixed within a v-navigation-drawer using Vuetify?

Can the <v-toolbar-title> be fixed within a <v-navigation-drawer>? <v-card class="d-inline-block elevation-12"> <v-navigation-drawer hide-overlay permanent stateless height="440" value="true"> <v-toolbar color="whi ...

Update overall font size to be 62% for a consistent look across the website

Recently, I developed a browser extension that adds an overlay button to the LinkedIn website. Everything was running smoothly until I discovered that LinkedIn uses a global font-size: 62,5% that completely messes up my design.. https://i.stack.imgur.com ...

What is the best way to make background SVGs tile seamlessly within the cells of a table?

I am currently dealing with a series of table cells that are filled with various colors and styles. The issue I'm facing is getting the styles to tile properly, as they are not seamlessly continuing from one cell to the next even if they share the sam ...

What is the best way to target elements that have the contentEditable attribute set to true using CSS?

Can someone help me style table cells that have contentEditable set to "true"? I've tried various CSS selectors like td[contenteditable], td[contenteditable=true], and td[contenteditable="true"], but none seem to work. Is there a specific selector for ...

When a UI side makes a restApi call and subsequently closes the UI screen, the expected outcome will occur

Exploring the Interaction Between ReactJS Front End and Java 1.8 Spring Rest API When a call is made from the Front End UI to the REST API on the Backend Server, a delay in receiving the status is observed. What occurs on the server side in this scenario ...

My React application is being loaded by Express regardless of the route I access. What could be causing this issue?

I'm struggling to access the json data located at /species because express always seems to load the react app regardless of the route I use. Can someone help me identify the issue? Here is an excerpt from my server.js file: const app = require(' ...

Building subdocuments schemas/calls for Mongoose in NextJS: A step-by-step guide

I have a requirement to save a single document with multiple subdocuments inside. Specifically, I need to create a Document named 'Scores' with subdocuments that contain 'Player: x, Score: y'. Currently, I am utilizing mongoose in conju ...

In React TS, the function Window.webkitRequestAnimationFrame is not supported

I'm facing an issue where React TS is throwing an error for window.webkitRequestAnimationFrame and window.mozRequestAnimationFrame, assuming that I meant 'requestAnimationFrame'. Any suggestions on what to replace it with? App.tsx import Re ...

Reveal and conceal using CSS animations

I am working on adding animation effects to show and hide HTML elements triggered by a button click. The button toggles a "hide" class to display or hide the element. Check out my code snippet: const toggleButton = document.querySelector('button ...

Prevent the parent component's ripple effect from being activated by the child component

If I have a simple code snippet like the following: <ListItem button={true} > <Typography variant='caption' color='primary'> {value} </Typography> <Button onClick={foo} > Button ...

The function window.alert() has not been implemented in jest

Recently, I crafted a test for my API using jest. In the test file, I included a function that invokes my API: import AuthManager from "../Client/Modules/Auth/AuthManager"; Then, I utilized it in the following manner: test("login api resolv ...

Strategies for avoiding a hover component from causing distortion to its parent component in React

I am encountering an issue with a hover component that is causing distortion in its parent component when displayed. Essentially, I need to prevent the hover component from affecting the layout of its container. Below is the code snippet: Styling for Lang ...

The division is now appearing below the preceding division instead of following it

I am currently encountering an issue that I believe has a simple solution, but I am unable to find it. I have two divs in my code. The first div contains a blurred background image and content, which is working perfectly fine. However, the second div is n ...

What are the best practices for avoiding text wrapping around a DIV?

I have scoured this site extensively, searching for a solution to my problem. What I thought was a simple issue has left me frustrated after hours of trying to figure it out on my own. So, I've finally admitted defeat and turned to seek help... Here& ...