Last active
August 29, 2015 14:17
-
-
Save stuartweir/4e78340742174671ef1d to your computer and use it in GitHub Desktop.
Creating a responsive `wp_nav_menu` in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// inside of header.php | |
<div class='menu_bg'> | |
<?php wp_nav_menu( array( 'theme_location'=>'main', 'menu_class' => 'menu', 'depth' => 1)); ?> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The problem is I am not sure how to properly create a menu bar/dropdown from the array in header.php. | |
Currently, the mobile query just floats left and if it cant, loads the menu items on the next line. | |
However, it obviously looks really unprofessional and I'd like to create a dropdown menu instead, | |
but I cannot use bootstrap or some other CSS framework, just pure CSS. | |
-Stu. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Inside the mobile media query */ | |
.menu_bg{ | |
background:#005e90; | |
height:48px; | |
position:relative; | |
top:55px; | |
border-top:thin solid #218ac9; | |
} | |
.menu{ | |
padding: 0; | |
width:100%; | |
margin:0 auto; | |
} | |
.menu-item a { | |
height:31px; | |
color:#ffffff; | |
font-family:'Open Sans', sans-serif; | |
padding:0px 23px; | |
float: left; | |
position: relative; | |
font-size:14px; | |
padding-top: 17px; | |
top:-1px; | |
width: 89.75%; | |
background:#005e90; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output of
wp_nav_menu
is just aul
full ofli
anda
tags. So you could hide the menu for mobile and show a menu toggle button at a certain breakpoint and then when that is clicked, show the menu. Here's a codepen based off of the menu in the screencast on the:hover
pseudo class: http://codepen.io/guyroutledge/pen/QwYPeO. The code could be cleaned up a little but the idea is there. Let me know if you need a hand. :)