Properly Align Menu Item Search Bar
-
I added my search bar to my menu navigation, by using the following code:
add_filter('wp_nav_menu_items','add_search_box', 10, 2); function add_search_box($items, $args) { ob_start(); get_search_form(); $searchform = ob_get_contents(); ob_end_clean(); $items .= '<li>' . $searchform . '</li>'; return $items; }
This put the search bar directly to the right of my last menu item, with the usual spacing between menu items. I want the search bars position to be all the way to the right, with equivalent spacing from the right just as the rest of the site has going down (all the way to the right, 10 or so pixel padding).
To do this, I altered my #search css, and added:
margin-left: 120px;
The number is arbitrary for the example, so ignore the value. I just want to know if this is how I would properly position my search bar, and if not, how do I go about doing this? I assume it’s wrong, as if I change the menu navigation, the length will change, which will alter the position, and it’ll need to be manually set over and over. There must be a cleaner, more automated to the theme-width way to do this.
My site – https://www.pixelpurge.com/wordpress
(Temp url, just for building)
- The topic ‘Properly Align Menu Item Search Bar’ is closed to new replies.