-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
text-wrap-balance-nav.html
118 lines (111 loc) · 3.45 KB
/
text-wrap-balance-nav.html
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Navigation Bar with Text-Wrap Balance</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
}
nav {
background-color: #f0f0f0;
padding: 10px;
margin-bottom: 20px;
width: 400px;
max-width: 100%;
box-sizing: border-box;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
}
li {
display: inline;
margin-right: 10px;
line-height: 40px;
}
a {
text-decoration: none;
color: #333;
padding: 5px 10px;
border-radius: 3px;
background-color: #e0e0e0;
}
.controls {
margin-top: 20px;
width: 400px;
max-width: 100%;
}
.control-item {
margin-bottom: 10px;
}
#item-count-value {
margin-left: 10px;
}
</style>
</head>
<body>
<nav id="main-nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">FAQ</a></li>
<li><a href="#">Support</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Team</a></li>
<li><a href="#">Careers</a></li>
<li><a href="#">Partners</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Events</a></li>
</ul>
</nav>
<div class="controls">
<div class="control-item">
<label for="item-count">Number of visible items:</label>
<input type="range" id="item-count" min="4" max="14" value="13">
<span id="item-count-value">13</span>
</div>
<div class="control-item">
<label>
<input type="checkbox" id="balance-toggle"> Enable text-wrap: balance
</label>
</div>
</div>
<script>
const nav = document.getElementById('main-nav');
const toggle = document.getElementById('balance-toggle');
const itemCountSlider = document.getElementById('item-count');
const itemCountValue = document.getElementById('item-count-value');
const navItems = nav.querySelectorAll('li');
function updateVisibleItems(count) {
navItems.forEach((item, index) => {
item.style.display = index < count ? 'inline' : 'none';
});
}
function updateTextWrap() {
if (toggle.checked) {
nav.style.textWrap = 'balance';
} else {
nav.style.textWrap = '';
}
}
toggle.addEventListener('change', updateTextWrap);
itemCountSlider.addEventListener('input', function() {
const count = parseInt(this.value);
itemCountValue.textContent = count;
updateVisibleItems(count);
});
// Initialize with all items visible and default text-wrap
updateVisibleItems(13);
updateTextWrap();
</script>
</body>
</html>