98 lines
2.7 KiB
HTML
98 lines
2.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Modal/Floating Element Examples</title>
|
|
<style>
|
|
/* Common styles */
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
line-height: 1.6;
|
|
margin: 0;
|
|
padding: 20px;
|
|
}
|
|
.btn {
|
|
padding: 10px 20px;
|
|
background-color: #007bff;
|
|
color: white;
|
|
border: none;
|
|
cursor: pointer;
|
|
}
|
|
|
|
/* Method 1: CSS Positioning */
|
|
.modal-overlay {
|
|
display: none;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
}
|
|
.modal-content {
|
|
position: fixed;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
background-color: white;
|
|
padding: 20px;
|
|
border-radius: 5px;
|
|
}
|
|
#modal1:target {
|
|
display: block;
|
|
}
|
|
|
|
/* Method 2: Dialog Element */
|
|
dialog::backdrop {
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
}
|
|
dialog {
|
|
padding: 20px;
|
|
border-radius: 5px;
|
|
border: none;
|
|
}
|
|
|
|
/* Method 3: Floating Element */
|
|
.floating-element {
|
|
position: fixed;
|
|
bottom: 20px;
|
|
right: 20px;
|
|
background-color: white;
|
|
padding: 20px;
|
|
border-radius: 5px;
|
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Modal/Floating Element Examples</h1>
|
|
|
|
<!-- Method 1: CSS Positioning -->
|
|
<h2>1. CSS Positioning</h2>
|
|
<a href="#modal1" class="btn">Open Modal 1</a>
|
|
<div id="modal1" class="modal-overlay">
|
|
<div class="modal-content">
|
|
<h2>Modal 1</h2>
|
|
<p>This is a modal using CSS positioning.</p>
|
|
<a href="#" class="btn">Close</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Method 2: Dialog Element -->
|
|
<h2>2. Dialog Element</h2>
|
|
<button class="btn" onclick="document.getElementById('modal2').showModal()">Open Modal 2</button>
|
|
<dialog id="modal2">
|
|
<h2>Modal 2</h2>
|
|
<p>This is a modal using the dialog element.</p>
|
|
<button class="btn" onclick="document.getElementById('modal2').close()">Close</button>
|
|
</dialog>
|
|
|
|
<!-- Method 3: Floating Element -->
|
|
<h2>3. Floating Element</h2>
|
|
<div class="floating-element">
|
|
<h2>Floating Element</h2>
|
|
<p>This is a floating element using fixed positioning.</p>
|
|
</div>
|
|
</body>
|
|
</html> |