Tips for positioning a button outside the dialog box

I need to include a close button that can function independently of the dialog box.

I want the modal with the close button positioned outside the div element.

Desired outcome:

https://i.sstatic.net/DK4f7.png

Current implementation:

https://i.sstatic.net/KbPk5.png

const Component = styled(Box)`
  display: flex;
  height: 528px;
`;

const Image = styled(Box)`
  width: 270px;
  background: url(https://static-assets-web.flixcart.com/www/linchpin/fk-cp-zion/img/login_img_c4a81e.png)
    no-repeat;
  color: #fff;
  background-color: #2874f0;
  background-position: 50% 85%;
  padding: 40px 33px;

  & > p {
    margin-top: 12px;
    color: #dbdbdb;
    font-size: 18px;
  }
`;

const ReqBtn = styled(Button)`
  background-color: #fb641b;
  text-transform: none;
  height: 48px;
  width: 305px;
  padding: 10px 20px 10px 20px;
`;

const Wrapper = styled(Box)`
  padding: 56px 35px 16px 35px;
  & > p {
    color: #878787;
    font-size: 12px;
  }
`;

//      <--------------------------------------- styled section ends-------------------------------->

const LoginDialog = ({ open, setOpen }) => {
  const handleCloseDialog = () => {
    setOpen(false);
  };
  return (
    <Dialog
      open={open}
      onClose={handleCloseDialog}
      sx={{
        "& .MuiDialog-container": {
          "& .MuiPaper-root": {
            width: "100%",
            maxWidth: "750px",
          },
        },
      }}
    >
      <Component>

        <Image>

          {/* <Typography
            style={{ fontWeight: "bold", fontSize: "28px", color: "#fff" }}
          >
            Login
          </Typography>
          <Typography>
            Get access to your Orders, Wishlist and Recommendations
          </Typography> */}


        </Image>


        <Wrapper>

          {/* <TextField label="Enter Email/Mobile Number" variant="standard" />
          <Typography>
            By continuing, you agree to Flipkart's Terms of Use and Privacy
            Policy.
          </Typography>
          <ReqBtn
            variant="contained"
            sx={{
              "&.MuiButtonBase-root:hover": { backgroundColor: "#fb641b" },
            }}
          >
            Request OTP
          </ReqBtn>
          <Typography>New to Flipkart?Create an Account</Typography> */}

        </Wrapper>

//close button

        <ClearIcon
          onClick={handleCloseDialog}
          style={{ cursor: "pointer", backgroundColor: "yellow" }}
        />
      </Component>
    </Dialog>
  );
};

export default LoginDialog;

When I tried placing the <ClearIcon> outside the <Dialog> component, it ended up appearing in my navbar position.

 <>
    <ClearIcon
        onClick={handleCloseDialog}
        style={{ cursor: "pointer", backgroundColor: "yellow" }}
      />
    </>

https://i.sstatic.net/kSCAq.png

Is there a way to position the CloseIcon outside the dialog box according to the provided design?

Answer №1

Here's an example:

.container{
  position:relative;
  background:gray;
  width:100px;
  height:100px;
}
.container>.buttons{
  position:absolute;
  right:-30px;
}
<div class="container">
  <div class="buttons">
    <button>x</button>
  </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

Error in Angular Due to Circular Reference in JSON

I'm currently working on integrating a tree structure in AngularJS. The goal is to construct the tree by dynamically adding nodes based on user input from an Angular Select element. Here is the specific operation I'm trying to accomplish: var a ...

What are the reasons for validation failure when it is moved into a method?

I am currently in the process of developing a validation function in JavaScript. However, when I extracted the logic into a private method, my validation started failing and I can't seem to figure out why. Here is my HTML definition: <input type= ...

Executing VueJS keyup handler after the previous onclick handler has been executed

Link to example code demonstrating the issue https://codepen.io/user123/pen/example-demo I am currently facing an issue with a text field named search_val that has a watcher attached to it. The text field includes a v-on keyup attribute to detect when th ...

extract information from a document and store it in an array

As I delve into the realm of programming, I find myself grappling with the best approach to extract data from a file and store it in an array. My ultimate aim is to establish a dictionary for a game that can verify words provided by players. Despite my no ...

Unable to transfer bootstrap form data from the view to the controller due to issues with bootstrap validations

