I want to hide this bit: <li class="categories">Kατηγορίες<ul> as seen in the code below (also see here https://poiimata.com/poets/):
<li class="categories">Kατηγορίες<ul>
<li class="cat-item cat-item-123">
<a href="https://poiimata.com/category/robert-frost/" >Robert Frost</a>
</li>
<li class="cat-item cat-item-124">
<a href="https://poiimata.com/categoryshlain-goldberg/" >Shlain</a>
</li>
I tried using
.categories {
display:none;
}
but the result was to hide all items below that one (the whole list).
That happen because you've an invalid HTML code in :
<li class="categories">Kατηγορίες<ul>
_________________________________^^^^
The browser will evaluate your code to the below format, that why all your li's become hidden :
<ul>
<li class="categories">Kατηγορίες
<ul>
<li class="cat-item cat-item-123">Robert Frost
</li>
<li class="cat-item cat-item-124">Shlain
</li>
</ul>
</li>
</ul>
Instead it should be :
<ul>
<li class="categories">Kατηγορίες</li>
<li class="cat-item cat-item-123">Robert Frost
</li>
<li class="cat-item cat-item-124">Shlain
</li>
</ul>
Snippet:
.categories {
display: none;
}
<ul>
<li class="categories">Kατηγορίες</li>
<li class="cat-item cat-item-123">Robert Frost
</li>
<li class="cat-item cat-item-124">Shlain
</li>
</ul>
It appears you just have an error in your HTML. You use an incorrect closing tag and therefore hide the entire thing.
<li class="categories">Kατηγορίες<ul> <!--- closed <li> with <ul> --->
<li class="cat-item cat-item-123">
<a href="https://poiimata.com/category/robert-frost/" >Robert Frost</a>
</li>
<li class="cat-item cat-item-124">
<a href="https://poiimata.com/categoryshlain-goldberg/" >Shlain</a>
</li>
Try instead:
<ul class="categories">
<li >Kατηγορίες<li>
<li class="cat-item cat-item-123">
<a href="https://poiimata.com/category/robert-frost/" >Robert Frost</a>
</li>
<li class="cat-item cat-item-124">
<a href="https://poiimata.com/categoryshlain-goldberg/" >Shlain</a>
</li>
</ul>
and change CSS to
.categories:first-child {
display:none;
}
That's just one way of accomplishing it. There are quite a few different angles you can take.
Since li contains tags that you do not need to hide, you need to masked the hidden text. for example like this:
.categories {
font-size: .1%;
}
.categories ul {
font-size: 100000%;
}
if only child elements is not a bug...
Related
In the website I'm working on the navigation menu is made by several nested lists, when one element is clicked on the <li> element with the page name acquires the .active class, if it belongs to a nested list all parent li elements above also acquire the .active class.
I'd like to be able to style the last <li> element with class .active since it corresponds to the currently open webpage.
I'm working with Omeka s content management system, which means that I can't use javascript or modify the HTML files, so I'm looking for a solution in pure CSS.
here is the menu structure:
`
<ul class="">
<li >
Introduction
</li>
<li>
level 1
<ul>
<li>
subpage
<ul>
<li>
sub-subpage
<ul>
<li>
sub-sub-page
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
here is when I'm on th page "sub-sub-page":
<ul class="">
<li >
Introduction
</li>
<li class="active">
level 1
<ul>
<li class="active">
subpage
<ul>
<li class="active">
sub-subpage
<ul>
<li class="active">
sub-sub-page
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
`
I've tried to use li.active:last-of-type but it only select the last element of type li.
ul *{
color : #000;
text-decoration: none
}
ul .active ul li ul li ul li a{
color : #f00;
font-weight : bold;
}
<ul class="">
<li >
Introduction
</li>
<li class="active">
level 1
<ul>
<li class="active">
subpage
<ul>
<li class="active">
sub-subpage
<ul>
<li class="active">
sub-sub-page
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
It appeared simpler than I first thought:
Given the current structure, from all nested active elements you need to select the li that only has an a element. To make it work in general (other than a list element) don't use the li element selector at all.
I added two differently nested examples in the snippet along with an ::after text...
.active > a:only-child { color: red }
.active > a:only-child::after { content: ' (active)' }
<ul class="">
<li>
Introduction
</li>
<li class="active">
level 1
<ul>
<li class="active">
subpage
<ul>
<li class="active">
sub-subpage
<ul>
<li>
sub-sub-page
</li>
<li class="active">
sub-sub-page
</li>
<li>
sub-sub-page
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<br><br><br>
<ul class="">
<li>
Introduction
</li>
<li class="active">
level 1
<ul>
<li class="active">
subpage
<ul>
<li>
sub-sub-page
</li>
<li>
sub-sub-page
</li>
<li class="active">
sub-subpage
</li>
<li>
sub-sub-page
</li>
</ul>
</li>
</ul>
</li>
</ul>
<br><br><br>
<ul class="">
<li>
Introduction
</li>
<li class="active">
level 1
<ul>
<li class="active">
subpage
<ul class="">
<li>
Introduction
</li>
<li class="active">
level 1
<ul>
<li class="active">
subpage
<ul>
<li class="active">
sub-sub-page
</li>
<li>
sub-sub-page
</li>
<li>
sub-subpage
</li>
<li>
sub-sub-page
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
This is proving very difficult. Nav is pasted pasted below. This is a wordpress website so while I could change the structure of the html I'd rather not.
It looks like the nested drop down menus <ul> are contained within parent <li> elements.
My goal is to have, on hover, the list items be orange with 0.4 opacity. I would also like this for the drop down menu line items. Except, the problem is, that when hovering over a line item that has a drop down nested within it, the 0.4 opacity seems to apply to the whole menu, as opposed to just the hovered one. I have tried numerous things. Here is a taste of what I have tried:
.dropdown > ul li:hover { // the styling in question. Everything below is an attempt to limit this from affecting the whole drop down menus.
background-color: orange;
opacity:0.4;
}
.dropdown > ul.children li:hover, .dropdown > ul.children:hover { // trying to select just the drop down menu and take of the opacity by setting it to 1
opacity: 1;
}
ul.children li:hover { // similar to above just another attempt
opacity: 1;
}
ul.children, ul.children:hover, ul.children li, ul.children li:hover{ // just resorting to trying everything now
opacity: 1;
}
I made a fiddle too: http://jsfiddle.net/m7owomb0/
See how when you hover over the menu items with drop downs it's transparent? Then click on one of the actual links and the styling from the live site loads into the frame. When you hover there it's not transparent and you can see the items clearly. I just want them to be orange when hovered.
<div id="main-navigation">
<nav>
<div class="dropdown dropdown-horizontal">
<ul class="main-nav">
<li class="current_page_item">
<a href="http://dduck8977.webfactional.com/">
Home
</a>
</li>
<li class="page_item page-item-57">
<a href="http://dduck8977.webfactional.com/?page_id=57">
Clear Outs & Offers
</a>
</li>
<li class="page_item page-item-8 page_item_has_children">
<a href="http://dduck8977.webfactional.com/?page_id=8">
Flooring
</a>
<ul class='children'>
<li class="page_item page-item-19">
<a href="http://dduck8977.webfactional.com/?page_id=19">
Chestnut
</a>
</li>
<li class="page_item page-item-15">
<a href="http://dduck8977.webfactional.com/?page_id=15">
Douglas Fir
</a>
</li>
<li class="page_item page-item-12">
<a href="http://dduck8977.webfactional.com/?page_id=12">
Heart Pine
</a>
</li>
<li class="page_item page-item-17">
<a href="http://dduck8977.webfactional.com/?page_id=17">
Maple
</a>
</li>
<li class="page_item page-item-10">
<a href="http://dduck8977.webfactional.com/?page_id=10">
Oak
</a>
</li>
</ul>
</li>
<li class="page_item page-item-50 page_item_has_children">
<a href="http://dduck8977.webfactional.com/?page_id=50">
Locations
</a>
<ul class='children'>
<li class="page_item page-item-52">
<a href="http://dduck8977.webfactional.com/?page_id=52">
New York
</a>
</li>
<li class="page_item page-item-55">
<a href="http://dduck8977.webfactional.com/?page_id=55">
Philadelphia
</a>
</li>
</ul>
</li>
<li class="page_item page-item-21 page_item_has_children">
<a href="http://dduck8977.webfactional.com/?page_id=21">
Paneling
</a>
<ul class='children'>
<li class="page_item page-item-31">
<a href="http://dduck8977.webfactional.com/?page_id=31">
Barn Wood
</a>
</li>
<li class="page_item page-item-27">
<a href="http://dduck8977.webfactional.com/?page_id=27">
Eastern Mix
</a>
</li>
<li class="page_item page-item-29">
<a href="http://dduck8977.webfactional.com/?page_id=29">
Mushroom Wood
</a>
</li>
<li class="page_item page-item-23">
<a href="http://dduck8977.webfactional.com/?page_id=23">
Oak
</a>
</li>
<li class="page_item page-item-25">
<a href="http://dduck8977.webfactional.com/?page_id=25">
Pine & Fir
</a>
</li>
</ul>
</li>
<li class="page_item page-item-40">
<a href="http://dduck8977.webfactional.com/?page_id=40">
Patchwork
</a>
</li>
<li class="page_item page-item-37 page_item_has_children">
<a href="http://dduck8977.webfactional.com/?page_id=37">
Reclaimed Wood
</a>
<ul class='children'>
<li class="page_item page-item-47">
<a href="http://dduck8977.webfactional.com/?page_id=47">
Lumber Phrases
</a>
</li>
<li class="page_item page-item-42">
<a href="http://dduck8977.webfactional.com/?page_id=42">
Wood Types
</a>
</li>
</ul>
</li>
<li class="page_item page-item-35">
<a href="http://dduck8977.webfactional.com/?page_id=35">
Shelving
</a>
</li>
<li class="page_item page-item-33">
<a href="http://dduck8977.webfactional.com/?page_id=33">
Tables
</a>
</li>
</ul>
</div>
</nav>
</div>
How can I add styling so that hovered line items are orange with opacity 0.4, without affecting nested ULs within these line items?
You cannot override opacity in child elements, use rgba instead.
.dropdown > ul li:hover {
background-color: rgba(255,165,0,0.4);
}
I'd like to target the first occurence of the <a> element in this list, first-child doesn't seem to work because it selects all the children <a> s. Any ideas?
<li class="cat-item cat-item-1 current-cat">
<a title="View all posts filed under Basket" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=1">Basket</a>
<ul class="children">
<li class="cat-item cat-item-19">
<a title="View all posts filed under Article List" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=19">Article List</a>
<ul class="children">
<li class="cat-item cat-item-20">
<a title="View all posts filed under Mobile" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=20">Mobile</a>
<ul class="children">
<li class="cat-item cat-item-21">
<a title="View all posts filed under Current" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=21">Current</a>
</li>
</ul>
</li>
<li class="cat-item cat-item-22">
<a title="View all posts filed under Desktop" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=22">Desktop</a>
<ul class="children">
<li class="cat-item cat-item-23">
<a title="View all posts filed under Current" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=23">Current</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
You would need to target the first li and then it's anchor link
ul li:first-child a {
/* your styles here */
}
It difficult to be more specific but if you were referring to the children ul you can make it
ul.children > li:first-child a {
/*your styles here */
}
If you mean this
<li class="cat-item cat-item-1 current-cat">
<a title="View all posts filed under Basket" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=1">Basket</a>
The css would be
li.cat-item.cat-item-1.current-cat > a {
/*styles */
}
If by "this list" you mean the root, you could do:
.current-cat > a
Not sure if you're using jQuery on your site, but if so, you can work with jquery and do this.
$("a").first().attr("title");
Etc.
As I said, it depends if you're using jQuery and it can be used for what you'd like to do, but since you didn't specify what you plan to do with the result, it's hard to assume otherwise.
I have a navigator on my site, made of <ul> elements:
<div class="navigator">
<ul>
<li class="nav-item nav-parent nav-expanded">Category One
<ul>
<li class="nav-item nav-parent nav-collapsed">Subcategory One</li>
<li class="nav-item nav-parent nav-collapsed">Subcategory Two</li>
<li class="nav-item nav-parent nav-collapsed">Subcategory Three</li>
<li class="nav-item nav-parent nav-expanded">Subcategory Four
<ul>
<li class="nav-item nav-expanded">Item 4-1</li>
<li class="nav-item nav-selected">Item 4-2</li>
<li class="nav-item nav-expanded">Item 4-3</li>
</ul>
</li>
<li class="nav-item nav-parent nav-collapsed">Subcategory Five</li>
</ul>
</li>
<li class="nav-item nav-collapsed">Category Two</li>
<li class="nav-item nav-collapsed">Category Three</li>
<li class="nav-item nav-collapsed">Category Four</li>
</ul>
</div>
Expanded and collapsed elements differ in a mark "+" or "-" made by following rules of css:
li.nav-expanded:before {
content: "- ";
}
li.nav-collapsed:before {
content: "+ ";
}
It looks fine in Firefox:
But it looks weird in Chromium:
Why is this weird - because it fixes with strange action in Developer tools:
I choose li.nav-item element, change display: list-item to display:inline and back to display:list-item. And it looks fine.
I don't understand, how to fix this? Is this Chromium bug?
<ul> that are inside the <li> should be display: list-item too. So making:
li.nav-item ul, .navigator ul {
display: list-item;
}
fixed the problem in Chromium.
I have a list with multiple sections. I try to make it look like a kind of tree. It started quite well but I can't fix the last bits.
The code can be found at:
http://jsfiddle.net/Kwfpm/
Here is how it should work
The first "Datorer", "Mjukvara" and
"Microsoft" should be connected to
the tree with a horisontal line.
"Mjukvara" at the bottom left should
be connected to "Kategorier".
There are some repeated problems but these should be solved if the two above is solved.
Here is a link what it should look like (without the collapsing things):
Open and close to see the tree:
http://jquery.bassistance.de/treeview/demo/prerendered.html
Info
I don't know how many levels there are.
The HTML can't be changed because its generated by Wordpress
Use backgrounds or borders to show what you got.
If JSfiddle don't work you can use this:
CSS
* {
margin: 0;
padding: 0;
}
.sidebar > ul > li {
background: none;
}
li {
padding-left: 20px;
list-style: none;
background: url('http://www.jenst.se/images/normal.png') repeat-y 10px 0;
color: #333;
font-family: Arial;
font-size: 13px;
line-height: 22px;
}
li a {
color: #555;
}
li:last-child {
background: url('http://www.jenst.se/images/lastchild.png') no-repeat 10px 0px;
}
HTML
<div class="sidebar default">
<ul>
<li id="categories-10" class="widget widget_categories">
<h4 class="title">Kategorier</h4>
<ul>
<li class="cat-item cat-item-7">Datorer
</li>
<li class="cat-item cat-item-3">Mjukvara
<ul class='children'>
<li class="cat-item cat-item-4">Hårdvara
<ul class='children'>
<li class="cat-item cat-item-6">Microsoft
</li>
<li class="cat-item cat-item-9">Office-paket
</li>
</ul>
</li>
</ul>
</li>
<li class="cat-item cat-item-3">Mjukvara
<ul class='children'>
<li class="cat-item cat-item-4">Hårdvara
<ul class='children'>
<li class="cat-item cat-item-6">Microsoft
</li>
<li class="cat-item cat-item-9">Office-paket
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li id="categories-10" class="widget widget_categories">
<ul>
<li class="cat-item cat-item-7">Datorer
</li>
<li class="cat-item cat-item-3">Mjukvara
<ul class='children'>
<li class="cat-item cat-item-4">Hårdvara
<ul class='children'>
<li class="cat-item cat-item-6">Microsoft
</li>
<li class="cat-item cat-item-9">Office-paket
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
Have a look at this javascript treeview: http://krijnhoetmer.nl/stuff/javascript/list-treeview-menu/
It does have a same structure as you prefer with li's and ul's. Maybe you could take a look at it with firebug.
I figured it out. Here is a working code:
http://jsfiddle.net/Kwfpm/3/
The red borders can be changed to a background image horizontal lines.