Need to select the first-child [duplicate] - html

This question already has answers here:
What does the ">" (greater-than sign) CSS selector mean?
(8 answers)
Closed 3 years ago.
I need to center the first a element only.
Example : Text "Ajax" should be centered align, but text "Ajax Help" and Ajax Intro" should be left aligned. I need to implement it for all li element.
ul.child-sidebar-menu li.current_page_parent a:first-child {
position: absolute;
width: 100%;
text-align: center;
}
<ul class="child-sidebar-menu">
<li class="page_item page-item-21 current_page_ancestor current_page_parent has_children">
Ajax
<ul class="grandchild-sidebar-menu level-0 children">
<li class="page_item page-item-104 current_page_item">
Ajax help</li>
<li class="page_item page-item-54">Ajax Intro</li>
</ul>
</li>
<li class="page_item page-item-16">Angular JS</li>
<li class="page_item page-item-29">Jquery</li>
<li class="page_item page-item-31">Jason</li>
<li class="page_item page-item-37">React JS</li>
<li class="page_item page-item-39">Node JS</li>
</ul>

You're looking for the child combinator > to only select the a elements that are direct children of li.current_page_parent, and not the grandchildren.
Note that you won't actually need the :first-child pseudo-class in this case.
ul.child-sidebar-menu li.current_page_parent > a {
position: absolute;
width: 100%;
text-align: center;
}
<ul class="child-sidebar-menu">
<li class="page_item page-item-21 current_page_ancestor current_page_parent has_children">
Ajax
<ul class="grandchild-sidebar-menu level-0 children">
<li class="page_item page-item-104 current_page_item">
Ajax help</li>
<li class="page_item page-item-54">Ajax Intro</li>
</ul>
</li>
<li class="page_item page-item-16">Angular JS</li>
<li class="page_item page-item-29">Jquery</li>
<li class="page_item page-item-31">Jason</li>
<li class="page_item page-item-37">React JS</li>
<li class="page_item page-item-39">Node JS</li>
</ul>
Your other <li> elements don't have the .current_page_parent class, so you can either target .page_item > a if you want to target their (theoretical) children.

Related

Why is column-count rendering thin lines in Chrome on 4K screens?

