📜  modal 和 in modal (1)

📅  最后修改于: 2023-12-03 15:02:58.850000             🧑  作者: Mango

Modal and In Modal

Introduction

Modal and In Modal are commonly used in web development to create pop-up windows, dialogs, and modals that display important information or requests to the user. In this article, we will explore what Modal and In Modal are, how they work, and how they can be integrated into your web application.

What is a Modal?

A modal is a graphical user interface (GUI) element that appears on top of the main content and blocks user interaction with the rest of the interface until a specific action is taken. Modals can be used to display alerts, confirmations, forms, or any other type of information that requires user attention.

What is In Modal?

An In Modal is a nested Modal that appears inside of another Modal. This is useful when you need to ask for additional details or information within a Modal window that has already been opened. The In Modal is displayed on top of the parent Modal, creating a stacked effect.

How They Work

Modals and In Modals are created using HTML, CSS, and JavaScript. Here’s a basic example of how to create a Modal:

<!-- HTML -->
<div id="myModal" class="modal">
  <div class="modal-content">
    <span class="close">&times;</span>
    <h2>Modal Title</h2>
    <p>Modal content goes here.</p>
  </div>
</div>

<!-- CSS -->
.modal {
  display: none;
  position: fixed;
  z-index: 1;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.4);
}

.modal-content {
  background-color: #fefefe;
  margin: 15% auto;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  width: 70%;
}

.close {
  color: #aaaaaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
}

This HTML creates a basic Modal with a title, content, and close button. The CSS sets the Modal to display as a fixed positioned element, while the JavaScript is used to show and hide the Modal on button click events.

To add an In Modal, you can simply nest another Modal within the Modal-content div of the parent Modal. Here’s an example:

<!-- HTML -->
<div id="myModal" class="modal">
  <div class="modal-content">
    <span class="close">&times;</span>
    <h2>Modal Title</h2>
    <p>Modal content goes here.</p>
    <!-- In Modal -->
    <div id="myInModal" class="modal">
      <div class="modal-content">
        <span class="close">&times;</span>
        <h2>In Modal Title</h2>
        <p>In Modal content goes here.</p>
      </div>
    </div>
  </div>
</div>

This HTML creates an In Modal inside the parent Modal. The CSS and JavaScript are the same as the basic Modal.

Conclusion

Modal and In Modal are useful GUI elements that can improve the user experience on your web application. They can be used to display important information and requests, while blocking user interaction with the rest of the interface. With a basic understanding of HTML, CSS, and JavaScript, you can create your own Modals and In Modals to use in your web development projects.