Scenario I have integrated a bootstrap form into my codeigniter application with bootstrap validation to ensure data accuracy. I want the submit button to work properly so that users can successfully submit the form and be redirected to the action page ...

What's the reason behind CSS selectors not allowing empty spaces, while XPath does?

Why is it that Xpath is able to find an HTML element with a class attribute containing empty spaces, while CSS cannot? # Element: <div class="I Love StackOverFlow"></div> self.page.locator('//div[@class="I Love StackOverFlo ...

Returning to the initial identifier of the element

I am working with li blocks that, when clicked, change their class ID in the following way: onclick = "document.getElementById('procblock1').id = 'procblock1Clicked';" "document.getElementById('procblock2Click ...

I have assigned the Header section, the search feature, and the error handling component

I'm currently working on adding a search bar that will retrieve data from an API based on the user input. If anyone is experienced with the latest version of ReactJS, I could really use your help. I'm struggling with the search component, header ...

Changing the tooltip background color in FullCalendar 6 and Bootstrap 5: A step-by-step guide

My FullCalendar agenda displays events with colored backgrounds. However, I want the tooltips for these events to have matching background colors as well. Currently, the tooltips always show up with a black background. Is there a way to dynamically change ...

Implement a delete function within the delete button for every row in DataTables in Angular and incorporate a background color for the button

I am facing an issue where I can add a button to each row in my data tables, but the button is not functional. I am unsure how to implement a delete event for this button. Can anyone provide assistance? It would be great if you could also show me a demo ;) ...

How can I refresh an HTML element when a value in a multi-dimensional array changes?

I'm facing an issue with a v-btn component that gets its content from values deep inside a multi-dimensional array. <div v-for="student in students"> <v-btn disabled v-for="tag in student.tags">{{tag}}</v-btn> </div> In ...

A guide on converting JSON without using the "&quot" symbol

let newText = [{&quot;name&quot;:&quot;en3&quot;,&quot;value&quot;:234},{&quot;name&quot;:&quot;en4&quot;,&quot;value&quot;:135},{&quot;name&quot;:&quot;en1&quot;,&quot;value&quot;:335 ...

Scaling Three.js Mesh to fit renderer while maintaining aspect ratio

Currently, I am using the STLLoader plugin from the Github repository of three.js. This is a snippet of my code: this.loadSTL = function(scene, stlFile){ var loader = new THREE.STLLoader(); loader.addEventListener('load', function(g ...

Table functionality encountering issue when using multi-select with controlShouldRenderValue enabled

My table has a header with rows of select options. I am facing an issue where the selections are only displaying under one of the selects instead of each respective select. I can't seem to figure out what is causing this problem. You can view a worki ...

Launching a cutting-edge web application using React.js and Node.js

I'm currently developing a web application using React.js and Node.js. I'm curious about the deployment process for my web app. When running it on my local server, I need to use two servers - one for React.js and another for Node.js. Does this se ...

React: Switching PopUp causes the entire component to be re-rendered

Currently, I am in the process of familiarizing myself with React, so I appreciate your patience. I am developing a component using MaterialUI which consists of a grid and a PopOver. A basic mockup of this component is as follows: export const Overview ...

Leverage the power of React, Material-UI, and Typescript to inherit button props and incorporate a variety of unique

Looking to enhance the Material-UI button with additional variants like "square." How can I create a prop interface to merge/inherit props? Check out the following code snippet: import React from "react"; import { Button as MuiButton } from "@material-u ...

Tips for Enhancing JavaScript Performance

Is there a way to enhance my JavaScript code like this: $(window).scroll(function() { if ($('#sec1').isVisible()) { $('.js-nav a.m1').addClass('active'); } else { $('.js-nav a.m1').removeClas ...

What is the best method to dynamically navigate through JSON data and save an object at a specific level?

Here is an example json structure for a menu: { "menu": [{ "name": "vegetation", "id": "1", "children": [ { "name": "landuse", "id": "1.1", "children": [ ...

Is there an issue with the JSON data?

"stocksdata" :[{"id":7,"SCRIP":"ASIANPAINT","LTP":3341,"OHL":"BUY","ORB15":"BREAKOUT","ORB30":"NT","PRB":"NA","CAMARILLA& ...