I have found an odd rendering issue in Chrome when it deals with the column-count property on high resolution screens. I am seeing this on a 4K screen.
body {
background-color: #30271d;
font-family: arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-size: 18px;
line-height: 1.2em;
padding: 1em;
border: solid 1px gray;
}
a {
color: white;
text-decoration: none;
transition-property: color,background-color,border-color;
transition-duration: .2s;
transition-timing-function: linear;
}
.page-list {
margin: 0 !important;
display: block;
padding:0;
-webkit-column-count: 4;
column-count: 4;
}
.page-list .page_item {
padding: 0 !important;
list-style: none;
display: list-item;
}
.page-list .page_item a {
padding: .25em 0 !important;
display: block;
}
.dark-background .page-list .page_item a {
color: #FDF9F5;
font-weight: 400;
}
.page-list .children {
padding-left: 1em;
padding-bottom: .5em;
}
.page-list .page_item a:hover, .page-list .page_item a:focus {
color: #FFEB00;
}
.page-list .current_page_item {
opacity: .5;
}
#media screen and (max-width: 1000px) {
.page-list {
-webkit-column-count: 3;
column-count: 3;
}
}
#media screen and (max-width: 800px) {
.page-list {
-webkit-column-count: 2;
column-count: 2;
}
}
#media screen and (max-width: 480px) {
.page-list {
-webkit-column-count: 1;
column-count: 1;
}
}
<ul class="page-list ">
<li class="page_item page-item-172 page_item_has_children">Base Rock Minerals Locations
<ul class='children'>
<li class="page_item page-item-173">Base Rock Minerals</li>
<li class="page_item page-item-174">Bonne Terre, MO</li>
<li class="page_item page-item-175">Fruitland, MO</li>
</ul>
</li>
<li class="page_item page-item-169 page_item_has_children">BMC Sand Locations
<ul class='children'>
<li class="page_item page-item-170">BMC Sand, LLC</li>
<li class="page_item page-item-171">Old Monroe, MO</li>
</ul>
</li>
<li class="page_item page-item-163 page_item_has_children">BMC Stone Locations
<ul class='children'>
<li class="page_item page-item-164">BMC Stone</li>
<li class="page_item page-item-165">Defiance, MO</li>
<li class="page_item page-item-166">High Hill, MO</li>
<li class="page_item page-item-167">Warrenton, MO</li>
<li class="page_item page-item-168">Wright City, MO</li>
</ul>
</li>
<li class="page_item page-item-44">Eastern Missouri Concrete</li>
<li class="page_item page-item-141 page_item_has_children">Illinois Locations
<ul class='children'>
<li class="page_item page-item-142">Caseyville, IL</li>
<li class="page_item page-item-143">Columbia, IL</li>
<li class="page_item page-item-144">Hamel, IL</li>
<li class="page_item page-item-145">Lebanon, IL</li>
</ul>
</li>
<li class="page_item page-item-132 page_item_has_children">Missouri Locations
<ul class='children'>
<li class="page_item page-item-129">Arnold, MO</li>
<li class="page_item page-item-131">Chesterfield, MO</li>
<li class="page_item page-item-133">Chesterfield, MO (Gumbo)</li>
<li class="page_item page-item-134">Festus, MO</li>
<li class="page_item page-item-135">Maryland Heights, MO</li>
<li class="page_item page-item-136">O’Fallon, MO</li>
<li class="page_item page-item-137">St. Louis Downtown</li>
<li class="page_item page-item-128">Webster Groves, MO</li>
</ul>
</li>
<li class="page_item page-item-191">Ozark Building Materials</li>
<li class="page_item page-item-146 page_item_has_children">Politte Locations
<ul class='children'>
<li class="page_item page-item-148">Arcadia, MO</li>
<li class="page_item page-item-156">Bonne Terre, MO</li>
<li class="page_item page-item-157">Ellington, MO</li>
<li class="page_item page-item-158">Ellsinore, MO</li>
<li class="page_item page-item-159">Farmington, MO</li>
<li class="page_item page-item-147">Politte LLC</li>
<li class="page_item page-item-160">Potosi, MO</li>
<li class="page_item page-item-161">Van Buren, MO</li>
<li class="page_item page-item-162">Viburnum, MO</li>
</ul>
</li>
<li class="page_item page-item-149 page_item_has_children">RMC Locations
<ul class='children'>
<li class="page_item page-item-151">Fredericktown, MO</li>
<li class="page_item page-item-153">Perryville, MO</li>
<li class="page_item page-item-150">RMC, LLC</li>
<li class="page_item page-item-154">STE Genevieve, MO</li>
</ul>
</li>
<li class="page_item page-item-138 page_item_has_children current_page_ancestor current_page_parent">Rolla Locations
<ul class='children'>
<li class="page_item page-item-139 current_page_item">Rolla, MO</li>
<li class="page_item page-item-140">Salem, MO</li>
</ul>
</li>
</ul>
So when you hover over the links, you can sometimes see very thin white/gray lines appear around the <a>, <li> and <ul>, depending on what you are hovering over. Sometimes the lines persist, and sometimes they go away once you move the cursor elsewhere. These lines are pixel thin, and what I mean is they are smaller than a web 1px unit, they are one pixel on the 4K monitor. These are very thin and easy to miss! I recommend hovering over the links in the last column as that is where I see them most frequently.
Stranger still, it looks like the size of the browser window effects whether it appears and the intensity. I have two lower-res monitors as extra monitors hooked up to my main screen, and it appears for them as well, but when trying to recreate the issue on a single monitor that is not high-res, I cannot see the lines appear.
I am using Chrome version 68 but I've seen it in older versions as well.
Any ideas on what is happening?

