My HTML includes a pointing menu
when the screen width exceeds 630px
. Below 630px, it switches to a sidebar with a menu button:
<nav class="ui inverted sidebar menu vertical slide out" id="m_menu">
<a href="index.php" class="item">
<i class="home icon"></i>Home
</a>
<a href="about.php" class="item">
<i class="user icon"></i>User
</a>
<a href="portfolio.php" class="item">
<i class="archive icon"></i> Portfolio
</a>
</nav>
<div id="menuDiv">
<nav class="ui inverted fluid four item pointing menu" id="menu">
<a href="index.php" class="item">
<i class="home icon"></i>Home
</a>
<a href="about.php" class="item">
<i class="user icon"></i>User
</a>
<a href="portfolio.php" class="item">
<i class="archive icon"></i> Portfolio
</a>
<a href="contact.php" class="item">
<i class="message icon"></i> Contact
</a>
</nav>
<div class="ui labeled icon button black" id="m_btn">
<i class="icon list layout"></i> Menu
</div>
</div>
<img src="http://paulandtwyla.files.wordpress.com/2010/02/table-chairs-2.jpg" alt="Table With Chairs">
This is my CSS styling:
body{
margin:0;
padding:0;
font-family:"helvetica",arial;
}
#menuDiv{
margin:40px 40px 0 40px;
text-align:center;
}
#menu:{
max-width:1024px;
margin:0 auto;
}
#m_btn{display:none;}
img{
width:100%;
height:auto;
position:absolute;
top:0;
z-index:-1;
}
@media all and (max-width:630px)
{
#menu{display:none;}
#m_btn{
display:inline-block;
}
}
/*fails to fix sidebar sidebar showing @width>=631px*/
@media all and (min-width:631px)
{
/*suggested on tutsplus,no change on applying*/
body.pushable{margin-left:0 !important;}
#m_menu.visible{
display:none;
}
}
Upon resizing the screen to 630px or lower, the horizontal navigation bar menu disappears while a centered button appears. A screenshot can be found here
If I open the sidebar and resize the screen to a width greater than 630px, the menu items disappear but the sidebar remains visible. Another screenshot is available here
I am looking for a solution to ensure that the sidebar also disappears when open at resolutions over 630px.
EDIT:
While the sidebar is open, Semantic UI wraps everything else in a pusher
class and adds a pushable
class to the body
. It utilizes the visible
class to indicate the sidebar's status, prompting me to try:
@media all and (min-width:631px)
{
/*suggested on tutsplus,no change on applying*/
body.pushable{margin-left:0 !important;}
#m_menu.visible{
display:none;
}
}
Here is a visual representation of the DOM with the sidebar visible:
<body class="pushable">
<nav class="ui inverted sidebar menu vertical slide out uncover left animating visible" id="m_menu">
<a href="index.php" class="item">
<i class="home icon"></i>Home
</a>
<a href="about.php" class="item">
<i class="user icon"></i>User
</a>
<a href="portfolio.php" class="item">
<i class="archive icon"></i> Portfolio
</a>
</nav>
<div class="pusher dimmed"><div id="menuDiv">
<nav class="ui inverted fluid four item pointing menu" id="menu">
<a href="index.php" class="item">
<i class="home icon"></i>Home
</a>
<a href="about.php" class="item">
<i class="user icon"></i>User
</a>
<a href="portfolio.php" class="item">
<i class="archive icon"></i> Portfolio
</a>
<a href="contact.php" class="item">
<i class="message icon"></i> Contact
</a>
</nav>
<div class="ui labeled icon button black" id="m_btn">
<i class="icon list layout"></i> Menu
</div>
</div><img src="http://paulandtwyla.files.wordpress.com/2010/02/table-chairs-2.jpg" alt="Table With Chairs"></div>
</body>
Check out this jsfiddle and a runnable demo