Is it possible to get rid of border-top property in the second line of a list item on hover?
<ul>
<li>This is a<br/>long Link</li>
</ul>
Display:block causes the border has the same width like the whole element
Display:inline-block causes nearly same results
Starting Fiddle
By the help of #Pete and the others I ended up with this:
$('#access a').each(function() {
$(this).contents().filter(function() {
return this.nodeType == 3;
}).wrap('<span></span>');
});
to simply wrap the <li> contents with <span> elements:
<!-- with the javascript -->
<nav id="access" role="navigation">
<ul id="menu-primary" class="menu">
<li class="menu-item">
<a href="http://www.url.com"><span>Hello</span><br/><span>World</span><a/>
</li>
</ul>
</nav>
This makes it possible to create a hover only for the first span element of the li element:
.mainmenu ul a:hover span:first-child {border-top:1px dotted #fbf9ef;}
Pete's Fiddle
you can separate the two line with span tag
<ul>
<li><span>This is a</span><br/><span>long Link</span></li>
</ul>
then make this in css :
a:hover span:first-child {border-top:1px solid}
a:hover span:last-child {border-top:none;}
Add your first line in <span> & use this code a:hover span{border-top:1px solid;}
I'm not sure I understand what you mean if inline-block isn't working for you; this worked for me:
a {
display:inline-block;
text-decoration:none;
vertical-align:text-top;
}
a:hover {
border-top:1px solid;
display:inline-block;
}
http://jsfiddle.net/kK2bf/
You can use the pseudo-element ::first-line.
Related
In my <ul> list I have several <li> with <a> tags in them.
I want to change the color of the li bullet icons when hovering on the <a> tag (I mean bullets beside <li>)
I tried
a:hover {
color:red;
}
but it doesn't affect the<li> bullet icon.
I also tried
ul li:hover{
color:red;
}
But it doesn't work perfectly because when mouse move to near <a> tag and not on it <li> and the bullets starts to change color.
your code actually worked for me.
<ul>
<li>
A
</li>
<li>
B
</li>
<li>
C
</li>
</ul>
CSS:
ul li:hover{
color:red;
}
Fiddle: https://jsfiddle.net/tox9je8n/
I have tried something related to your question and it works fine. To fix the issue of li:hover not hovering link, you should set to display:block, as below, so that it takes full width.
ul li a {
color: black;
display: block
}
ul li:hover {
color: red;
}
ul li:hover a {
color: black;
}
<ul>
<li>Value 1</li>
<li>Value 2</li>
<li>Value 3</li>
</ul>
i am a newbie to CSS,HTML and trying to understand lists.however something confuses me .As you can see below my HTML i am trying to create a drop down navigation bar.what i don't understand is why would display property won't work on a single li element.
.block1{background-color:#736570;margin:0px;}
ul a {color:white;}
ul li{list-style-type: none; padding:5px;}
.hidden {display:none;}
.home:hover .hidden{display:block;}
.hidden a:hover{background-color: #f1f1f1;}
<body>
<ul class="block1">
<li class="home">Home
<li class="hidden">
contact us
</li>
<li>about<li>
<li>Investor</li>
<li> what we do</li>
</li>
</ul>
</body>
Here is the new css you should use:
.block1{background-color:#736570;margin:0px;}
ul a {color:white;}
ul li{list-style-type: none; padding:5px;}
.hidden{display:none;}
.home:hover + .hidden{display:block;}
li:hover{background-color: #f1f1f1;}
Then your html should look like this:
<body>
<ul class="block1">
<li class="home">Home</li>
<li class="hidden" >
contact us
</li>
<li>about</li>
<li>Investor</li>
<li> what we do</li>
</ul>
</body>
Nothing too wrong with your html, just a mismatch <li>, and the css you want to look at this post: Using only CSS, show div on hover over <a>
Here is the JSFiddle: Example of OP Code
i don't understand is why would display property won't work on a
single li element.
The div with class .home is not the parent of li tag with class hidden. Hence it will never trigger a hover over that. Whenever you trigger a hover over a parent container it trickles down and find its children and does some sort of styling.
In your case, you are trying to use display:none to hide a li and make it display by means of hover.
Consider the snippet below, whenever you hover over the parent container, the li tag is being displayed. (This approach below does not make a drop down menu for you but it is give you some insight how to make that display property change on hover)
.block1 {
background-color: #736570;
margin: 0px;
}
ul a {
color: white;
}
ul li {
list-style-type: none;
padding: 5px;
}
.hidden {
display: none;
}
.block1:hover .hidden {
display: block;
}
.hidden a:hover {
background-color: #f1f1f1;
}
.home
<html>
<body>
<ul class="block1">
<li class="home">Home
<li class="hidden">
contact us
</li>
<li>about
<li>
<li>Investor</li>
<li> what we do</li>
</li>
</ul>
</body>
</html>
I do not want that the same color is side by side. At the moment: 1-2-1-1-2 but It must be: 1-2-1-2-1
HTML
<ul class="list list-unstyled">
<li>The_hangover_part_1.avi<span class="pull-right">25Gb</span></li>
<li>The_hangover_part_1_intro.avi<span class="pull-right">15Gb</span></li>
<li>Covers<span class="pull-right">255Kb</span></li>
<ul>
<li>the_hangover_part_1_cover_1.jpg<span class="pull-right">123Kb</span></li>
<li>the_hangover_part_1_cover_2.jpg<span class="pull-right">122Kb</span></li>
<li>the_hangover_part_1_cover_2.jpg<span class="pull-right">122Kb</span></li>
</ul>
</ul>
CSS
.list li:nth-child(even) {
background: transparent;
}
.list li:nth-child(odd) {
background-color: rgba(255,255,255,0.05);
}
First, you need to correct your HTML. The ul element can't be nested directly in another ul, it must be inside one of the lis:
<ul class="list list-unstyled">
<li>The_hangover_part_1.avi<span class="pull-right">25Gb</span></li>
<li>The_hangover_part_1_intro.avi<span class="pull-right">15Gb</span></li>
<li>Covers<span class="pull-right">255Kb</span>
<ul>
<li>the_hangover_part_1_cover_1.jpg<span class="pull-right">123Kb</span></li>
<li>the_hangover_part_1_cover_2.jpg<span class="pull-right">122Kb</span></li>
<li>the_hangover_part_1_cover_2.jpg<span class="pull-right">122Kb</span></li>
</ul>
</li>
</ul>
Then, when you get the correct markup, you can redefine the order of colors for sub-items of the odd items of the main list:
.list li:nth-child(odd) li:nth-child(odd) {
background: transparent;
}
.list li:nth-child(odd) li:nth-child(even) {
background-color: rgba(255,255,255,0.05);
}
This is because the :nth-child selector only looks at the position within its direct parent. To fix this, you can remove the li tags outside of their ul and indent them by giving them a class that contains the indentation style.
I am simply trying to get there to be a li:hover function that turns background of one list item black on hover. Please see my jsFiddle at here
<div id="sidebar">
<ul class="nav">
<li id="home">home</li>
<li id="about">about</li>
<li id="blog">blog</li>
<li id="contact">contact</li>
</ul>
Give a
position:relative;
z-index:999;
to the .nav element
Demo at http://jsfiddle.net/ATX9f/1/
#sidebar .nav li:hover {
background: black;
}
Your :before and :after are covering the lis that's why you can't hover them. your hover code is correct.
fixed using z-index here
I guess I am not getting css child combinators.
I am trying to target just the first level on the li's with the following:
ul > li { color: green; }
<ul>
<li>Home</li>
<li>
Products
<ul>
<li>Product 1 </li>
<li>Product 2</li>
<li>Product 3</li>
</ul>
</li>
<li>Contact</li>
<li>News</li>
</ul>
http://jsfiddle.net/5vB3h/
NOTE: I also tried removing the spaces between >, with no luck.
You're using them fine, but all (properly marked-up) <li>s are children of <ul>s. You can specify the parent (in your jsFiddle, body):
body > ul > li
Or reverse the styles with the more specific case:
li ul > li {
color: black;
}
In the case of color, you need to use the second option anyways, because color is inherited. Here's the updated jsFiddle.
Your rule targets the child list items of any list. What you can do is create a second rule to recolor the other sub list items. For example:
ul > li {
color: green;
}
li li {
color:black
}
jsFiddle example
ul will match all the <ul> elements. Since every <li> is a child of one of the <ul>s…
You need to be more specific about which <ul> you mean. Perhaps add a class to it.
ul > li will select all the li elements in your document because they are all the children of ul elements.
If you apply a class to the parent like <ul class="top">, then you can use ul.top > li.
Add a class
li {color: blue;}
/* ^ added because maybe initial property is color: inherit;
If not, someone correct me */
ul.a > li { color: red; }
After this, add class to ul like <ul class="a" ...
http://jsfiddle.net/5vB3h/7/
EDIT (worked it out):
Okay so I ballsed up. Below is wrong.
ul:first-child > li { color: green; }
I found that when applying:
div>ul>li{color:green}
all lis went green... turns out that the li magically inherit the color of the li (odd behaviour as I assume the content had color:#000)
anyway... You need to explicitly set the color: to soemthing other than green to see the style working.
fiddle here
//html
<div>
<ul>
<li>Home</li>
<li>
Products
<ul>
<li>Product 1</li>
<li>Product 2</li>
<li>Product 3</li>
</ul>
</li>
<li>Contact</li>
<li>News</li>
</ul>
</div>
//css
li {color:black} //you have to have this (or something like * {color:black} OR body/html {color:black} as li seem to automatically inherit parent li color property
div>ul>li{ color: green; } //have to have parent.