CSS/HTML menu not showing correctly

I'm trying to create a 2-level menu where level 1 is displayed horisontally and level 2 is displayed vertically. No fancy folding, just a plain sitemap'ish menu.
How it looks now:
How I would like it to look:
my html:
<nav class="menu">
<ul class="lvl1">
<li class="lvl1">Lorem</li>
<ul class="lvl2">
<li class="lvl2">Vino</li>
<li class="lvl2">Fino</li>
<li class="lvl2">Dolce</li>
<li class="lvl2">Vita</li>
<li class="lvl2">Mamma Mia</li>
</ul>
<li class="lvl1">Ipsum</li>
<ul class="lvl2">
<li class="lvl2">Vino</li>
<li class="lvl2">Fino</li>
<li class="lvl2">Dolce</li>
<li class="lvl2">Vita</li>
<li class="lvl2">Mamma Mia</li>
</ul>
<li class="lvl1">Dolor</li>
<ul class="lvl2">
<li class="lvl2">Vino</li>
<li class="lvl2">Fino</li>
<li class="lvl2">Dolce</li>
<li class="lvl2">Vita</li>
<li class="lvl2">Mamma Mia</li>
</ul>
<li class="lvl1">Sit</li>
<ul class="lvl2">
<li class="lvl2">Vino</li>
<li class="lvl2">Fino</li>
<li class="lvl2">Dolce</li>
<li class="lvl2">Vita</li>
<li class="lvl2">Mamma Mia</li>
</ul>
<li class="lvl1">Amet</li>
<ul class="lvl2">
<li class="lvl2">Vino</li>
<li class="lvl2">Fino</li>
<li class="lvl2">Dolce</li>
<li class="lvl2">Vita</li>
<li class="lvl2">Mamma Mia</li>
</ul>
</ul>
</nav>
my css:
.menu ul {list-style: none; }
ul.lvl1 {display: table; }
li.lvl1 {display: table-cell; font: bold 1.8em BlenderHeavy; color: white; }
ul.lvl2 {display: block; }
li.lvl2 {display: block; font: normal 1.2em BlenderHeavy; color: silver; }
This is simple, I suppose, but I am a css rookie.
Your HTML is invalid.
Try it:
.menu ul {
list-style: none;
}
ul.lvl1 {
display: table;
}
li.lvl1 {
display: table-cell;
font: bold 1.8em BlenderHeavy;
color: white;
}
ul.lvl2 {
display: block;
}
li.lvl2 {
display: block;
font: normal 1.2rem BlenderHeavy;
color: silver;
}
ul ul {
padding: 0;
}
<nav class="menu">
<ul class="lvl1">
<li class="lvl1">Lorem
<ul class="lvl2">
<li class="lvl2">Vino
</li>
<li class="lvl2">Fino
</li>
<li class="lvl2">Dolce
</li>
<li class="lvl2">Vita
</li>
<li class="lvl2">Mamma Mia
</li>
</ul>
</li>
<li class="lvl1">Ipsum
<ul class="lvl2">
<li class="lvl2">Vino
</li>
<li class="lvl2">Fino
</li>
<li class="lvl2">Dolce
</li>
<li class="lvl2">Vita
</li>
<li class="lvl2">Mamma Mia
</li>
</ul>
</li>
<li class="lvl1">Dolor
<ul class="lvl2">
<li class="lvl2">Vino
</li>
<li class="lvl2">Fino
</li>
<li class="lvl2">Dolce
</li>
<li class="lvl2">Vita
</li>
<li class="lvl2">Mamma Mia
</li>
</ul>
</li>
<li class="lvl1">Sit
<ul class="lvl2">
<li class="lvl2">Vino
</li>
<li class="lvl2">Fino
</li>
<li class="lvl2">Dolce
</li>
<li class="lvl2">Vita
</li>
<li class="lvl2">Mamma Mia
</li>
</ul>
</li>
<li class="lvl1">Amet
<ul class="lvl2">
<li class="lvl2">Vino
</li>
<li class="lvl2">Fino
</li>
<li class="lvl2">Dolce
</li>
<li class="lvl2">Vita
</li>
<li class="lvl2">Mamma Mia
</li>
</ul>
</li>
</ul>
</nav>
edited your code in this Fiddle
use float:left will resolve your problem
hope this will help

