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

Tips for formatting angular text sections

Within the scope of a controller, I have a status variable. After a successful rest PUT request, I add a message to this JavaScript variable. This message is displayed in my template using the {{status}} Is there a way to customize the styling of this mes ...

Creating a smooth sliding textarea in HTML

I am working on creating an HTML table with numerous text input areas (textarea) that expand downwards when clicked. Currently, the textarea element expands properly but disrupts the layout of the table. My goal is to achieve a design like this Instead o ...

Syntax highlighting in VSCode does not seem to be functional when the ?? nullish coalescing operator is being utilized

Hello there! I've recently started using react.js with typescript on a new computer, but I've encountered an issue with syntax highlighting in VSCode. It seems that the problem arises when there's a double question mark (??) in the code, spe ...

Transforming an array into an object using TypeScript

I am attempting to create a generic type for a function that transforms an array into an object, like so: type ObjectType = { id: number; name: string; status: string }; const xyz: ObjectType[] = [ { id: 1, name: "X", status: " ...

There seems to be an issue with authentication in React JS and AWS Cognito as the logins are

I've been encountering an issue with logging in. Every time I try, I keep receiving the error message: Logins don't match. Please include at least one valid login for this identity or identity pool. I already have a registered user and have confi ...

Creating a custom dialog box using JavaScript

How can I create a customized dialog box in the center without displaying "the host name says..." using CSS? function myFunction() { alert("Record Save"); } Thank you in advance! ...

Customize the color of an unchecked radio button in Material UI

I am currently working on my React app and I have implemented Material UI radio buttons. I wanted to customize their color to match my theme, so I utilized the ThemeProvider from '@material-ui/core/styles'. Below is the snippet of the theme objec ...

Transfer ERC20 tokens along with an Ethereum transaction

Is there a way to specify the ETH value for a transaction when using the "useContractWrite" hook? I need to send both ETH and ERC20 tokens. I am having trouble with nesting elements, asynchronous calls... I'm not sure how to handle this in wagmi. Any ...

The appearance of my website appears differently depending on the resolution

Just recently, I began exploring the world of HTML/CSS/JS and created a handy tool for my personal use. However, I encountered an issue when viewing it on different resolutions which caused some elements to look distorted. The tool I made allows me to inp ...

Is Amazon altering the names of their CSS selectors and HTML elements on the fly?

For my Amazon.es web scraper built with Selenium, I am using a CSS selector to determine the total number of pages it will iterate through. However, the selector name seems to change dynamically and I must update it daily. As someone not well-versed in H ...

How can I create a circular Datepicker in JavaFX?

Struggling with customizing my JavaFX application using CSS. Everything was going smoothly until I encountered the Datepicker. Despite trying various approaches, none seem to be working. Is there a way to round the Datepicker just like my TextFields? Here ...

The getStaticProps function will generate an object by fetching data from various URLs

Within my getStaticProps function in next js, I am faced with the challenge of fetching multiple dynamic URLs and exporting the results as props to the component. As these URLs are automatically generated, I do not know how many there will be to fetch. My ...

Struggling with finding the appropriate CSS selector?

I'm struggling to find the correct selector. Let me do my best to explain the situation: I am currently working on a project where I am unable to make changes to the HTML and JavaScript due to dynamic content and other constraints. Within this proj ...

In ES6 React, if you want to add arguments to event handlers when functions are bound in the constructor, follow these

When working with constructors in es6, it is recommended to bind functions early like so: class App extends React.Component { constructor(props) { super(props); this.handleClick = this.handleClick.bind(this); // binding done in the constructor ...

React - Input fields remain uneditable despite state being updated

I am experiencing difficulty typing in the input fields, as the changes I make are not displaying. Currently, I am utilizing props to either show an event or display an empty event if there are no props provided. Unfortunately, Stack is prompting me to in ...

Issue: The function (0, react__WEBPACK_IMPORTED_MODULE_1__.useActionState) is not recognized as a valid function or its output is not iterable

I found a great example of using useActionState at this source. Currently, I am implementing it in my project with Next.js and TypeScript. app/page.tsx: "use client"; import { useActionState } from "react"; import { createUser } from ...

Utilizing an external SCSS or CSS file with Material UI in React: A step-by-step guide

Encountering issues with external CSS files in my React project that uses Material UI components. Despite creating a CSS file for each component in the react components folder, they fail to load upon hard reloading the site. I prefer using external CSS ov ...

Maintain the aspect ratio of an image within a flex container when the height is adjusted

I'm currently facing an issue with an image in a flex container. My goal is to maintain the image's ratio when the height of the container or window is decreased or resized. Check out this sample fiddle html, body { height: 100%; } .wrappe ...

Tips for expanding a text input field vertically, not horizontally like in Facebook, while typing or by holding down the Shift key and pressing Enter

I've come across numerous plugins that enable vertical resizing of a textarea and others that allow horizontal resizing of an input field. However, I have yet to find one that enables vertical resizing of an input field similar to Facebook's comm ...

What is the method for triggering two actions within a single linked tag?

I have a link tag structured like this: <a href="<?php echo base_url().'dashboard' ?>" class="check_session">Home</a> Upon clicking the "Home" link, it should navigate to the dashboard. At the dashboard page, I want to check i ...