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>
Related
In my code, there are list items and they all have a category. Each categories are sequentially added for each list items.
Here is my HTML:
HTML
<ul>
<li class='A'>A1</li>
<li class='A'>A2</li>
<li class='A'>A3</li>
<li class='A'>A4</li>
<li class='B'>B1</li>
<li class='B'>B2</li>
<li class='B'>B3</li>
<li class='B'>B4</li>
<li class='C'>C1</li>
<li class='C'>C2</li>
<li class='C'>C3</li>
<li class='C'>C4</li>
</ul>
CSS
ul li{display:none}
ul li.A:nth-of-type(1){display:block}
ul li.B:nth-of-type(1){display:block}
ul li.C:nth-of-type(1){display:block}
I am trying to display only the first element of each category. I am expecting below output:
A1
B1
C1
Here is my fiddle - https://jsfiddle.net/9pdby6st/200/
I observed that nth-of-type works only when the very first element is that category.
Here are the limitations:
Cannot change html structure
Cannot use javascript
Can use SCSS. Any advice?
You could use the adjacent sibling selector + for the elements that end with a class name and start the next tag with another class name.
Eg: .A + .B {display: block}
In the above case, only one instance is possible and the first element with the classname B displays and the other siblings are hidden.
You could use it to create many combos such as .B + .C {display: block} and so on.
JSFiddle link
ul li {
display: none
}
ul li.A:first-child {
display: block
}
ul li.A+.B {
display: block
}
ul li.B+.C {
display: block
}
<ul>
<li class='A'>A1</li>
<li class='A'>A2</li>
<li class='A'>A3</li>
<li class='A'>A4</li>
<li class='B'>B1</li>
<li class='B'>B2</li>
<li class='B'>B3</li>
<li class='B'>B4</li>
<li class='C'>C1</li>
<li class='C'>C2</li>
<li class='C'>C3</li>
<li class='C'>C4</li>
</ul>
As seen here: https://stackoverflow.com/a/8539107/1423096
You can set the property for all the items and then undo it for the siblings that come after the first one.
ul li {
color: red
}
ul li.A:nth-of-type(1) {
color: blue
}
ul>li.B {
color: green
}
ul>li.B~li.B {
color: red
}
ul>li.C {
color: yellow
}
ul>li.C~li.C {
color: red
}
<ul>
<li class='A'>A1</li>
<li class='A'>A2</li>
<li class='A'>A3</li>
<li class='A'>A4</li>
<li class='B'>B1</li>
<li class='B'>B2</li>
<li class='B'>B3</li>
<li class='B'>B4</li>
<li class='C'>C1</li>
<li class='C'>C2</li>
<li class='C'>C3</li>
<li class='C'>C4</li>
</ul>
Try this (inspired by alo Malbarez answer)
ul li{display:block}
ul>li.A~li.A {display: none}
ul>li.B~li.B {display: none}
ul>li.C~li.C {display: none}
<ul>
<li class='A'>A1</li>
<li class='A'>A2</li>
<li class='A'>A3</li>
<li class='A'>A4</li>
<li class='B'>B1</li>
<li class='B'>B2</li>
<li class='B'>B3</li>
<li class='B'>B4</li>
<li class='C'>C1</li>
<li class='C'>C2</li>
<li class='C'>C3</li>
<li class='C'>C4</li>
</ul>
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'm using [class*="menu-class-"]:not(.menu-class-2) for my <li> elements, it works properly. The problem is when I want to point to the <a> tag inside the <li>, [class*="menu-class-"]:not(.menu-class-2) a. For some reason it doesn't work.
CSS:
.nav-menu .menu-class > .sub-menu li[class*="menu-class-"]:not(.menu-class-2) {
display: table-cell;
}
.nav-menu .menu-class > .sub-menu li[class*="menu-class-"]:not(.menu-class-2) a {
text-transform: uppercase;
}
HTML
<ul class="nav-menu" id="menu-main-navigation">
<li class="menu-class">
Nav 1
<ul class="sub-menu">
<li class="menu-class-3">
Nav 2
<ul class="sub-menu">
<li class="menu-class-2">Anchor, it should be lowercase</li>
</ul>
</li>
</ul>
</li>
</ul>
The problem is the <a> inside the <li class="menu-class-2"> is uppercase, but it should be lowercase, because I didn't add any property for this element. The container of the <a> (<li class="menu-class-2">), didn't get the display:table-cell property, so it works properly.
The JSFiddle link: http://jsfiddle.net/qnzos5t4/3/
The reason is because you do have a li that is not .menu-class-2:
<ul class="nav-menu" id="menu-main-navigation">
<li class="menu-class">
Nav 1
<ul class="sub-menu">
<li class="menu-class-3"> <!-- THIS ONE HERE -->
Nav 2
<ul class="sub-menu">
<li class="menu-class-2">Anchor, it should be lowercase</li>
</ul>
</li>
</ul>
</li>
</ul>
Since your css rule is using a whitespace to select the anchor after the li, every <a> descendant of it, will be uppercase. You need to use a child selector:
Updated JsFiddle
.nav-menu .menu-class > .sub-menu li[class*="menu-class-"]:not(.menu-class-2) > a {
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.