This project demonstrates the implementation of a modal dialog using HTML, CSS, and JavaScript.
The HTML structure consists of the following elements:
button: A button with the IDopenthat triggers the opening of the modal.div.modal-container: A container for the modal dialog.div.modal: The modal dialog itself.div.modal-header: The header section of the modal.h2: The title of the modal.i.fa.fa-close.close-icon: The close icon for the modal.
div.modal-content: The content section of the modal.img: An image displaying a profile photo.p: Placeholder text.
div.modal-footer: The footer section of the modal.button.btn-close: A button to close the modal.
The CSS styles are defined in an external stylesheet (style.css) and are responsible for the visual appearance of the modal.
The JavaScript code (modal.js) adds the necessary functionality to the modal. It performs the following actions:
- Listens for the
DOMContentLoadedevent to ensure the JavaScript code is executed after the HTML has loaded. - Retrieves the required DOM elements using their IDs.
- Attaches event listeners to the
open,close, andclose-iconelements. - When the
openbutton is clicked, it adds the classshow-modalto themodal-containerelement, displaying the modal. - When the
closebutton or the close icon is clicked, it removes the classshow-modalfrom themodal-containerelement, hiding the modal.
The project utilizes the following external resources:
- Font Awesome: A popular icon library used for the close icon.
- Custom CSS styles defined in
style.cssfor the modal appearance.
To use the modal, follow these steps:
- Click the "Click to Open" button.
- The modal dialog will appear, displaying the user profile details.
- To close the modal, click the "Close" button or the close icon.