What is the best way to use margin-top and margin-bottom in CSS?

Looking to perfectly center this modal in the middle of the screen with some margin all around. However, struggling to apply margin specifically to the top and bottom!

export function Modal() {
  return (
    <div className="fixed inset-0 z-[60] bg-opacity-25 backdrop-blur-sm flex justify-center items-center">
      <div className="absolute inset-0 flex justify-center items-center">
        <div className="bg-background border rounded-lg w-full h-full m-8">
          <h1>Hello</h1>
        </div>
      </div>
    </div>
  );
}

Answer №1

To make adjustments to the modal display, it is recommended to eliminate the h-full class from the container div, as this will cause it to occupy the entire height of the screen. Additionally, consider adding the max-w-md class to restrict the width of the modal. To enhance the design, including some padding to the inner div would also be beneficial.

function CustomModal() {
  return (
    <div className="fixed inset-0 z-[60] flex bg-opacity-25 backdrop-blur-sm justify-center items-center">
       <div className="absolute inset-0 flex justify-center items-center">
          <div className="bg-background border rounded-lg w-full max-w-md m-8 p-4">
             <h1>Hello</h1>
          </div>
        </div>
    </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

Mobile device scrolling glitch

I'm currently working on my website, which can be found at . After testing it on mobile devices, I came across an issue that I just can't seem to fix. For instance, when viewing the site on a device with 768px width, you can scroll to the righ ...

How come the icon doesn't update on the client side after being rendered on the server side?

Currently implementing a Daisyui theme switcher in my nextjs project. It's mostly working fine, but there are some issues I'm having trouble with. I've created a simple theme switch button: // Themeswitch.jsx 'use client'; impor ...

What is the best way to eliminate excess spacing between HTML td and table elements in Outlook?

Here's the HTML email code snippet. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Co ...

Excessive width of the lower border

I have a dropdown menu on my website and I wanted to add a border-bottom to the menu. However, the border appears too wide. I went through every step of this solution as it seemed like the same problem, but nothing seems to be working. It would be great i ...

Text with Icon Fonts Does Not Align Vertically

I'm using icon fonts in a nav list and I want to place text between two of the icons. However, there's an issue with alignment - the icons are positioned higher than the text, causing them to not match up well. Is there a solution to this problem ...

The page loads successfully at first, but upon refreshing, a 404 error occurs when using Zeit, Nextjs, and now

After recently updating from now v1 to v2, I encountered an issue where my pages would return a 404 error when reloading after pushing to production using now --prod. While everything worked fine locally with now dev, the routing seemed to be causing confu ...

I'm having trouble changing the background color on my HTML Bootstrap website. Is there a way to easily add social network buttons as well?

I'm encountering a problem here. One of my friends assisted me with Bootstrap elements for my website, but after switching my site to Bootstrap, I am unable to change the background color on my website. Can someone lend a hand? Much appreciated! Also, ...

Incorporating a spectrum of hues into an HTML document

As a beginner in HTML, I recently stumbled upon a website (YT video) showcasing a stunning array of colors on buttons. You can check it out here: https://www.youtube.com/watch?v=OPaLnMw2i_0 I'm curious if these colorful designs can be applied to text ...

The yarn installation process is not utilizing the latest available version

Working with a custom React component library my-ui hosted on a personal GitLab instance. In the package.json, I include the library like this: "my-ui": "git+ssh://<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6 ...

The error encountered reads as "Uncaught TypeError: Unable to destructure the property 'basename' from 'React2.useContext(...)' as it is null."

Currently experiencing the following issue: Uncaught TypeError: Cannot destructure property 'basename' of 'React2.useContext(...)' as it is null. Specifically in the Link component from this code snippet: import React, { useEffect, u ...

jQuery - encountering issues setting CSS properties within an AJAX callback function

I'm struggling with a jquery ajax callback function to change the background color of a table cell. Despite no errors in Firebug, my code isn't working as expected. Here's the code I have: $(".tariffdate").click(function () { var proper ...

Ran into a situation where Nextjs13 had two children sharing the same key

Currently, I am in the process of creating a booking form using shadcn/ui within nextjs13. As part of this, I am mapping over different hairstyles listed in my postgres database to generate selectable options for users. However, during this process, I enco ...

Emphasize the engaged menu selection when the page is refreshed

My application is a dashboard app built with React, Redux, and Antdesign. I utilized the layout provided by Ant design at https://ant.design/components/layout/. One issue I encountered is that when clicking on side menus, the active menu gets bold but upo ...

Developing interactive checkboxes for individual rows through React.js

Within a form, I have rows containing two inputs each. Upon clicking "add", a new row is created. For the second row onwards, by clicking "add" a checkbox labeled 1 should be added to indicate dependency on the previous row. In addition, for the third row, ...

Position CSS elements at the bottom of the webpage

I'm having trouble with my footer always being covered by dynamic content on my page. How can I adjust the CSS to make sure the footer stays at the bottom and adjusts to the size of the content? Here's the current CSS code for the footer: div ...

What is the method for adding an event listener in AngularJS within an ng-repeat iteration?

I'm completely new to AngularJS and currently working on building a photo gallery. The basic idea is to have an initial page displaying thumbnail photos from Twitter and Instagram using an AngularJS ng-repeat loop. When a user hovers over an image, I ...

Creating a basic secured route using NextAuth - a step-by-step guide

I am looking to create a simple protected route for my application. I already have a credentials provider and nextAuth middleware set up. Here is the logic I want to implement: If a user is logged in, they should be able to visit /profile. If they try to ...

CSS for when the mouse hovers over an element

Two php files and a js file are involved in this scenario. The issue at hand is that when the div is clicked, it navigates to a new page with an appended # to the URL, causing it to scroll to the specified comment ID. However, instead of scrolling to the c ...

Omitting specific modules from the Webpack DLL compilation

I have a universal JavaScript application built with Webpack. I've utilized the DLL plugin to pre-build all my node_modules, but recently encountered an issue when adding a new library. This specific library is causing the DLL build process to fail (d ...

The specified font-size in my CSS is being ignored by Chrome

I'm a beginner in the world of html/css and was tasked with creating a html webpage. I set a specific font-size for my webpage, only to be surprised when my browser (Google Chrome) adjusted it on its own. Even though I specified the font-size as 14px, ...