SlickNav not correctly reading my nested structure

I'm using slickNav and its not properly reading my nested list.
This page is a repository for NPCS for a Table top RPG.
The top level is general information and organizes NPCs by location.
The second level organizes NPCs by rarity level
and the third level is the NPC's themselves.
Now interestingly, slickNav displays levels 1 and 2 just fine, but level 3 opens up to invisible text. I say invisible text because the amount of space that is revealed by the dropdown is correct.
This GIF shows what i'm talking about.
Observe how I click on Domestic animals, according the code below you can this is a long list of NPCs. The space SlickNav drops down is large.
Then observe how I click under Eol, this part of the site is undeveloped still, and so its only list item is " coming soon". Accordingly slickNav only drops down a little to make enough space for that.
According to http://slicknav.com/, it seems ive correctly nested my structure and labeled the menu as class="menu".
Its worth noting that on other parts of the site this menu works fine, but the menu's on those parts of the site are maximum of two levels deep.
Here is my HTML: Warning this is a big menu
<div class ="menu_wrap">
<nav id = "navMenu">
<ul class = "menu clearfix">
<li>Home
<ul class='subMenu1'>
<li id="instr">Instructions</li>
</ul>
</li>
<li>General
<ul class="subMenu1" >
<li>Domestic Animals
<ul class="subMenu2">
<li id="da1">Camel</li>
<li id="da2">War Camel</li>
<li id="da3">Druldon</li>
<li id="da4">Donkey</li>
<li id="da5">Pony</li>
<li id="da6">Draft Horse</li>
<li id="da7">Saddle Horse</li>
<li id="da8">Light War Horse</li>
<li id="da9">Heavy War Horse</li>
<li id="da10">Chariot Horse</li>
<li id="da11">Voran War Horse</li>
<li id="da12">Elven Narathi</li>
<li id="da13">Mountain Ram</li>
<li id="da14">War Elephant</li>
<li id="da15">War Mammoth</li>
<li id="da16">Dovashi Mastiff</li>
</ul>
</li>
<li>Common NPCs
<ul class="subMenu2">
<li id="guard1">Guard: Dovashi</li>
<li id="guard2">Guard: Dwarven</li>
<li id="guard3">Guard: Elven</li>
<li id="guard4">Guard: Gamoran</li>
<li id="guard5">Guard: Salatai</li>
<li id="guard6">Guard: Voran</li>
<li id="guard7">Guard: Dark Elf</li>
<li id="c5">Gnoll</li>
<li id="c6">Grimlock</li>
<li id="c11">Roper</li>
<li id="c12">Skeleton</li>
<li id="c13">Giant Spider</li>
<li id="c15">Zombie</li>
</ul>
<li>Uncommon NPCs
<ul class= "subMenu2">
<li id="uc5">Fire Child</li>
<li id="uc6">Ghoul</li>
<li id="uc11">Rakasa</li>
</ul>
</li>
<li>Rare NPCs
<ul class= "subMenu2">
<li id="r1">Adherer</li>
<li id="uc24">Arcane</li>
<li id="r3">Bane Dead</li>
<li id="r5">Fire Lord</li>
<li id="eleGen">Generic Elementalist</li>
<li id="necGen">Generic Necromancer</li>
<li id="illGen">Generic Illusionist</li>
<li id="cleGen">Generic Cleric</li>
<li id="r8">Radasai Warrior</li>
<li id="r9">Elemental(Fire)</li>
<li id="r10">Elemental(Water)</li>
<li id="r11">Elemental(Earth)</li>
<li id="r12">Elemental(Air)</li>
</ul>
</li>
<li>Very Rare NPCs
<ul class="subMenu2">
<li id="vr1">Arch Shadow</li>
<li id="vr3">Gorgon</li>
<li id="vr4">Illithid</li>
<li id="new3">Vampire</li>
<li id="new4">Were Wolf</li>
</ul>
</li>
</ul>
</li>
<li id ="world_drop"> Wol
<ul class ="subMenu1" >
<li>Common NPCs
<ul class="subMenu2">
<li id="c1">Cave Bear</li>
<li id="c2">Dire Wolf</li>
<li id="c3">Echuyan</li>
<li id="c4">Goblin</li>
<li id="c7">Voran Raider</li>
<li id="c8">Dovashi Ronin</li>
<li id="c9">Naga</li>
<li id="c10">Orc</li>
<li id="c14">Umber Hulk</li>
</ul>
</li>
<li>Uncommon NPCs
<ul class="subMenu2">
<li id="uc1">Ant (Giant)</li>
<li id="uc2">Alaghi</li>
<li id="uc3">Centaur</li>
<li id="uc4">Dire Boar</li>
<li id="uc7">Ogre</li>
<li id="uc8">Orc(Black)</li>
<li id="uc9">Orc (Shaman)</li>
<li id="uc10">Owl Bear</li>
<li id="uc12">Rastipede</li>
<li id="uc13">Troll</li>
<li id="new1">Young Black Wyvern</li>
</ul>
</li>
<li>Rare NPCs
<ul class="subMenu2">
<li id="r2">Ant Lion( giant)</li>
<li id="new2">Adult Black Wyvern</li>
<li id="r4">Basilisk</li>
<li id="r6">Hill Giant</li>
<li id="r7">Naga Elite</li>
</ul>
</li>
<li>Very Rare NPCs
<ul class="subMenu2">
<li id="vr2">Dray</li>
<li id="vr5">kalin</li>
<li id="vr6">Naga Queen</li>
<li id="vr7">Minotaur</li>
</ul>
</li>
</ul>
</li>
<li> Nol
<ul class="subMenu1">
<li>Common NPCs
<ul class="subMenu2">
<li id="c16">Abrian</li>
<li id="c17">Cave Bear (Polar)</li>
<li id="c18">Dwarven Bandits</li>
<li id="c19">Ettin</li>
<li id="c20">Frost Orc</li>
<li id="c21">Tus'Khul</li>
<li id="c22">Icemaw Raiders</li>
<li id="c23">Kenku</li>
<li id="c24">Kobold</li>
<li id="c25">Tundra Stag</li>
<li id="c26">Wight</li>
</ul>
</li>
<li>Uncommon NPCs
<ul class="subMenu2">
<li id="uc14">Bainligor</li>
<li id="uc15">Ettin (Mage)</li>
<li id="uc16">Blue Orc</li>
<li id="uc17">Goatmen</li>
<li id="uc18">Ice Golem</li>
<li id="uc19">Rogue ClockWork</li>
<li id="uc20">Snow Serpent</li>
<li id="uc21">Ice Wyvern(Young)</li>
<li id="uc22">Voldun</li>
</ul>
</li>
<li>Rare NPCs
<ul class="subMenu2">
<li id="r13">Aviarag</li>
<li id="r14">Crystal Hydra</li>
<li id="r15">Dark Hood</li>
<li id="r16">Derro Warrior</li>
<li id="r17">Frost Giant</li>
<li id="r18">Gargoyle</li>
<li id="r19">Ice Wyvern(Adult)</li>
<li id="r20">Mammoth</li>
</ul>
</li>
<li>Very Rare NPCs
<ul class="subMenu2">
<li id="vr8">White Dragon</li>
<li id="vr9">Pit Horror</li>
<li id="vr10">Frozen Men</li>
<li id="vr11">Vaporighu</li>
</ul>
</li>
</ul>
<li id ="indie_drop"> Sol
<ul class="subMenu1">
<li>Common NPCs
<ul class="leftSubMenu2">
<li id="c27">Cistern Fiend</li>
<li id="c28">Dire Crocodile</li>
<li id="c29">Dire Lion</li>
<li id="c30">Gamoran Exiles</li>
<li id="c31">Giant Scorpion</li>
<li id="c32">Myconid</li>
<li id="c33">Sand Bones</li>
<li id="c34">Salatai Bandits</li>
<li id="c35">Shissai half Breed</li>
<li id="c36">Tus-Kowah</li>
</ul>
</li>
<li>Uncommon NPCs
<ul class="leftSubMenu2">
<li id="uc23">Amiq-Rasol</li>
<li id="uc25">Beholder-Kin</li>
<li id="uc26">Gremlin</li>
<li id="uc27">Lesser Salamander</li>
<li id="uc28">Mummy</li>
<li id="uc29">Scrab</li>
<li id="uc30">Spell-Sword Merc.</li>
<li id="uc31">Shissai Pure Blood</li>
<li id="uc32">Will-O-Wisp</li>
</ul>
</li>
<li>Rare NPCs
<ul class="leftSubMenu2">
<li id="r21">Assimar</li>
<li id="r22">Elephant</li>
<li id="r23">Hattori</li>
<li id="r24">Roc</li>
<li id="r25">Sand-Men</li>
<li id="r26">Skordi</li>
<li id="r27">Tortle</li>
<li id="r28">Winged Snake</li>
</ul>
</li>
<li>Very Rare NPCs
<ul class="leftSUbMenu2">
<li id="vr12">Beholder</li>
<li id="vr13">Black Dragon</li>
<li id="vr15">Djinn</li>
<li id="vr14">Mummy Lord</li>
<li id="vr16">Sand Hydra</li>
</ul>
</li>
</ul>
</li>
<li> Eol
<ul class="subMenu1">
<li>Common NPCs
<ul class="leftSUbMenu2">
<li>Comming Soon</li>
</ul>
</li>
<li>Uncommon NPCs
<ul class="leftSUbMenu2">
<li>Comming Soon</li>
</ul>
</li>
</li>
<li>Rare NPCs
<ul class="leftSUbMenu2">
<li>Comming Soon</li>
</ul>
</li>
</li>
<li>Very Rare NPCs
<ul class="leftSUbMenu2">
<li>Comming Soon</li>
</ul>
</li>
</li>
</ul>
</li>
</ul>
This is all the CSS associated with the Menu.
Note: This is a simple CSS menu, the submenus are set to display:none and on hover the display is set to block.
All my menus work the same way on other parts of the site. But display being set to none is the only thing I can think of.
#navMenu{
margin:0;
padding: 0;
position: absolute;
line-height: 2em;
top: 28%;
left: 5.1%;
width: 100%;
font-size: 1.2vw;
font-family: verdana,arial,serif;
cursor: pointer;
z-index: 3;
}
#navMenu ul {
margin: 0;
padding: 0;
line-height: 2vw;
}
#navMenu li{
margin: 0;
padding: 0;
list-style: none;
float: left;
position: relative;
background: #999;
padding:.5em;
}
#navMenu ul li {
text-align: center;
text-decoration: none;
height: 1.875em;
width:13.5vw;
display: block;
color: #e0e0da;
background: black;
border-color: #99cdde;
border: 1px solid #99cdde;
}
.subMenu1,.subMenu2{
position: absolute;
display: none;
top: 100%;
left: -.25%; /*this fixes a menu alignment problem */
cursor: pointer;
}
.subMenu2{
position: absolute;
left: 100%;
top: 0%;
overflow-y: auto;
overflow-x:hidden;
height: 30vh;
}
.leftSubMenu2{
position: absolute;
right: 100%;
top: 0%;
overflow-y: auto;
overflow-x:hidden;
height: 30vh;
display: none;
}
#navMenu ul li:hover>ul {
display: block;
}
#navMenu ul li:hover{
transition:all linear .15s;
color: #99cdde;
}

