-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
93 lines (83 loc) · 2.53 KB
/
index.html
File metadata and controls
93 lines (83 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Favorite Links</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
.button-container {
display: flex;
flex-wrap: wrap;
gap: 10px;
width: 100%;
max-width: 800px;
}
.link-button {
display: inline-block;
padding: 10px 20px;
margin: 5px;
border: none;
border-radius: 5px;
background-color: #4CAF50;
color: white;
cursor: pointer;
font-size: 16px;
transition: 0.3s;
position: relative;
}
.link-button:hover {
background-color: #45a049;
}
.favorite {
background-color: #FFD700;
color: black;
}
.favorite-button {
position: absolute;
top: 5px;
right: 5px;
background-color: transparent;
border: none;
font-size: 18px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>My Links</h1>
<div class="button-container" id="buttonContainer">
<div class="link-button" onclick="window.open('https://example.com')">
Example Link 1
<button class="favorite-button" onclick="toggleFavorite(event)">⭐</button>
</div>
<div class="link-button" onclick="window.open('https://another-example.com')">
Example Link 2
<button class="favorite-button" onclick="toggleFavorite(event)">⭐</button>
</div>
<div class="link-button" onclick="window.open('https://yet-another-example.com')">
Example Link 3
<button class="favorite-button" onclick="toggleFavorite(event)">⭐</button>
</div>
</div>
<script>
function toggleFavorite(event) {
event.stopPropagation(); // Prevents the main button click from triggering
const button = event.target.parentElement;
button.classList.toggle('favorite');
const container = document.getElementById('buttonContainer');
const favorites = Array.from(container.children).filter(child => child.classList.contains('favorite'));
const nonFavorites = Array.from(container.children).filter(child => !child.classList.contains('favorite'));
container.innerHTML = ''; // Clear existing buttons
favorites.forEach(fav => container.appendChild(fav)); // Append favorites first
nonFavorites.forEach(nonFav => container.appendChild(nonFav)); // Then append non-favorites
}
</script>
</body>
</html>