Using Tailwind CSS to center a NexJS <Image /> component within a modal

In an effort to style my MapBoxGL popup content, I am working on aligning the text above the image to the left and centering the image below within the popup. As shown in the image below, this is currently proving to be a challenge as I transition from using <img> components to next.js <Image /> components and find myself wishing for more examples in the documentation.

https://i.stack.imgur.com/JhQ0U.png

Below is my existing code where I have experimented with various approaches to achieve the desired layout. As far as I understand it, the text should be contained within an outer parent with the class flex flex-col, aligned using either justify-start or items-start, while the parent of the <Image /> should utilize flex justify-center or similar attributes.

I am also struggling to comprehend why my popup appears wider than the content when I only specify w-full in the parent div and provide an exact width for the <Image />.

Any assistance or guidance on this matter would be greatly appreciated!

const popupContent = (
    <div className='test w-full h-full flex flex-col space-y-4'>
        {/*<div className='flex flex-row w-full h-full'>*/}
        <div className='flex flex-col items-start'>
            <Link
                href={`/listings/${listing.id}`}
                className="text-blue-500 hover:underline focus:outline-none">
                <h3>
                    {listing.title}
                </h3>
            </Link>
            <p>{listing.activity_type}</p>
            <p>{listing.mount_type}</p>
        </div>
        {/*<div className="relative w-full h-full">*/}
        <div className="relative w-3/4 h-full flex justify-center">
            {/*<div className="relative w-36 h-64">*/}
            <Image
                src={listing.primary_image_url}
                alt="Listing"
                // fill={true}
                object-Fit='fill'
                // width="100%"
                // className='justify-items-center'

                // className="object-cover w-full h-full"
                width='300'
                height='600'
                /*object-Fit='contain'
                fill={false}
                className='w-full'*/
            />
        </div>
    </div>
);

Answer №1

To fix the problem, simply designate the parent <div> of the image as mx-auto. This snippet translates to margin: 0 auto, effectively centering the div along the vertical axis.

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

Can flex-basis be used with percentage in IE11?

Encountering an issue with flexbox and IE10/11. Trying to utilize min-width/max-width values, but IE11 is not cooperating. Discovered flex-basis and used a percentage value, which functions as intended in Chrome but fails in IE11. Experimented with adding ...

CSS filter for Internet Explorer

Can this CSS class be made to work in Internet Explorer 11? .inactive { filter: contrast(0.5) sepia(100%) hue-rotate(116deg) brightness(1.2) saturate(0.28); } I attempted to implement the SVG grayscale filter but it was unsuccessful, causing issu ...

Ways to conceal overflow at the base of a container while enabling the image to break free from the top of the container

Trying to create a visual effect where an image of a person appears to be partially hidden inside a container, with the bottom part concealed by overflow: hidden. However, I want the top part of the image to extend out of the container. Is there a way to a ...

Utilizing React.js with Material-UI to retrieve data from a table row when clicked

I came across a code snippet for a material table that can handle lists as input and perform pagination, sorting, and filtering on them. The challenge I am facing is figuring out how to extract the data from a row click event and navigate to a new route al ...

Weighing the importance of a multiple-choice quiz

I am faced with the challenge of assessing 25 multiple choice questions, each offering 4 answer choices worth varying points. Additionally, I have 2 free response questions that I wish to score based on the time taken to answer them. My proposed scoring ru ...

Issue with Material UI Textfield not aligning text to the right edge of the field

In my application, I have a field that can be edited based on the state - if isEditing is true, a Textfield component is rendered; otherwise, a disabled Textfield is shown. When the user clicks on the Textfield, a form appears to allow editing of the fiel ...

Is it possible to verify the values of a specific column in the MUI Data Grid?

I'm working with a MUI Data Grid that includes an editable column labeled 'Status', which allows for three possible values - "Accepted", "Ready for Review" and "Update Required". After each cell edit, I want to be able to verify if all rows ...

What is the best way to showcase column data in a React table when the data within the column is an array of objects?

Utilizing a react table to showcase a data table. In the tags column, the goal is to display all tags present in the tags array of objects. Despite several attempts, no success has been achieved yet. Being new to working with tables, any guidance on a more ...

Error encountered when using Symfony 2 command line interface

Just started learning Symfony2 and encountered a problem. I made changes to my CSS and when I try to re-install them in Eclipse shell, I get this error message: 'C:\wamp\www\Symfony' is not recognized as an internal or external ...

Prevent the utilization of <span> tags for line breaks to

When resizing my window to a smaller size, I encountered some unsightly spans that cut into new lines. To demonstrate this issue, I intentionally set the width:20px;. Can this problem be avoided? <link href="https://maxcdn.bootstrapcdn.com/bootstrap/ ...

Removing scrollbar from table in React using Material UI

I successfully created a basic table using react and material UI by following the instructions found at: https://material-ui.com/components/tables/#table. The table is functioning properly, but I am finding the scrollbar to be a bit inconvenient. https:// ...

Tips for deploying your next.js application on AWS and determining the entry file for the server

I am currently working on a project using Next.js. The image below showcases my folder structure. On my local machine, I can successfully run npm build and npm start commands. The build process completes without any issues and the pages display correctly. ...

An error occurs when trying to access the Constants property in the RNCSafeAreaViewConfig object because it is undefined

There was a TypeError: undefined is not an object (evaluating 'RNCSafeAreaViewConfig.Constants') <global> InitialWindowSafeAreaInsets.ts:9:38 loadModuleImplementation require.js:322:6 <global>> index.tsx:6 loadModuleImp ...

What could be causing the 'margin-top' property not to function as expected?

Although I understand the concept of 'margin-collapse', I am puzzled as to why there is no visible 10 px margin on the top of the first box here. The top box, which has the id 'first', should have a 10px margin above it. If this method ...

What could be preventing props from being set as state?

I am facing an issue with setting the state of a child component using props, and I'm also puzzled by why the BarChart component is rendering multiple times in this scenario. What would be considered a better practice: obtaining all store values in t ...

The React useEffect hook runs whenever there is a change in the state

Within my React component, I have the following code snippet (excluding the return statement for relevance): const App = () => { let webSocket = new WebSocket(WS_URL); const [image, setImage] = useState({}); const [bannerName, setBannerName] = use ...

Issue with PrimeFaces radiobutton styles not updating after being clicked programmatically

My setup includes a p:selectOneRadio constructed like this: <p:selectOneRadio id="positionRadio" value="#{employeeBean.empPosition}" converter="#{empPositionConverter}" layout="custom" required="true" requiredMessage="Please select ...

Revamp the current webpage to display attribute values in textual format

As I peruse a webpage, I notice that there is room for improvement in terms of user-friendliness. The page is filled with a list of movie titles, each accompanied by a link to IMDb. However, the IMDB user rating is only visible when hovering over the titl ...

I have implemented the appropriate code to showcase a background color, yet it doesn't seem to be appearing on the screen. Additionally, I am utilizing Sass in this project

Could someone help me understand why the background color is not showing on my website? This is the CSS I am using html { font-size: 100%; -webkit-box-sizing: border-box; box-sizing: border-box; } *, *::before, *::after { -webkit-box-sizi ...

How can I prevent a button from being clicked in React JS if the input field is empty?

React Code Snippet: import { useState } from "react"; export default function IndexPage() { const [text, setText] = useState(""); const autoComplete = (e) => { setText({ value: e.target.value }); }; return ( <fo ...