I need to know how I can select the <li>Iquitos Peru</li> tag using CSS, I have read about "nth-child" but I do not understand it. I have the following sample code.
<ul id="pais">
<h1>Perú</h1>
<li class="departamento">
<ul>
<h2>Lima</h2>
<li class="provincia">
<h3>Lima</h3>
<ul>
<li><strong>Ciudades:</strong></li>
<li>Ancon</li>
<li>Comas</li>
<li>Los Olivos</li>
<li>La Molina</li>
<li>Chorrillos</li>
<li><input type="text" class="eleccion"></li>
</ul>
</li>
</ul>
</li>
<li class="departamento">
<ul>
<h2>Loreto</h2>
<li class="provincia">
<h3>Iquitos Ciudad</h3>
<ul>
<li><strong>Ciudades:</strong></li>
<li>Iquitos Perú</li> <-- I need format this ######
<li>Nauta</li>
<li>Belén</li>
<li>Punchana</li>
<li><input type="text" class="eleccion"></li>
</ul>
</li>
</ul>
</li>
</ul>
<input type="button" value="Enviar" class="btnEnviar" (click)="alert()">
I found this example but I do not know how I can apply it to my case. Is that in this example only divs are used, and I have <ul> I find this but is difficult to understand. Thank you very much.
One way is selecting it like this if you know that the order is not going to change
#pais .departamento:last-child .provincia li:nth-child(2) {
color: red;
}
or using both times the nth-child selector
#pais .departamento:nth-child(3) .provincia li:nth-child(2) {
color: red;
}
Not possible to select the content with CSS. So added a value attribute to the li for selector.
Alternatively if you are using jquery then you can use the contains selector
li[value='Iquitos Per'] {
background-color:red
}
<ul id="pais">
<h1>Perú</h1>
<li class="departamento">
<ul>
<h2>Lima</h2>
<li class="provincia">
<h3>Lima</h3>
<ul>
<li><strong>Ciudades:</strong></li>
<li>Ancon</li>
<li>Comas</li>
<li>Los Olivos</li>
<li>La Molina</li>
<li>Chorrillos</li>
<li><input type="text" class="eleccion"></li>
</ul>
</li>
</ul>
</li>
<li class="departamento">
<ul>
<h2>Loreto</h2>
<li class="provincia">
<h3>Iquitos Ciudad</h3>
<ul>
<li><strong>Ciudades:</strong></li>
<li value="Iquitos Per">Iquitos Perú</li>
<li>Nauta</li>
<li>Belén</li>
<li>Punchana</li>
<li><input type="text" class="eleccion"></li>
</ul>
</li>
</ul>
</li>
</ul>
<input type="button" value="Enviar" class="btnEnviar" (click)="alert()">
You can either give that <li> an id or a class. Otherwise you can use a selector, see: Nested classes selectors
Related
I'm fighting with this for 2 days and it may be simple, but I'm not getting there.
I want to have a nice, clean tree view with multiple levels and I'm trying to first target children after root. I can do that, but I'm sure using ~ and + signs this may be simpler. Second I need the checkboxes to open / close the tree.
I know I can always use a pre made one, but I want need to learn.
Any help?
No javascript or query, pure css please.
ul.tree li a {
/* 1º Nível */
color: red;
}
ul.tree ul>li a {
/* 2º Nível */
color: blue;
}
ul.tree ul>ul li a {
/* 3º Nível */
color: yellow;
}
ul.tree ul>ul>ul li a {
/* 4º Nível */
color: green;
}
ul.tree ul>ul>ul>ul li a {
/* 5º Nível */
color: orange;
}
ul.tree>input.[type=checkbox]:checked ul.tree ul>li {
display: none;
}
<ul class="tree">
<li><input type=checkbox /><b>_root</b></li>
<li class="ficheiro">ficheiro</li>
<li class="ficheiro">ficheiro</li>
<li>
<ul class="pasta">
<li><input type=checkbox /><b>Pasta A</b></li>
<li class="ficheiro">ficheiro</li>
<li class="ficheiro">ficheiro</li>
<li class="ficheiro">ficheiro</li>
<li>
<ul class="pasta">
<li><input type=checkbox /><b>Pasta A - 1</b></li>
<li class="ficheiro">ficheiro</li>
<li>
<ul class="pasta">
<li><input type=checkbox /><b>Pasta dentro da pasta A - 1</b></li>
<li class="ficheiro">ficheiro</li>
<li class="ficheiro">ficheiro</li>
<li class="ficheiro">ficheiro</li>
<li>
<ul class="pasta">
<li><input type=checkbox /><b>Pasta dentro da pasta dentro da pasta A -1</b></li>
<li class="ficheiro">ficheiro</li>
<li class="ficheiro">ficheiro</li>
<li class="ficheiro">ficheiro</li>
<li class="ficheiro">ficheiro</li>
<li class="ficheiro">ficheiro</li>
</ul>
</li>
<li class="ficheiro">ficheiro</li>
<li class="ficheiro">ficheiro</li>
</ul>
</li>
<li class="ficheiro">ficheiro</li>
</ul>
</li>
<li class="ficheiro">ficheiro</li>
</ul>
</li>
<li class="ficheiro">ficheiro</li>
<li class="ficheiro">ficheiro</li>
</ul>
the fiddle
example of what I made
Here's the code, and later I will link to the documentation and explain what I have done. I have validated the HTML. Strange syntax in CSS that you're seeing is BEM methodology. You should avoid targeting bare elements and always try to give them specific class.
JSFiddle - if you find it easier.
Please note: Although I have tried to use best practices both for HTML and CSS, this is NOT something you would do in production. It is too "hacky" and the "price" for pure css solution is much higher than if we decided to use a little bit of JS. But, nevertheless it was interesting to try and overcame the obstacles, that is - to propose the solution within the boundaries you have set.
label {
font-weight: bold;
}
/* LIST style hacks which allows us to avoid bullets before checkbox - unfortunately, we have to supply and fake the bullets with pseudo before element for every li where we want them */
ul {
list-style: none;
}
.ficheiro::before {
content: "•";
position: absolute;
left: -15px;
}
.pasta-1 .ficheiro::before {
content: "°";
position: absolute;
left: -15px;
top: 3px;
}
.pasta-2 .ficheiro::before {
content: "*";
position: absolute;
left: -15px;
top: 3px;
}
/* CHECKBOX hacks for selectively hiding and showing the parts of the tree */
.tree {
display: none;
}
#level-0:checked ~ .tree {
display: block;
}
.pasta-1,
.pasta-2,
.pasta-3,
.pasta-4 {
display: none;
}
#level-1:checked ~ .pasta-1 {
display: block;
}
#level-2:checked ~ .pasta-2 {
display: block;
}
#level-3:checked ~ .pasta-3 {
display: block;
}
#level-4:checked ~ .pasta-4 {
display: block;
}
/* LINKS */
.ficheiro {
position: relative;
}
.ficheiro__link--root {
color: red;
}
.ficheiro__link--level-1 {
color: blue;
}
.ficheiro__link--level-2 {
color: yellow;
}
.ficheiro__link--level-3 {
color: green;
}
.ficheiro__link--level-4 {
color: orange;
}
<input id="level-0" type="checkbox" />
<label for="level-0">_root</label>
<ul class="tree">
<li class="ficheiro"><a class="ficheiro__link--root" href="#">ficheiro</a></li>
<li class="ficheiro"><a class="ficheiro__link--root" href="#">ficheiro</a></li>
<li>
<input id="level-1" type="checkbox" />
<label for="level-1">Pasta A</label>
<ul class="pasta-1">
<li class="ficheiro"><a class="ficheiro__link--level-1" href="#">ficheiro</a></li>
<li class="ficheiro"><a class="ficheiro__link--level-1" href="#">ficheiro</a></li>
<li class="ficheiro"><a class="ficheiro__link--level-1" href="#">ficheiro</a></li>
<li>
<input id="level-2" type="checkbox" />
<label for="level-2">Pasta A - 1</label>
<ul class="pasta-2">
<li class="ficheiro"><a class="ficheiro__link--level-2" href="#">ficheiro</a></li>
<li>
<input id="level-3" type="checkbox" />
<label for="level-3">Pasta dentro da pasta A - 1</label>
<ul class="pasta-3">
<li class="ficheiro"><a class="ficheiro__link--level-3" href="#">ficheiro</a></li>
<li class="ficheiro"><a class="ficheiro__link--level-3" href="#">ficheiro</a></li>
<li class="ficheiro"><a class="ficheiro__link--level-3" href="#">ficheiro</a></li>
<li>
<input id="level-4" type="checkbox" />
<label for="level-4">Pasta dentro da pasta dentro da pasta A -1</label>
<ul class="pasta-4">
<li class="ficheiro"><a class="ficheiro__link--level-4" href="#">ficheiro</a></li>
<li class="ficheiro"><a class="ficheiro__link--level-4" href="#">ficheiro</a></li>
<li class="ficheiro"><a class="ficheiro__link--level-4" href="#">ficheiro</a></li>
<li class="ficheiro"><a class="ficheiro__link--level-4" href="#">ficheiro</a></li>
<li class="ficheiro"><a class="ficheiro__link--level-4" href="#">ficheiro</a></li>
</ul>
</li>
<li class="ficheiro"><a class="ficheiro__link--level-3" href="#">ficheiro</a></li>
<li class="ficheiro"><a class="ficheiro__link--level-3" href="#">ficheiro</a></li>
</ul>
</li>
<li class="ficheiro"><a class="ficheiro__link--level-2" href="#">ficheiro</a></li>
</ul>
</li>
<li class="ficheiro"><a class="ficheiro__link--level-1" href="#">ficheiro</a></li>
</ul>
</li>
<li class="ficheiro"><a class="ficheiro__link--root" href="#">ficheiro</a></li>
<li class="ficheiro"><a class="ficheiro__link--root" href="#">ficheiro</a></li>
</ul>
Try to understand what is happening in the code, and why I have structured it the way I have. It's best way to learn. Meanwhile, I will prepare the links and explanations and append them in the later edit.
EDIT:
You can validate code with w3c validator. It will scream at you
because we're missing <!DOCTYPE html>, lang, title, etc. but
the code itself is valid.
MDN - li element:
permitted parents: <ul>, <ol>, or <menu>
permitted content: Flow content (basically, any element that is valid within <body>)
30 CSS selectors you should know - we were using sibling combinator ~ (number 9 on this list of 30)
CSS code could be much cleaner with the use of preprocessor such as SASS and mixins, or even with the simple nesting.
When you target elements several levels deep, you're increasing the specificity and make it extremely hard to maintain it later. You can try this specificity calculator to understand it better. That's why one of the best practices is to use classes. With good naming, the code basically documents itself and it's quite clear what your intention was. You immediately know which element belongs to which level just by looking at the class names.
I have 3 UL inside a div. 2 UL contain a directive that checks if the user is authenticated or not. like so:
<div class="language-options">
<ul>
<li>
<a>
<select box></select box>
</a>
</li>
</ul>
<!-- Show this for logged out users -->
<ul *appShowAuthed="false">
<li>
<a>
Sign in
</a>
</li>
<li>
<a>
Sign up
</a>
</li>
</ul>
<!-- Show this for logged in users -->
<ul *appShowAuthed="true">
<li>
<a>
Home
</a>
</li>
<li>
<a>
<i></i> New Article
</a>
</li>
<li>
<a>
<i></i> Settings
</a>
</li>
<li>
<a>
<img [src]="currentUser.image" *ngIf="currentUser.image" class="user-pic" /> {{ currentUser.username }}
</a>
</li>
</ul>
</div>
What is happening is that although my language-options select box is before in the html code then the other 2 ULs it displays after them in the page:
[ Sign in | Sign up ] [ select box ]
It seems that due to the directive execution that the html code takes longer to render and as suchs displays before the language-options.
How an I set the language-options UL to display before the Sign in | Sign up? see below:
[ select box ] [ Sign in | Sign up ]
This is related to the css: float: right.
navigation image here
how can i disable the green color there whenever i click in gallery page?
Home
<li class="dropdown mega-dropdown">
<a class="dropdown-toggle" href="Gallery.aspx">Gallery<span class="caret"></span></a>
<div class="pc-nav">
<ul class="dropdown-menu mega-dropdown-menu">
<li class="col-sm-3 col-md-push-3">
<ul>
<li class="dropdown-header" style="text-align:left">Company Trips</li>
<li style="text-align:left; visibility:hidden;"> 2016 - Vietnam</li>
<li style="text-align:left;"> 2015 - Guilin</li>
</ul>
</li>
</ul>
CSS here
<ul class="dropdown-menu mega-dropdown-menu">
<li class="col-sm-3 col-md-push-3">
<ul>
<li class="dropdown-header" style="text-align:left">Company Trips</li>
<li style="text-align:left;"> 2016 - Vietnam</li>
<li style="text-align:left;"> 2015 - Guilin</li>
</ul>
</li>
</ul>
I assume the current class indicates the column you have selected. Given the markup you provided in the comments, you can rewrite the rule like this to remove the background color:
.current {
background-color: transparent;
}
If you do not have access to the original code but wish to override it, you can supersede the background-color property like this:
.current {
background-color: transparent !important;
}
But in the end, if you don't wish there to be any special background color for the current column, you can just delete the entire block of code.
EDIT
Based on your feedback, I assume you want to highlight the names of the countries in the list but not the first item of the list. In that case, you can target them like this:
ul.dropdown-menu ul li:not(.dropdown-header) {
background-color: #00b200;
}
I'm trying to display a li when an another li from a different ul is hovered , but i didn't have success until now.Can you help me ? Thank you !
HTML
<div id="parent">
<ul id="child1">
<li id="child1a">bla bla</li>
<li id="child1b">bla bla</li>
<li id="child1c">bla bla</li>
<li id="child1d">bla bla</li>
</ul>
<ul id="child2">
<li id="child2a">bla bla</li>
<li id="child2b">bla bla</li>
<li id="child2c">bla bla</li>
<li id="child2d">bla bla</li>
</ul>
</div>
CSS
#child2a {display:none;}
#child1a:hover #child2a {display:block}
https://jsfiddle.net/t9y4wu61/
You will need more than just CSS to solve this. But first of all, your approach contains a logical mistake:
#child1a:hover #child2a {display:block}
Adding a space between selectors means that they are nested in the markup. So your CSS would work just fine for something like this:
<div id="parent">
<ul id="child1">
<li id="child1a">
<span id="child2a">bla bla</span>
</li>
</ul>
</div>
But of course, this is not what you want. To get things working, you will need JavaScript. I recommend jQuery for this:
$(document).ready(function() {
$("#child1a").mouseover(function() {
$("#child2a").show();
};
$("#child1a").mouseoout(function() {
$("#child2a").hide();
};
}
Please note that I did not test this code, so it might have some issues. However it might lead you into the right direction. See the linked jQuery website for reference and code examples.
I'm building a LHN in Sitefinity and ran into an issue styling it. When a page is set as the active page, it gets the sfsel class. Unfortunately, it also applies it to the parent page when a subpage is active. I need to get the styling so when a subpage is active, only that list item is highlighted, but when only the parent "About" page is active, it still gets highlighted.
http://jsfiddle.net/4NnaZ/1/
<div class="sfNavWrp sfNavTreeviewWrp leftnav">
<div class="k-widget k-treeview" tabindex="0" role="tree" aria-activedescendant="C001_ctl00_ctl00_navigationUl_tv_active">
<ul class="sfNavTreeview sfNavList k-group k-treeview-lines" id="C001_ctl00_ctl00_navigationUl" data-role="treeview">
<li class="k-item k-first k-last" data-uid="ceac0efa-1b50-46c7-a351-945f05a6eb87" role="treeitem" data-expanded="true" aria-expanded="true">
<div class="k-top k-bot"><span class="k-icon k-minus"></span><a class="sfSel k-in" href="../about">About</a>
</div>
<ul id="C001_ctl00_ctl00_ctl03_ctl00_childNodesContainer" class="k-group" style="display: block;">
<li class="k-item" data-uid="3b1f4e90-1945-4c93-a770-43787527d7bf" role="treeitem" id="C001_ctl00_ctl00_navigationUl_tv_active">
<div class="k-top"><a class="sfSel k-in k-state-focused" href="locations">Locations</a>
</div>
</li>
<li class="k-item" data-uid="48d48d44-55ee-4bf7-9fcd-20380c18b991" role="treeitem">
<div class="k-mid">Careers
</div>
</li>
<li class="k-item" data-uid="267e4a18-8489-45c2-bef3-1efcba63916f" role="treeitem">
<div class="k-mid">Producer Board
</div>
</li>
<li class="k-item k-last" data-uid="d75d7989-3815-49b3-856c-c4d24dcd5dc8" role="treeitem">
<div class="k-bot">Contact Information
</div>
</li>
</ul>
</li>
</ul>
</div>
isn't k-state-focused the class you should use to highlihgt only current link/page ?
I believe this is a jQuery script producing this classname.
You can modify your code to set a class for that purpose , http://www.sitefinity.com/developer-network/forums/general-discussions-/highlight-current-page