Hi guys I am trying to position a search box in my navigation menu of my wordpress site. I have managed to get it displaying in the menu using a plugin called Search Box Navigation. This plugin enables me to style the box to suit my needs.
However this is where I am running into issues.
The code responsible for generating the box located in a plugin file: (I added a class to the li in an effort to control how it would appear on the site...
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 class="menusearch">' . $searchform . '</li>';
return $items;
}
?>
This is my navigation html:
<nav id="access" role="navigation">
<div class="skip-link screen-reader-text">Skip to content</div>
<div class="menu">
<ul id="prime_nav" class="menu"><li id="menu-item-7" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-7"><span>Item 1</span></li>
<li id="menu-item-8" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-8"><span>Item 2</span>
<li id="menu-item-9" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-9"><span>Item 3</span></li>
<li id="menu-item-10" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-10"><span>Item 4</span></li>
<li id="menu-item-102" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-102"><span>Test</span></li>
<li class="menusearch">
<form method="get" id="searchform" action="http://incomebrokers.tld//">
<input type="text" value="Search"/>
<input type="submit" id="searchsubmit" value="Search" />
</form>
</li>
</ul>
</div>
</nav>
This is my css
#access ul li {
position:relative;
display:block;
float:left;
text-align: center;
width:100px;
white-space: nowrap;
}
/*Menu Search Class*/
.menusearch{
margin-left:500px;
}
any help on how I can position this box to the far right of the navigation but have it adjust when the browser is smaller in size?
I noticed that the same width(100px) is set for each li of the nav.
What about if you edit the css and you add:
#access ul li {
position:relative;
display:block;
float:left;
text-align: center;
width:100px;
white-space: nowrap;
}
#access ul li:last-child {
float:right;
width:300px;
}
http://jsfiddle.net/mBBJM/4537/
You could make it fluid and setting the width in % with a different percentage for the li of the nav that might need it.
Related
I would like to call a a div id function in CSS so that when my mouse hovers over the text it highlights it
<ul class="sub-menu">
<li id="menu-item-1721" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1721">Strategic IT Consulting</li>
is there a way to call this for all sub-menus in the ul class using CSS?
.sub-menu:hover {
color:green
}
.sub-menu li a:hover {
color:green
}
You can use the mark tag around the text
mark:hover {
background-color:green
}
mark
{
background-color:white
}
<ul class="sub-menu">
<li id="menu-item-1721" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1721"><mark>Strategic IT Consulting</mark></li>
I want to change the text of the 3 sub-menu items (under portfolio in the main navigation) on my site to blue. They are currently white and the same color as the background --> www.ronanmart.in
Here is the HTML of the navigation
<div class="menu-main-navigation-container"><ul id="menu-main-navigation" class="menu"><li id="menu-item-166" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-166">Blog</li>
<li id="menu-item-168" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-168">Portfolio
<a class="expand" href="#"></a>
<ul class="sub-menu">
<li id="menu-item-342" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-342">Digital Marketing</li>
<li id="menu-item-339" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-339">Creative Media</li>
<li id="menu-item-476" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-476">Ubikwitty</li>
</ul>
</li>
<li id="menu-item-172" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-172">About</li>
<li id="menu-item-171" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-171">Contact</li>
</ul></div>
I added the following CSS, thinking that specificity would do the trick but it didn't update.
#menu-item-342 {
color: #4486bf;
}
#menu-item-339 {
color: #4486bf;
}
#menu-item-476 {
color: #4486bf;
}
Feels like I'm missing something obvious but can't figure it out.
Thanks
Okay great. You are almost there. You just need to target <a>. The reason is you need to give the colour for the links and they don't automatically inherit like the other elements do. Change your code to either of the below:
#menu-item-342 a {
color: #4486bf;
}
#menu-item-339 a {
color: #4486bf;
}
#menu-item-476 a {
color: #4486bf;
}
Also, note that since you have same definition, you can combine them all:
#menu-item-342 a,
#menu-item-339 a,
#menu-item-476 a {
color: #4486bf;
}
Preview
What you need is the following:
ul.submenu li a {
color: blue;
}
Use
#menu-item-342 a, #menu-item-339 a, #menu-item-476 a {
color: #4486bf;
}
Basically, the navbar works perfectly, it stays statically stuck to the top of the screen when the user scrolls. When it is text-only, everything works fine. When I want to add the Twitter and Facebook icons, I can simply do so and it will work. However, as soon as I add an <a href="#"> to enclose the image, it breaks completely. Occasionally, the navbar will work even with the image links, but around 90% of the time it will simply fail, the navbar will not appear, and even though Inspect Element reveals that it should be loaded, nothing is shown.
Relevant:
Working HTML
<div class="" id="header">
<ul class="menu">
<li class="menu-item first">Gallery</li>
<li class="menu-item second">Charity</li>
<li class="menu-item third">About Me</li>
<li class="menu-item fourth">Contact</li>
<li class="menu-item media"><img src="TaiwanSite_files/twitter.png" height="25">
<img src="TaiwanSite_files/fb.png" height="25"></li>
<li class="menu-top">
<img src="TaiwanSite_files/top-arrow.svg" height="61" width="61">
</li>
</ul>
</div>
Broken HTML
<div class="" id="header">
<ul class="menu">
<li class="menu-item first">Gallery</li>
<li class="menu-item second">Charity</li>
<li class="menu-item third">About Me</li>
<li class="menu-item fourth">Contact</li>
<li class="menu-item media"><img src="TaiwanSite_files/twitter.png" height="25">
<img src="TaiwanSite_files/fb.png" height="25"></li>
<li class="menu-top">
<img src="TaiwanSite_files/top-arrow.svg" height="61" width="61">
</li>
</ul>
</div>
The relevant CSS:
.menu {
padding:0;margin:0 auto;position:relative;max-width:1024px;height:2.4em;padding-left:62px;padding-right:62px
}
.menu:after {
display:block;content:"";clear:both
}
.menu-logo {
position:absolute;top:.18em;left:0;right:0;text-align:center;z-index:-1
}
.menu-logo img {
width:4.8em;margin:0;padding:0
}
.menu-item {
display:block;float:left;min-width:20%;text-align:right;height:1.2em;margin-top:.58em
}
.menu-item.first {
text-align:left
}
.menu-item.second {
text-align:left
}
.menu-item.third {
text-align:left
}
.menu-item.fourth {
text-align:left
}
.menu-item.media {
float:right;text-align:right
}
.menu-item a {
text-decoration:inherit;font-family:inherit;color:inherit;font-weight:inherit;line-height:inherit;display:none
}
If there is any additional information I can provide at this time, please inform me and I will try my best to do so. Thank you very much in advance for your time and assistance.
Add a special class to your a tags (in this case on):
<a class="on" href="https://twitter.com/">
<img src="TaiwanSite_files/twitter.png" height="25"></a>
<a class="on" href="https://facebook.com/">
<img src="TaiwanSite_files/fb.png" height="25"></a>
Then add this to your styling:
.on {
display: inline-block !important;
}
for the images to display side-by-side, or this:
.on {
display: block !important;
}
for the images to be one on top of the other.
This should help.
I have a little problem with my vertical navigation:
<div class="menu-container">
<ul>
<li>Menu1
<ul class="sub-menu">
<li>Submenu1</li>
<li>Submenu2</li>
<li>Submenu3</li>
</ul>
</li>
...
</div>
My CSS:
.menu-container a{
text-decoration:none;
color:black;
}
.menu-container a:hover{
font-weight:bold;
}
.menu-container li:hover > .sub-menu{
display:block;
}
.sub-menu{
display:none;
list-style-type:none;
padding:6px;
}
ul.sub-menu a{
text-decoration:none;
}
.menu-container > ul.sub-menu a{
display:block;
background:#ddd;
}
.menu-container > .sub-menu:active{
display:block;
background:#ddd;
}
If I hover the menu the sub-menu show up. Now, in addition I would like, that if e.g. the submenu1 is active that the whole submenu stays openend. Can I realize that with CSS?
Greets,
Yab86
Here's an example using PHP. You need to create a page variable before the <html> like this:
<?php $page = 'menu1'; ?>
<html>
<!-- rest of HTML below here-->
That php code gets put on top of every submenu page that shares a common main parent menu. So in your example, submenu1, submenu2, and submenu3 would have the same variable. In this example, menu1. What this does, is allows you to add a CSS class of current to the submenu parent ul.
Here's the HTML with the PHP in place:
<?php $page = "menu1"?>
<html>
<head></head>
<body>
<div class="menu-container">
<ul>
<li>Menu1
<ul class="sub-menu <?php if($page == 'menu1')echo 'current'; ?>">
<li>Submenu1</li>
<li>Submenu2</li>
<li>Submenu3</li>
</ul>
</li>
<li>Menu2
<ul class="sub-menu <?php if($page == 'menu2')echo 'current'; ?>">
<li>Submenu4</li>
<li>Submenu5</li>
<li>Submenu6</li>
</ul>
</li>
</ul>
</div>
</body>
</html>
And here's the CSS that would keep it open:
.menu-container li:hover > .sub-menu,
.menu-container .current {
display:block;
}
When the HTML outputs to the browser, this is what it would actually look like if you were on any of the submenu1,2,3 pages:
<div class="menu-container">
<ul>
<li>Menu1
<ul class="sub-menu current">
<li>Submenu1</li>
<li>Submenu2</li>
<li>Submenu3</li>
</ul>
</li>
<li>Menu2
<ul class="sub-menu">
<li>Submenu4</li>
<li>Submenu5</li>
<li>Submenu6</li>
</ul>
</li>
</ul>
</div>
Hopefully this helps you out.
i creat a dropdown list when mouse hover at #clim the height of #dropdown change from 0 to 150px . but the code not work .
html code
<div id="menu">
<ul>
<li id="index">Accueil</li>
<li id="clim">Climatisation</li>
<li id="ventil">Ventilation</li>
<li id="electro">Electromenager</li>
</ul>
</div>
</div>
<div id="dropdown" >
<ul>
<li id="index">Climatisation</li>
<li id="clim">Ventilation</li>
</ul>
</div>
CSS code
#dropdown{
margin-left:693px;
width:165px;
height:0px;
position:absolute;
background:#158DFB;
overflow:hidden;
-webkit-transition-duration:0.3s;
}
i have a problem in this part . not working
#clim:hover #dropdown{
height:150px;
}
first of all, your code has extra finishing tags and 2 elements with the same id (#clim), that doesn't make the question very clear.
to make this work with css and no javascript you have to include the hidden element (the dropdown) inside the outer element that you will hover and trigger the dropdown to be shown.
try this instead and then add the remaining css rules you need:
<div id="menu">
<ul>
<li id="one">Accueil</li>
<li id="two">
Climatisation
<ul id="dropdown">
<li id="subone">sub Link</li>
<li id="subtwo">Another sub link</li>
</ul>
</li>
<li id="three">Ventilation</li>
<li id="four">Electromenager</li>
</ul>
</div>
#dropdown{
height: 0;
overflow:hidden;
-webkit-transition-duration:0.3s;
}
#menu:hover #dropdown{
height:150px;
}
when mouse hover at #clim the height of #dropdown change
You cannot do that with pure CSS, because there is no parent selector.