Instead of adding a individual class to each list items, is there a way to add a single class to a whole set of list item at once?
CSS
<li class="foot_nav">Home</li>
<li class="foot_nav">Discovery</li>
<li class="foot_nav">Subjects</li>
<li class="foot_nav">Guide</li>
<li class="foot_nav">About us</li>
Thanks
It's only one way - JS. Jquery for example:
$('li').addClass('foot_nav');
Just add a class to parent and use child selector:
.foot_nav li {
display: inline-block;
}
<ul class="foot_nav">
<li>Home</li>
<li>Discovery</li>
<li>Subjects</li>
<li>Guide</li>
<li>About us</li>
</ul>
apply the class to the entire ul and then targeth the ul li using CSS
.foot_nav{list-style:none}
.foot_nav li:nth-child(even) {background:red}
.foot_nav li:nth-child(odd) {background:yellow}
<ul class="foot_nav">
<li>Home</li>
<li>Discovery</li>
<li>Subjects</li>
<li>Guide</li>
<li>About us</li>
</ul>
<ul class="foot_nav">
<li>Home</li>
<li>Discovery</li>
<li>Subjects</li>
<li>Guide</li>
<li>About us</li>
</ul>
//css
.foot_nav li{//styling}
What do you need it for?
Maybe you should add the class to its parent.
<ul class="foot_nav">
<li></li>
…
</ul>
.foot_nav
{
list-style-type:none;
}
.foot_nav li
{
display:inline-block;
}
<ul class="foot_nav">
<li >Home</li>
<li >Discovery</li>
<li >Subjects</li>
<li >Guide</li>
<li >About us</li>
</ul>
Something like this in JavaScript should do the trick:
var lis = document.querySelectorAll("li");
for(var i = 0; i < lis.length; i++){
lis[i].className = lis[i].className += " foot_nav"
}
Try this
.list-item li{
}
.list-item:nth-child(1){
}
.list-item:nth-child(2){
}
<ul class="list-item">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
Related
<div class="menu">
<ul>
<li>
<ul class="sub-menu">
<li>
<ul class="sub-menu">
<li></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
Could You please tell me how to target just first ul element with "sub-menu" class as on an example above? Every pseudo-class I know targets both "sub-menu" ul-s at the same time.
One option:
ul:not(.sub-menu) > li > .sub-menu {
...
}
I am running this simple "test" code to change the background color of the nested list<ul class="dropcontent"> by using :hover on parent <li class="drop">
.drop:hover .dropcontent {
background-color: yellow;
}
<body>
<ul id="nav">
<li>Home</li>
<li class="drop">Services</li>
<ul class="dropcontent">
<li>serv1</li>
<li>serv2</li>
<li>serv3</li>
<li>serv4</li>
<li>serv5</li>
</ul>
<li>Gallery</li>
<li>About</li>
<li>Get in Touch</li>
</ul>
</body>
Please someone explain what's wrong here.
.dropcontent is a sibling of .drop (not a descendant), so the selector .drop:hover .dropcontent will not target it.
To correct this, either move the closing </li> of .drop to after the closing </ul> of .dropcontent:
.drop:hover .dropcontent {
background-color: yellow;
}
<body>
<ul id="nav">
<li>Home</li>
<li class="drop">Services
<ul class="dropcontent">
<li>serv1</li>
<li>serv2</li>
<li>serv3</li>
<li>serv4</li>
<li>serv5</li>
</ul>
</li>
<li>Gallery</li>
<li>About</li>
<li>Get in Touch</li>
</ul>
</body>
Or make use of the adjacent sibling combinator (+) with the selector .drop:hover + .dropcontent:
.drop:hover + .dropcontent {
background-color: yellow;
}
<body>
<ul id="nav">
<li>Home</li>
<li class="drop">Services</li>
<ul class="dropcontent">
<li>serv1</li>
<li>serv2</li>
<li>serv3</li>
<li>serv4</li>
<li>serv5</li>
</ul>
<li>Gallery</li>
<li>About</li>
<li>Get in Touch</li>
</ul>
</body>
Note that the former will apply the hover while the child links are selected, while the latter will only apply the hover when .drop itself is selected.
Hi I want to select the "Link" in class beers only but It always select all the links from sub-menu. I try
.beers:first-child does not work
.beers a:nth-child(1) does not work
.beers a:first-of-type (this apply to all the links of sub-menu)
<ul>
<li class="beers"><a>Link</a> only here
<ul class="sub-menu">
<li ><a></a></li> not here
<li><a></a></li> not here
</ul>
</li>
<li ><a></a></li>
<li ><a></a></li>
</ul>
Please help me
If you want to use style for a
.beers > a{color:green;}
If you want to use for li you have override
li.beers{ color:green;}
li.beers ul li{ color:black;}
You can get first element from child as below:
<style>
.beers >a {
background-color:red;
}
You have to maintain the elements level. Try the below one.
.beers>a
.beers:first-child
to
.beers li:first-child
With:
<ul class="beers">
<li><a>Link</a> only here
<ul class="sub-menu">
<li ><a></a></li> not here
<li><a></a></li> not here
</ul>
</li>
<li ><a></a></li>
<li ><a></a></li>
I want to display 7-9 html links in one line, but whenever I add another link, the last link goes down and forms another row. I want to put them in one line.
like
<link1> <link2><link3><link4><link5><link6><link7>
<li>HOME
<li>Check In</li>
<li>Check Out</li>
<li>Re-Issue</li>
<li><!--movies er drop down-->
Student<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Approve</li>
<li>Fine</li>
<li>Check List</li>
<li>Department</li>
</ul>
</li>
<li>Faculty<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Books issued</li>
<li>Search</li>
</ul>
</li>
<li> SEARCH<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Student</li>
<li>Faculty</li>
<li>Books</li>
<li>History</li>
</ul>
Use these styles:
ul {
white-space: nowrap;
}
li {
vertical-align: top;
display: inline-block;
padding: 0em 0.5em;
}
.sub-menu li {
display: block;
}
Fiddle
In the list that you put them in make a class and then in css add to the class: display:inline;
example: http://jsfiddle.net/JoshuaHurlburt/34nzt2d1/
<ul class="links">
Google
Google1
Google2
Google3
</ul>
I have a question about my sitemap if you look at the code you see ul and li. But every UL is below the other and i want it to be side by side. Every new UL side by side. How doe i do this? Working with first-child? ( the sitemap is inside my )
Sitemap
<ul>
<li>Opleiding</li>
<ul>
<li>Visie & Beleid</li>
<li>Opbouw Studieprogramma</li>
<li>Competenties</li>
<li>Diploma</li>
<li>Beroepen</li>
</ul>
<li>Onderwijsprogramma</li>
<ul>
<li>Mededelingen</li>
<li>Uitagenda</li>
<li>Propedeuse</li>
<li>Verdieping 1</li>
<li>Verdieping 2</li>
<li>Afstuderen</li>
</ul>
<li>Organisatie</li>
<ul>
<li>Contact</li>
<li>Blog</li>
<li>Docenten</li>
<li>Onderwijsbureau</li>
<li>Stagebureau</li>
<li>Buitenlandbureau</li>
<li>Examencommissie</li>
<li>Decaan</li>
</ul>
<li>Stages en Projecten</li>
<ul>
<li>Stages</li>
<li>Projecten</li>
</ul>
</ul>
This is my CSS
footer{
width: 100%;
position: absolute;
top: 317%;
left: -10%;
background: lightgrey;
margin:10%;
padding: 2%;
}
Try display inline-block or float left on the ul's you want side by side. I recommend adding classes to make the styling easier
HTML:
<ul>
<li>Opleiding</li>
<ul class="sitemap">
<li>Visie & Beleid</li>
<li>Opbouw Studieprogramma</li>
<li>Competenties</li>
<li>Diploma</li>
<li>Beroepen</li>
</ul>
<li>Onderwijsprogramma</li>
<ul class="sitemap">
<li>Mededelingen</li>
<li>Uitagenda</li>
<li>Propedeuse</li>
<li>Verdieping 1</li>
<li>Verdieping 2</li>
<li>Afstuderen</li>
</ul>
<li>Organisatie</li>
<ul class="sitemap">
<li>Contact</li>
<li>Blog</li>
<li>Docenten</li>
<li>Onderwijsbureau</li>
<li>Stagebureau</li>
<li>Buitenlandbureau</li>
<li>Examencommissie</li>
<li>Decaan</li>
</ul>
<li>Stages en Projecten</li>
<ul class="sitemap">
<li>Stages</li>
<li>Projecten</li>
</ul>
</ul>
CSS:
footer .sitemap {
display: inline-block;
OR
float: left;
}
Well, for starters your markup is invald. If you want to nest ULs inside of another UL, it needs to be inside of an LI
<ul>
<li>Title
<ul>
<li>Sub-Title</li>
</ul>
</li>
</ul>
From there, you probably just need something like this:
footer > ul > li {
float:left;
width:50%;
}
http://jsfiddle.net/fTCY5/