It seems like the issue here is that the media query is set to target a maximum width of 768px, so the styles are only applied under that condition. However, because there is no specific condition to hide the element, it still gets rendered on the page.
/* Initially hide the menu button */
.menu {
display: none;
}
/* Display the menu button when condition is met */
@media (max-width: 768px) {
.menu {
display: block;
}
}
<button class="menu">Menu</button>
In this scenario, I would recommend starting with mobile styling and simply adding display: none to a min-width media query. However, if your existing codebase relies on max-width, it's best to stick with that approach and include display: none outside of the current media query.