"Having trouble getting `justify-between` to work in a tailwind CSS on an absolute

I'm currently using Tailwind CSS and I'm trying to position my navbar on top of an image. The image is set in a relative position and the navbar is set in an absolute position. Surprisingly, when the navbar is not set in the absolute position, I am able to make the items justify between. However, when it is inside an "absolute" position, it doesn't work as expected.

Here is a snippet of my code:

    <div className='container max-w-full'>
        <div className='h-screen w-full'>
            <div className="relative w-max inset-0 -z-1">
                <Image 
                    src= {banner} 
                    alt="ic"
                    sizes="100vw"                       
                    className="w-full h-auto opacity-50"
                />
            </div>
            <h2 className='absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 text-slate-700'>
                <div className='flex flex-col space-y-5 justify-center items-center text-center'>
                    <div className='text-7xl font-bold'>Title</div>
                    <div className='text-7xl'>Title text</div>
                    <button className='text-2xl bg-sky-700 text-white px-10 py-5 rounded-lg'>Explore</button>
                </div>
            </h2>
            <p className='absolute top-0'>
                <div className='flex justify-between'>
                    <div className='text-3xl p-2'>Logo</div>
                    <div className='text-3xl p-2'>Menu</div>
                    <div className='text-3xl p-2'>Menu2</div>
                </div>
            </p>
        </div>
    </div>        

The issue lies with the part where the navbar is set in the absolute position:

                <p className='absolute top-0'>
                <div className='flex justify-center items-center text-center'>
                    <div className='text-3xl p-2'>Logo</div>
                    <div className='text-3xl p-2'>Menu</div>
                    <div className='text-3xl p-2'>Menu2</div>
                </div>
            </p>

It seems like the items are not being justified between, instead, they all stay at the top-left position. Any help on this issue would be greatly appreciated. Thank you!

Answer №1

When applying the position: absolute style to an element, it is essential to define its width to ensure that the child elements have enough space to maintain the desired layout.

Keep in mind that using a div within a p tag is not valid HTML, so I substituted it with a nav element.

 <nav className='w-full absolute top-0'>
     <div className='flex justify-between items-center text-center'>
            <div className='text-3xl p-2'>
               Logo
            </div>
            <div className='text-3xl p-2'>
               Menu
            </div>
            <div className='text-3xl p-2'>
               Menu2
            </div>
     </div>
 </nav>

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

Unable to Trigger Click Event on Div Element in Angular 9

Take a look at my HTML code snippet <mat-grid-list cols="3" rowHeight="150px"> <mat-grid-tile *ngFor="let tile of tiles;index as j;" [colspan]="tile.cols" [rowspan]="tile.rows" ...

Preventing scrolling in jQuery UI Draggable when using flexbox

In my project, I am looking to organize a container using jQuery UI draggable/droppable feature. Since the elements in my list are arranged in a straight horizontal line, I have utilized display: flex. This arrangement works well when adding new items to ...

What is the complete list of features that ColorTranslator.FromHtml() supports and what are the reasons behind its departure from traditional CSS color interpretation guidelines

I'm looking to enhance an API by providing users with the ability to specify the color of something. I want it to accept various representations of colors, such as hex codes and CSS colors. Initially, I thought that ColorTranslator.FromHtml() would fu ...

Transition from mouse wheel scroll to page scroll not functioning properly when overflow is enabled

The website has a fixed element that uses overflow:auto. Users can scroll this element by positioning the mouse over it. However, once the element reaches the end of its scroll, the page does not seamlessly take over the scrolling. Instead, there is about ...

Tips for aligning a Bootstrap row in the center

I need some help centering this temperature converter on the page. I've tried adjusting the columns and rows, but the alignment is still off. Here is a screenshot for reference: https://i.sstatic.net/xR8rA.png Below is the code I am using: < ...

What is the best way to host a Next.js App on Netlify?

I've encountered a problem with my Next.js app deployment. Following a tutorial from netlify's blog on implementing Server-side Rendering for Next.js using netlify, I managed to build the app successfully but it's not functioning as expected ...

What are some strategies for customizing the appearance of child components within a parent component?

I have a scenario where I am using parent and child components. When I use the HTML in another component, I also apply my CSS. For example, in my parent component: HTML <div class="chips"> <p class="tags">Tag 1</p&g ...

css3 animation keyframes timing function is exclusive to chrome

After creating a preloader animation using CSS3, I noticed that it only functions properly on Chrome. On all other browsers, the animation works, but the timing for the middle bar is delayed, throwing off the entire animation. I'm puzzled because all ...

I was surprised by how Await behaved in if-else statements, it was not what

let metadata = []; allNFTs.map(async (e) => { if (e.metadata) { metadata.push(JSON.parse(e.metadata).attributes); } else { let config = { method: "get", url: `http://localhost:3000/api/fetch ...

How can I eliminate the error message "WARNING: no homepage content found in homepage.md"?

Starting my journey with KSS utilizing Keith Grant's CSS in Depth as a guide. In section 10.1.4, the author suggests: To begin, create a new markdown file named homepage.md inside the css directory. This file will serve as an introduction to the patt ...

Switching the navigation menu using jQuery

I am looking to create a mobile menu that opens a list of options with a toggle feature. I want the menu list to appear when the toggle is clicked, and I also want to disable scrolling for the body. When the toggle menu is clicked again, the list should c ...

Toggle the visibility of a div element and smoothly scroll to it on the page

Upon clicking the form, my goal is to show or hide it and scroll down to view the form. The current code I have in place seems to work after the first click. However, on the initial click, it shows the form but fails to scroll down. Any insights on what I ...

What is the best way to maximize vertical space in every element on a page?

How can I achieve a layout similar to the image shown? I want three distinct sections: a navigation bar fixed at the bottom, and left and right sides each taking up 50% of the screen. Additionally, all boxes on the left side should have equal height. I am ...

Unshrinkable item causing multiple lines text-overflow in a flexbox layout

My goal is to achieve the following design: https://i.stack.imgur.com/YLUtN.png Currently, I have attempted the following approach (although it doesn't fully meet my requirements): .parent { max-height: 40px; display: flex; flex-wrap: wrap; ...

Learning how to utilize various types of buttons in C# and ASP.NET with this

I was following this tutorial: I like everything the same except I want to make the following change: <section> <a rel="external" href="#button" id="button">&#xF011;</a> <span></span> </section> ...

CSS class malfunction - various classes with identical functions

I'm new to the world of web development and design, embarking on a journey to learn all I can in these fields. Recently, I attempted to create unique hover styles for each menu button within my CSS classes-based menu list. However, I encountered an i ...

Determine whether a div that has been generated automatically has been selected by the user

My JSON file contains a list of elements, each creating a container. See the code below: $.getJSON('/data/risks.json', function(data) { var html = ''; $.each(data.risk, function(key, value){ html += '<div class="elementlis ...

Tips for managing table scroll in a flexbox design

Check out the demo here I am working with a table that has an indefinite number of rows and columns. When the table has a small number of rows and columns, it adjusts its width according to the available page space minus the width of the sidebar. Everythi ...

Introducing a fresh new feature incorporating various div elements through the power of JQuery

Why am I unable to retrieve the text of the newly added child divs? I am using JQuery to dynamically add these elements. Here is my sample fiddle: JSFIDDLE Could someone please guide me on what mistake I made? Javascript Code: var counter = 0; $("butto ...

Despite having data in the cache of the Apollo Client, the view page source does not display any information

It's puzzling why I can see data in the view page source on another page using a similar approach with a different query, but it doesn't work on this page. I suspect it may be due to using localStorage values as parameters, rather than an issue w ...