Selection css tag without id - css

I need help with setting up a wordpress menu.
I made my html css but when I go under wordpress and when I use the wp_nav_menu () function I lose my specific id on <a> tags, Wordpress automatically generates new <li> <a>.
How can I select them from the class "menu_word" please?
<ul class="menu_word">
<li><a id="home" href="#">Tilte1</a></li>
<li>Tilte2</li>
<li>Tilte3</li>
<li>Tilte4</li>
<li><a id="sem" href="#">Tilte4</a></li>
<li>Tilte5</li>
</ul>

There you go
body .menu_word >li:nth-child(1)> a{ /*Title1 on pos 1 (specific for first level of menu)*/
border:1px solid red;
}
body .menu_word >li:nth-child(2)> a{ /*Title2 on pos 2 (specific for first level of menu)*/
border:1px solid blue;
}
<ul class="menu_word">
<li><a id="home" href="#">Tilte1</a></li>
<li>Tilte2</li>
<li>Tilte3</li>
<li>Tilte4</li>
<li><a id="sem" href="#">Tilte4</a></li>
<li>Tilte5</li>
</ul>

Can you add a class and target that?
If not, this will work, although its pretty brittle. It'll become more robust if you can add a class to the UL, but if you can add a class, you may as well add it to the <a> tag, or the <li> tag.
body > ul > li:nth-child(1) > a

Thank you for your answers, I also find a solution that I share if it can help.
<ul class="menu_word">
<li><a id="home" href="home">Tilte1</a></li>
<li>Tilte2</li>
<li>Tilte3</li>
<li>Tilte4</li>
<li><a id="sem" href="sem">Tilte4</a></li>
<li>Tilte5</li>
</ul>
a[href*="home"]{
font-weight: 800;
font-size: 1.2em;
}
a[href*="sem"]{
text-transform: capitalize;
}

Related

How can I select the first link in my menu without selecting the other links inside the dropdown?

I'm having trouble figuring out how to solve this CSS problem.
The code is create by a WordPress plugin so have limited possibilities when it comes to naming the classes and so on.
This is the code:
<li class="page_item page-item-365 page_item_has_children current_page_item has_children”>
<a href="http://www.xxx.dk/side1/side2/“>Side 2</a>
<ul class="children">
<li class="page_item page-item-556”>
<a href="http://www.xxx.dk/“>punkt 1</a>
</li>
<li class="page_item page-item-556”>
<a href="http://www.xxx.dk/“>punkt 1</a>
</li>
<li class="page_item page-item-556”>
<a href="http://www.xxx.dk/“>punkt 1</a>
</li>
</ul>
</li>
The problem is that all of my links become bold when I'm styling them. I only want it to happen on the current page (selected page). I have tried with the following CSS code, but without luck:
li.current_page_item a:first-child {
font-weight: bold;
}
I believe I found a solution - dont know if I understand it but it works ;)
.current_page_item > a {
font-weight: bold;
}
In your case, every a is the first child of a li.
What you are searching for is:
li.current_page_item a {
Furthermore all of your menu entries link to the same id. So I guess every of it get the "current" class, if one is selected. Add some other links to the menu and you will see, that it will work!
You were close to the solution ;-)
Have a look here, is this what you looking for?
li.current_page_item > a:first-child {
font-weight: bold;
}
Example on Codepen:
http://codepen.io/funkysoul/pen/XNVdbE
please recheck your code. refer the screenshot.

display of only one "li" among number of "li" tags having same class based on mouse function

Myself in the beginning stages of javascript want to achieve the following.Say I had some li tags which are further included with some li tags like this.
<ul>
<li>
<ul>
<li class="2"></li>
<li class="2"></li>
<li class="2"></li>
</ul>
</li>
<li>
<ul>
<li class="2"></li>
<li class="2"></li>
<li class="2"></li>
</ul>
</li>
</ul>
Now class 2 block is hidden originally in the page.My work is when someone hovers on a link of class 1 its respective block ( i.e., class 2) should display.But the code i had written is displaying all blocks having class 2
May be i can write a mouseover() function for each link of class 1,but is it correct?I had seen this type effect in some sites like linked in,awwwards.com
Example link is
Best Colorful Websites | Web Design Inspiration
In this link when mouse is hovered on a image,then for only on that image a symbol is display on corner bottomI want this type effect.
Can any please help me??Thanks in advance??
Well this can be achived with css only:
ul ul{
display:none;
}
ul > li:hover ul{
display:block;
}
try a fast css solution (not tested because you did not put a jsFiffle code axample)
ul li:hover ul li.2
{
display:block;
}
also, do not use only numbers in class names... will not work on some browsers
try class="c2" at least

