![]()
![]()
This guide will show you how to use Icon Box widgets as a vertical navigation menu in the left column to control different content sections in the right column.
Here is an example of what you can build with this technique: a clean, icon-based navigation system.
30% and the right column to 70%. Adjust as needed for your design.Hover state to provide feedback to the user. Set a different background or icon color for when the mouse is over the box.This is the key step to link the “buttons” to the content.
icon-box-switcher#content-1icon-box-switcher to every box.#content-2, #content-3, and so on.content-1content-panelcontent-2, content-3, etc.). Make sure they all keep the content-panel class.This code brings the functionality to life. It listens for clicks on your Icon Boxes and shows the correct content panel.
</body> - End.<style>
/* By default, hide all the content panels */
.content-panel {
display: none;
}
/* Show the very first content panel by default */
#content-1 {
display: block;
}
/* Add a style for the "active" icon box */
.icon-box-switcher.active-box {
background-color: #f0f4ff; /* A light blue background */
border-left: 3px solid #6a63e4; /* A solid left border */
border-radius: 5px;
}
/* Make the whole icon box clickable */
.icon-box-switcher {
cursor: pointer;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Get all our icon boxes
const switcherBoxes = document.querySelectorAll('.icon-box-switcher');
// Get all our content panels
const contentPanels = document.querySelectorAll('.content-panel');
// Function to handle the content switching
function switchContent(targetId) {
// Hide all content panels
contentPanels.forEach(panel => {
panel.style.display = 'none';
});
// Show the target panel
const targetPanel = document.querySelector(targetId);
if (targetPanel) {
targetPanel.style.display = 'block';
}
// Update the 'active' class on the icon boxes
switcherBoxes.forEach(box => {
const boxLink = box.querySelector('a');
if (boxLink && boxLink.getAttribute('href') === targetId) {
box.classList.add('active-box');
} else {
box.classList.remove('active-box');
}
});
}
// Set the first box as active by default when the page loads
if (switcherBoxes.length > 0) {
switcherBoxes[0].classList.add('active-box');
}
// Add a click listener to each icon box
switcherBoxes.forEach(box => {
box.addEventListener('click', function(e) {
e.preventDefault(); // Stop the link from jumping the page
const link = this.querySelector('a');
if (link) {
const targetId = link.getAttribute('href');
switchContent(targetId);
}
});
});
});
</script>
Now, when you preview your page, clicking on each Icon Box will display its corresponding content panel, creating a seamless and interactive experience for your users.