Skip to content

Commit a36eaf1

Browse files
authored
1 parent 4ac8c4f commit a36eaf1

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

text-wrap-balance-nav.html

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Navigation Bar with Text-Wrap Balance</title>
7+
<style>
8+
body {
9+
font-family: Arial, sans-serif;
10+
margin: 0;
11+
padding: 20px;
12+
}
13+
nav {
14+
background-color: #f0f0f0;
15+
padding: 10px;
16+
margin-bottom: 20px;
17+
width: 400px;
18+
box-sizing: border-box;
19+
}
20+
ul {
21+
list-style-type: none;
22+
padding: 0;
23+
margin: 0;
24+
}
25+
li {
26+
display: inline;
27+
margin-right: 10px;
28+
margin-bottom: 15px; line-height: 40px;
29+
}
30+
a {
31+
text-decoration: none;
32+
color: #333;
33+
padding: 5px 10px;
34+
border-radius: 3px;
35+
background-color: #e0e0e0;
36+
}
37+
.controls {
38+
margin-top: 20px;
39+
width: 400px; /* Reduced from 600px to 400px to match nav */
40+
}
41+
.control-item {
42+
margin-bottom: 10px;
43+
}
44+
#item-count-value {
45+
margin-left: 10px;
46+
}
47+
</style>
48+
</head>
49+
<body>
50+
<nav id="main-nav">
51+
<ul>
52+
<li><a href="#">Home</a></li>
53+
<li><a href="#">About</a></li>
54+
<li><a href="#">Services</a></li>
55+
<li><a href="#">Products</a></li>
56+
<li><a href="#">Blog</a></li>
57+
<li><a href="#">Contact</a></li>
58+
<li><a href="#">FAQ</a></li>
59+
<li><a href="#">Support</a></li>
60+
<li><a href="#">Portfolio</a></li>
61+
<li><a href="#">Team</a></li>
62+
<li><a href="#">Careers</a></li>
63+
<li><a href="#">Partners</a></li>
64+
<li><a href="#">News</a></li>
65+
<li><a href="#">Events</a></li>
66+
</ul>
67+
</nav>
68+
69+
<div class="controls">
70+
<div class="control-item">
71+
<label for="item-count">Number of visible items:</label>
72+
<input type="range" id="item-count" min="4" max="14" value="13">
73+
<span id="item-count-value">13</span>
74+
</div>
75+
<div class="control-item">
76+
<label>
77+
<input type="checkbox" id="balance-toggle"> Enable text-wrap: balance
78+
</label>
79+
</div>
80+
</div>
81+
82+
<script>
83+
const nav = document.getElementById('main-nav');
84+
const toggle = document.getElementById('balance-toggle');
85+
const itemCountSlider = document.getElementById('item-count');
86+
const itemCountValue = document.getElementById('item-count-value');
87+
const navItems = nav.querySelectorAll('li');
88+
89+
function updateVisibleItems(count) {
90+
navItems.forEach((item, index) => {
91+
item.style.display = index < count ? 'inline' : 'none';
92+
});
93+
}
94+
95+
function updateTextWrap() {
96+
if (toggle.checked) {
97+
nav.style.textWrap = 'balance';
98+
} else {
99+
nav.style.textWrap = '';
100+
}
101+
}
102+
103+
toggle.addEventListener('change', updateTextWrap);
104+
105+
itemCountSlider.addEventListener('input', function() {
106+
const count = parseInt(this.value);
107+
itemCountValue.textContent = count;
108+
updateVisibleItems(count);
109+
});
110+
111+
// Initialize with all items visible and default text-wrap
112+
updateVisibleItems(13);
113+
updateTextWrap();
114+
</script>
115+
</body>
116+
</html>

0 commit comments

Comments
 (0)