We have nested unordered lists with product data.
For
<ul class="data_holder">
we want odd/even background colors.
ul.data_holder:odd => background: #ccc
ul.data_holder:even => background: #FFF
Our whole structure looks like this (as you see, our ul.data_holder sits inside an "li" element of the parent unordered list:
<ul class="row_holder">
<li class="row">
<ul class="data_holder">
<li class="data">Data 1</li><li class="data">Data 2</li><li class="data">Data 3</li>
</ul>
</li>
<li class="row">
<ul class="data_holder">
<li class="data">Data 1</li><li class="data">Data 2</li><li class="data">Data 3</li>
</ul>
</li>
<li class="row">
<ul class="data_holder">
<li class="data">Data 1</li><li class="data">Data 2</li><li class="data">Data 3</li>
</ul>
</li>
<li class="row">
<ul class="data_holder">
<li class="data">Data 1</li><li class="data">Data 2</li><li class="data">Data 3</li>
</ul>
</li>
</ul>
Thanks for help
You need to apply a CSS to the li, not to the ul which is inside the li. Try Below CSS:
ul.row_holder li:nth-child(odd) ul{
background-color:red;
}
ul.row_holder li:nth-child(even) ul{
background-color:black;
}
You can use the following CSS structure, nth-child(odd/even). With this code, you'll be able to have different stylings for odd/even objects in a list like this unordered list. Since you have a first <ul> with <li> elements inside, I would suggest you do this selector on the .row elements in your HTML.
.row:nth-child(odd) {
background: #ccc;
}
.row:nth-child(even) {
background: #fff;
}
Related
CSS:
border: 5px solid red;
}
#menu li{
font-size: 25px;
display:inline;
}
HTML:
<div class="container-fluid">
<div class="row">
<div class="col-lg-2" id="menu">
<ul class ="Menuitems">
<li>The Hub</li>
<li>FAQ</li>
</ul>
</div>
I am attempting to move the text in the li tags to the centre of the div. I cannot figure out the CSS to do so and I don't wish to use "position relative" "top: 5px" because it is bad practise and will mess up the responsive design element of the project. Text align is also not possible as the div is not large when it is full screen, see code pen for information
https://codepen.io/mdot700/pen/bGEGwLa
Found this with bootstrap
Source : https://www.codeply.com/go/bp/6COUMfNrEU
<div class="d-flex">
<ul class="list-inline mx-auto justify-content-center">
<li class="list-block-item">Item 1</li>
<li class="list-block-item">Item 2</li>
<li class="list-block-item">Item 3</li>
<li class="list-block-item">Item 4</li>
<li class="list-block-item">Item 5</li>
</ul>
</div>
Here i have the menu structure, what am i trying to do is that, when i click the parent level item or any sub menu item the class active is going to get added to the menu which is clicked.
i want to change the color of only the parent menu item but not the sub menu item, how can i do that. right now what is happening is that i have applied css, but its getting applied to parent menu as well as the child menu items.
.center-in-menu {
&:not(div.we-mega-menu-submenu) {
.we-mega-menu-li.active {
a {
color: blue !important;
}
}
}
}
<ul class="nav-tabs center-in-menu">
<li class="we-mega-menu-li dropdown-menu">
Menu 1
<div class="we-mega-menu-submenu">
<ul class="nav-tabs">
<li class="we-mega-menu-li">submenu1</li>
<li class="we-mega-menu-li dropdown-menu">submenu2</li>
<div class="we-mega-menu-submenu">
<ul class="nav-tabs">
<li class="we-mega-menu-li">submenu1</li>
<li class="we-mega-menu-li">submenu1</li>
<li class="we-mega-menu-li">submenu1</li>
<li class="we-mega-menu-li">submenu1</li>
<li class="we-mega-menu-li">submenu1</li>
</ul>
</div>
<li class="we-mega-menu-li">submenu3</li>
<li class="we-mega-menu-li">submenu4</li>
<li class="we-mega-menu-li">submenu5</li>
</ul>
</div>
<li class="we-mega-menu-li">Menu 2</li>
<li class="we-mega-menu-li">Menu 3</li>
<li class="we-mega-menu-li dropdown-menu">
Menu 4
<div class="we-mega-menu-submenu">
<ul class="nav-tabs">
<li class="we-mega-menu-li">submenu1</li>
<li class="we-mega-menu-li active dropdown-menu">submenu2</li>
<div class="we-mega-menu-submenu">
<ul class="nav-tabs">
<li class="we-mega-menu-li active">submenu1</li>
<li class="we-mega-menu-li">submenu2</li>
<li class="we-mega-menu-li">submenu3</li>
<li class="we-mega-menu-li">submenu4</li>
<li class="we-mega-menu-li">submenu5</li>
</ul>
</div>
<li class="we-mega-menu-li">submenu3</li>
<li class="we-mega-menu-li">submenu4</li>
<li class="we-mega-menu-li">submenu5</li>
</ul>
</div>
</li>
<li class="we-mega-menu-li">Menu 5</li>
</ul>
Example here
https://codepen.io/Chandanay/pen/YzKJNEE
Use > to apply styles only to elements inside the given selector without going deeper any further.
Here's an example:
div.wrapper > a { /* only applied to direct children */
font-weight: bold;
}
div.inner a {
font-style: italic;
}
<div class="wrapper">
<a>1st Level (Bold)</a>
<div class="inner">
<a>2nd Level (Italic)</a>
</div>
<div class="noclass">
<a>2nd Level (No style)</a>
</div>
</div>
I have a dropdown menu with a sub-menu, made up of lists:
<ul>
<li class="list_item">Item 1</li>
<li class="list_item">Item 2</li>
<ul>
<li class="sub_list_item">Sub Item 1</li>
<li class="sub_list_item">Sub Item 2</li>
</ul>
<li class="list_item">Item 3</li>
</ul>
My CSS changes the background-color of these items when hovered on.
What I want to do is keep Item 2's background color changed whilst hovering over any give Sub Item
Any simple way to do this?
CSS:
.list_item:hover {
background-color:green;
}
.sub_list_item:hover {
background-color:yellow;
}
Wrap item 2 around its <ul> tag
<ul>
<li class="list_item">Item 1</li>
<li class="list_item">Item 2
<ul>
<li class="sub_list_item">Sub Item 1</li>
<li class="sub_list_item">Sub Item 2</li>
</ul>
</li>
<li class="list_item">Item 3</li>
</ul>
You could use the direct child selector > to target a specific li as opposed any given li or ul.
jsFiddle here - menu I made a few weeks ago
Usage example:
#menu > ul > li:hover {
background: #2580a2;
}
Change the code and css
<ul class="item">
<li class="list_item">Item 1</li>
<li class="list_item">Item 2</li>
<ul>
<li class="sub_list_item">Sub Item 1</li>
<li class="sub_list_item">Sub Item 2</li>
</ul>
<li class="list_item">Item 3</li>
</ul>
CSS is
.item
{
color: #000000;
list-style-type: disc;
}
.item li:hover
{
color: #FFFFFF;
background-color: #336600;
}
.item ul li:hover
{
color: #FFFFFF;
background-color: #FF0000;
}
Enjoy ... and choose your color whatever you like
for more detail visit ..
http://www.mr-sudhir.com/blog/what-is-css.aspx
How can I make the menu-category color attribute change to orange when hovered and NOT remain orange while hovering other child items? Is this too tricky or am I not being clear enough? Please let me know. Thank you for help.
jsFiddle: http://jsfiddle.net/LmWk2/
<nav class="main-nav">
<ul>
<li class="menu-category">Title 1
<ul>
<li class="menu-item">Item 1</li>
<li class="menu-item">Item 2</li>
<li class="menu-item">Item 3</li>
<li class="menu-item">Item 4</li>
</ul>
</li>
<li class="menu-category">Title 2
<ul>
<li class="menu-item">Item 1</li>
<li class="menu-item">Item 2</li>
<li class="menu-item">Item 3</li>
<li class="menu-item">Item 4</li>
<li class="menu-item">Item 5</li>
</ul>
</li>
<li class="menu-category">Title 3
<ul>
<li class="menu-item">Item 1</li>
<li class="menu-item">Item 2</li>
<li class="menu-item">Item 3</li>
<li class="menu-item">Item 4</li>
<li class="menu-item">Item 5</li>
</ul>
</li>
<li class="menu-category">Title 4
<ul>
<li class="menu-item">Item 1</li>
<li class="menu-item">Item 2</li>
<li class="menu-item">Item 3</li>
<li class="menu-item">Item 4</li>
</ul>
</li>
</ul>
</nav>
The simplest way would be to add another element that wraps only the title:
<li class="menu-category"><span class="menu-category-title">Title 1</span>
.menu-category-title:hover {
color: orange;
}
http://jsfiddle.net/ExplosionPIlls/LmWk2/1/ (for TITLE1)
My answer addresses the color-change-on-hover issue and the related issue of making the links behave like buttons (block like) instead of text links.
As pointed out by a previous post, it is a good idea to wrap the title tag in a container, I chose h4 but almost anything will do. Also, for semantic reasons, but the link tags inside the list-item tags:
<nav class="main-nav">
<ul>
<li class="menu-category"><h4>Title 1</h4>
<ul>
<li class="menu-item">Item 1</li>
<li class="menu-item">Item 2</li>
<li class="menu-item">Item 3</li>
<li class="menu-item">Item 4</li>
</ul>
</li>
...
...
...
</ul>
</nav>
The essential changes to the CSS are as follows.
For the title text:
.main-nav ul li.menu-category h4 {
margin: 0;
display: inline-block;
padding:5px 15px 8px 15px;
font-weight: normal;
}
.main-nav ul li.menu-category h4:hover {
color:#FB8521;
}
The trick here is to set display: inline-block to the element wrapping the title text. Because I chose to use h4, I needed to zero out the margin and set the font-weight to normal to keep with your previous styling. Also, add padding to make the text area large so you can trigger the hover effect without actually mousing over the text.
For the sub-menu items, set the a tags to have display: block, that way the link's active area fills up the width of the sub-menu panel. Add padding as needed.
.menu-category .menu-item a {
display: block;
padding: 5px 15px;
}
.menu-category .menu-item a:hover {
color:#FB8521;
}
You can see the working demo at: http://jsfiddle.net/audetwebdesign/jvgkG/
PS
There is flexibility in this layout with regards to how the hover works. I assumed that the title text reverts to white when you mouse onto the secondary menu items, but I could set it up so that the title remains orange as you move over the secondary menu.
Also, you can style the default link color as you see fit.
Code:
<div class="menu">
<ul class="top_thing">
<li class="one_one">Services</li>
<ul class="the_one">
<li class="second">Language 1</li>
<li class="second">Language 2</li>
<li class="second">Language 3</li>
<li class="second">Language 4</li>
<li class="second">Language 5</li>
</ul>
<li class="one_one">About Us</li>
<li class="one_one">Contact</li>
</ul>
</div>
For CSS: I am using display:none on .the_one. Now once the services tab is hovered I want to then display .the_one. How can I do this? I tried doing:
li.the_one:hover {
display:block;
}
But that doesn't work either.
Your HTML is not valid. <ul> must have only <li> as children (and that includes other <ul>. Once you fix that, add these rules:
.the_one {
display: none;
}
.one_one:hover .the_one {
display: block;
}
http://jsfiddle.net/xvEvj/
You need to target the the inner list in your css to make it appear.
Change your css as below:
li.the_one:hover ul.the_one
{
display:block
}
the "li.the_one:hover" states that this will occur when the li with the class "the_one" is hovered over, then it applies a display:block to the ul with the class "the_one" inside the list item with the class "the_one".
Hope this helps.
Cheers.
Your HTML is not valid.
<div class="menu">
<ul class="top_thing">
<li class="one_one">Services
<ul class="the_one">
<li class="second">Language 1</li>
<li class="second">Language 2</li>
<li class="second">Language 3</li>
<li class="second">Language 4</li>
<li class="second">Language 5</li>
</ul>
</li>
<li class="one_one">About Us</li>
<li class="one_one">Contact</li>
</ul>
The second unordered list should rest within a list item of the first unordered list.