Background for <li> elements - child elements

I have menu like here https://jsfiddle.net/z93hy4gh/ .
.widget li:hover {
background:#002d5e;
}
<div class="widget">
<ul class="product-categories">
<li class="cat-item cat-item-7 cat-parent current-cat-parent">Odzież
<ul class="children">
<li class="cat-item cat-item-13">Bluzy białe</li>
<li class="cat-item cat-item-14">Bluzy 100% bawełna</li>
<li class="cat-item cat-item-22">Bluzy na trok</li>
<li class="cat-item cat-item-32">Spodnie kolorowe i białe</li>
<li class="cat-item cat-item-68">Spodnie 100% bawełna</li>
<li class="cat-item cat-item-33 current-cat">Spodnie białe</li>
</ul>
</li>
<li class="cat-item cat-item-43">Fartuch </li>
<li class="cat-item cat-item-44">Fartuch </li>
<li class="cat-item cat-item-8">Obuwie </li>
</ul>
</div>
I want to set background for hover elements. But I don't know how to set it for child elements. How can I use .cat-parent or .current-cat-parent class to fix it?
I am guessing a bit about what you want, but perhaps if you set the background color on the a elements, you can highlight each link without affecting a nested blocks of li's.
I am assuming that you want to highlight the link text for each link in the lists.
.widget .children li {
background-color: yellow; /* demo only... */
display: block;
}
.widget .children li:hover {
background: pink;
}
.widget .product-categories > li:hover:not(:first-child) {
background-color: lightgreen;
}
.widget .product-categories > li:first-child a:hover {
background-color: lightgreen;
display: block;
}
<div class="widget">
<ul class="product-categories">
<li class="cat-item cat-item-7 cat-parent current-cat-parent">Odzież
<ul class="children">
<li class="cat-item cat-item-13">Bluzy białe</li>
<li class="cat-item cat-item-14">Bluzy 100% bawełna</li>
<li class="cat-item cat-item-22">Bluzy na trok</li>
<li class="cat-item cat-item-32">Spodnie kolorowe i białe</li>
<li class="cat-item cat-item-68">Spodnie 100% bawełna</li>
<li class="cat-item cat-item-33 current-cat">Spodnie białe</li>
</ul>
</li>
<li class="cat-item cat-item-43">Fartuch </li>
<li class="cat-item cat-item-44">Fartuch </li>
<li class="cat-item cat-item-8">Obuwie </li>
</ul>
</div>
You can use css :not() to prevent .cat-parent.
$(document).ready(
function() {
$('.cat-parent').click(
function(event) {
event.preventDefault();
$(this).toggleClass('opened');
});
});
.widget li:not(.opened):hover {
background: #002d5e;
}
.children {
display: none;
}
.opened .children {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="widget">
<ul class="product-categories">
<li class="cat-item cat-item-7 cat-parent current-cat-parent">Odzież
<ul class="children">
<li class="cat-item cat-item-13">Bluzy białe
</li>
<li class="cat-item cat-item-14">Bluzy 100% bawełna
</li>
<li class="cat-item cat-item-22">Bluzy na trok
</li>
<li class="cat-item cat-item-32">Spodnie kolorowe i białe
</li>
<li class="cat-item cat-item-68">Spodnie 100% bawełna
</li>
<li class="cat-item cat-item-33 current-cat">Spodnie białe
</li>
</ul>
</li>
<li class="cat-item cat-item-43">Fartuch
</li>
<li class="cat-item cat-item-44">Fartuch
</li>
<li class="cat-item cat-item-8">Obuwie
</li>
</ul>
</div>

Is there anything "wrong" with this markup?

Here is the markup I'm using:
<ul class="menu">
<li id="planning_menuItem" class="menuItem">Estate Planning</li>
<ul class="subMenu">
<li id="will_menuItem" class="subMenuItem">Last Will & Testament</li>
<li id="poa_menuItem" class="subMenuItem">Power Of Attorney</li>
<li id="livingWill_menuItem" class="subMenuItem">Living Will</li>
<li id="trusts_menuItem" class="subMenuItem">Trusts</li>
</ul>
<li id="probate_menuItem" class="menuItem">
Estate Probate Administration
</li>
<li id="realEstate_menuItem" class="menuItem">Real Estate</li>
<li id="medicaid_MenuItem" class="menuItem">Medicaid</li>
<li id="guardianships_menuItem" class="menuItem">Guardianships</li>
</ul>
Is there anything stylistically wrong about having that "ul" (class=subMenu) in the middle of a list without it having it's own li tag? This particular mark-up solves my problem, but I want at least be aware of whether I'm breaking some standard or convention.
The alternative is as follows, but it doesn't work for my particular task.
<ul class="menu">
<li id="planning_menuItem" class="menuItem">Estate Planning
<ul class="subMenu">
<li id="will_menuItem" class="subMenuItem">Last Will & Testament</li>
<li id="poa_menuItem" class="subMenuItem">Power Of Attorney</li>
<li id="livingWill_menuItem" class="subMenuItem">Living Will</li>
<li id="trusts_menuItem" class="subMenuItem">Trusts</li>
</ul>
</li>
<li id="probate_menuItem" class="menuItem">
Estate Probate Administration
</li>
<li id="realEstate_menuItem" class="menuItem">Real Estate</li>
<li id="medicaid_MenuItem" class="menuItem">Medicaid</li>
<li id="guardianships_menuItem" class="menuItem">Guardianships</li>
</ul>
Thanks!
Yes, there is something wrong, <ul>'s can be inside of <li>'s, but not other <ul>'s.
This is correct...
<ul>
<li>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</li>
<li></li>
<li></li>
<li></li>
</ul>
According to the HTML DTD, you cannot have a <ul> directly under another <ul>. You should nest it inside a <li>.
If you're worried about the additional padding/margins, you can remove them with a rule that only applies to <ul> elements as direct children of <li> elements:
li > ul { margin: 0; padding: 0 }
(Or experiment with the best setting for your style)
BELOW is proper way
<ul class="menu">
<li id="planning_menuItem" class="menuItem">
Estate Planning
</li>
<li>
<ul class="subMenu">
<li id="will_menuItem" class="subMenuItem">
Last Will & Testament
</li>
<li id="poa_menuItem" class="subMenuItem">
Power Of Attorney
</li>
<li id="livingWill_menuItem" class="subMenuItem">
Living Will
</li>
<li id="trusts_menuItem" class="subMenuItem">
Trusts
</li>
</ul>
</li>
<li id="probate_menuItem" class="menuItem">
Estate Probate Administration
</li>
<li id="realEstate_menuItem" class="menuItem">
Real Estate
</li>
<li id="medicaid_MenuItem" class="menuItem">
Medicaid
</li>
<li id="guardianships_menuItem" class="menuItem">
Guardianships
</li>
</ul>
as others have said the second way is valid
here's a forked jsfiddle showing some new CSS which should help
summary is that you want to keep the ul's and their li's full width no side padding or margins, so reset all ul's; then make the a's display block so they fill their parent li's - then use text-indent to create the indented look of the li's
then however you choose to apply an "active or selected" class - apply it to the li OR a and any hover changes can be made too.