css selector java server faces tags

I'm implementing a dropdown list with jsf tags (commandLinks).
I have question about css selector in jsf.
When I hover on a commandLink class "about" I want to change font color of the other 2 commandLinks to red.
Here is my attempt:
In css file
.about:hover .sub{
color: red;
}
<h:commandLink styleClass="about" value="About us ▾" action="/about"/>
<h:commandLink styleClass="sub" value="test1" action="/customers"/>
<h:commandLink styleClass="sub" value="test2" action="/license" />
but nothing changes. I also tried this
.about:hover > .sub{
color: red;
}
It didn't work either.
You are missing things in your menu, you need to understand the parent / children concept. The css selector .about .sub will select childrens sub with a parent about. In your case you have no hierarchy at all.
Almost all menus are using this simple concept :
<ul>
<li class="about">
<h:commandLink value="About us ▾" action="/about"/>
<ul class="sub">
<li><h:commandLink value="test1" action="/customers"/></li>
<li><h:commandLink value="test2" action="/license" /></li>
</ul>
</li>
<!-- ... other top level menus ... -->
</ul>
Now your css selector will work :
.about:hover > .sub {
color: red;
}

Different behavior in different browsers with neither yielding the desired result

I'm wanting the text in the navigation bar to display a different color when the user is on that page so the user knows where they are. I can get this to work in all the browsers with just a single page, but things get funny when I start working with the children pages. In Chrome the parent page, a placeholder link (active4) responds but so do all the children pages (active4a-c), in both IE and Mozilla the individual child page (active4a) responds but the parent page (active4) doesn't. The CSS for these classes are in an internal style sheet so once you leave the page the links revert to the style in the external style sheet.
<li class="active4" ><a href="#" >Reviewers</a>
<ul>
<li class="active4a">Reviewer Information</li>
<li class="active4b" ><a href="#" >How</a></li>
<li class="active4c"><a href="#" >Future</a></li>
</ul>
</li>
.active4 a:visited {
color:#6206F7;
}
.active4a a:visited {
color:#6206F7;
}
I don't think the :visited pseudo-selector is what you want. This selects the <a> tag after it has been visited even once. So, once a visitor clicks on the link, it will always be the new color. Instead, try creating an active class that only selects <a> elements that are children. Here is some working code:
<!doctype html>
<html>
<head>
<style>
a:link {
color:blue;
}
a:visited {
color:blue;
}
.active > a:link {
color:red;
}
.active > a:visited {
color:red;
}
</style>
</head>
<body>
<ul>
<li class="active" ><a href="#" >Reviewers</a>
<ul>
<li class="active">Reviewer Information</li>
<li><a href="#" >How</a></li>
<li><a href="#" >Future</a></li>
</ul>
</li>
</ul>
</body>
</html>
The one thing I want to point out is the > between the .active and the a:link. This selects only <a> tags that are children of the .active. If you omit this, it will select all descendents which will lead to the problem you were having earlier.

CSS - Style the last 3 li of an ul

I have an ul with 7 li inside of it. I know that I can style the first and last li but is it possible to style the last 3 li's so the text is a different colour? This is the first time I have come across this problem/dilemma. I have googled around a bit and have not found much that is really helping me.
<div class="international-portfolio">
<div class="international-portfolio-title"> Sales Representation International</div>
<ul class="nobullet inline int-portfolio ">
<li class="excelsior-hotel-ernst first">
<li class="le-mas-candille">
<li class="mandarin-oriental-hotel-group-worldwide">
<li class="victoria-jungfrau-grand-hotel-spa">
<li class="palace-luzern">
<li class="eden-au-lac">
<li class="bellevue-palace last">
</ul>
</div>
ive updated the coding - trying the solutions given but not working at the moment but will keep at it.
This should do the trick (but mind you, it won't work in older versions of IE):
http://reference.sitepoint.com/css/pseudoclass-nthlastchild
Use the css selector as follows:
li:nth-last-child(-n+3) {
/*stuff here*/
}
Here's an example, too:
http://jsfiddle.net/yAUwb/
You can use:
li:nth-last-child(1), li:nth-last-child(2), li:nth-last-child(3) {
color: red;
}
It is kinda of possible with this code
.myList li:nth-last-child(1),
.myList li:nth-last-child(2),
.myList li:nth-last-child(3)
{
color: red;
}
Demo: http://jsfiddle.net/2np58/

Resources