The following is a TOC I have implemented on an instance of Confluence.
It's look has been customized so that when hovering over a menu item with the mouse, the corresponding menu item is highlighted as in the case of the 2. Navigation Bar menu item in the above image.
The hover effect is achieved via the following CSS code:
.toc-link:hover {
background-color: #e5e5e5;
text-decoration: none;
}
I'd like for the hover effect to span the entire width of the box though, similar to the image below:
What property would I have to insert into my CSS code to achieve the desired effect?
Thank you.
This can be achieved by setting display:block on your <a> element. The hover styles should be on your anchor tag, not on your <li>, for example:
a {
display: block;
text-decoration: none;
}
a:hover {
background-color: #e5e5e5;
}
<ul>
<li>Item</li>
<li>Item</li>
<li>Item</li>
</ul>
If your list items do not have an anchor tag inside, you can achieve it like so:
li {
display: block;
}
li:hover {
background-color: #e5e5e5;
}
<ul>
<li>Item</li>
<li>Item</li>
<li>Item</li>
</ul>
You can try this:
#content {
border: 1px solid #DDDDDD;
background-color: #F6F6F6;
padding-right: 25px;
}
li{
padding: 5px;
list-style: none;
}
li:before {
content: "• ";
color: #ABADBB;
}
li:hover {
background-color: #DDDDDD;
}
<div id="content">
<ul>
<li>
Opening the Asset Browser
</li>
<ul>
<li>1. Menu</li>
<li>2. Navigation Bar</li>
<li>3. Folder Tree</li>
<li>4. Search Result Pane</li>
</ul>
<li>
Live Updates for Asset Resources Selectors
</li>
<li>
Texture Tool-tips
</li>
</ul>
</div>
Related
I have css width problem with my menu and submenu
My menu is horizontaly like -
<ul>
<li> Menu <div style="diplay:none"> Submenu </li>
<li> Menu <div style="diplay:none"> Submenu </li>
</ul>
The width of <li> is auto, when hover on <li> the display but when the div width is bigger than the<li> ,there is a gap
I want that the <li> width doesn't move whenever I hover
Do you have a solution to keep <li> width fixed when I hover ?
Thanks
Typically dropdown menus are positioned absolutely within their relatively positioned parent element so they do not take up any space.
Here is a basic example. Modify to your needs.
ul, li {
margin: 0;
padding: 0;
}
.menu li {
display: inline-block;
background-color: rgba( 123, 123, 123, 1 );
cursor: pointer;
}
.menu li:hover {
background-color: rgba( 123, 123, 123, 0.5 );
}
.has-submenu {
position: relative;
}
.has-submenu li {
display: block;
}
.has-submenu > ul {
display: none;
position: absolute;
width: 100%;
}
.has-submenu:hover > ul {
display: block;
}
<ul class="menu">
<li>Item</li>
<li class="has-submenu">
Item with submenu
<ul>
<li>Item</li>
<li>Item</li>
</ul>
</li>
<li>Item</li>
</ul>
Here is the menu html code for the nav bar:
<nav>
<div id="menu">
<ul>
<li>Home Page</li>
<li>History</li>
<li>Events</li>
<li>Information</li>
<li>Photos</li>
<li>Contact Us</li>
<li>Useful Links</li>
</ul>
</div>
</nav>
and here's the code for css :
nav{
float: left;
margin-top: 15px;
}
nav ul {
list-style: none;
margin: 0;
padding: 0px 0px 0px 0px;
}
nav li {
display: inline-block;
}
nav a {
padding: 8px 0px;
margin-right:71px;
color: #ffffff;
display: block;
text-decoration: none;
text-transform: capitalize;
font-size: 13px;
}
nav a:hover {
color: #cccccc;
}
So for example, if I am currently looking at history page, the text "History" in the navbar will be red. How can I do such a thing?
#edit: As stated in a comment, I am trying to avoid jquery.
This is a great resource for beginners: W3Schools
This page on that site contains the answer to your question: CSS Text Formating
I don't mean to be vague, but your question is a little unclear.
just add active class name in the active state link.
<li>Home Page</li>
<li>History</li>
<li><a class="active" href="events.html">Events</a></li>
<li>Information</li>
And in your CSS
nav a.active {
color: red;
}
You will need to use jQuery to add an active class to the anchor tag that corresponds with the page that you are on. Once that is done you can style it like this a.active {color:red}
If these are individual HTML pages you could also just manually apply the active class to the anchor tag for that page.
The CSS attribute you are describing is a CSS selector. Your CSS will be as follows, which will target all "active" hrefs in the div ID menu
#menu a:active {
color: blue;
}
I am trying to make a horizontal drop down menu in CSS. However, it appears vertically:
I want the two topmost menu items to be horizontal. What can I do, besides making a table with one row?
ul ul {
display: none;
}
ul li:hover > ul {
display: block;
}
<ul>
<li>
abc
<ul>
<li>abc</li>
<li>abc</li>
</ul>
</li>
<li>
abc
<ul>
<li>abc</li>
<li>abc</li>
</ul>
</li>
</ul>
You can try floating the list items:
.root {
overflow: hidden; /* clear float */
}
.root > li {
float: left;
}
<ul class="root">
<li>
abc
<ul>
<li>abc</li>
<li>abc</li>
</ul>
</li>
<li>
abc
<ul>
<li>abc</li>
<li>abc</li>
</ul>
</li>
</ul>
You can add submenu a class/id with
.inline-menu{
display: inline;
}
http://jsfiddle.net/dyaskur/fby9fan6/
The gist of your question is actually this: what is the difference between inline and block elements? This is a fundamental question that is important to understanding the basics of layout in CSS/HTML. There is a good write-up on this topic and some of the trade-offs of the various approaches at:
http://designshack.net/articles/css/whats-the-deal-with-display-inline-block/
Basically, <li> is block-level tag, meaning that it displays as its own "block" element: receives a layout (settable dimensions), by default takes the entire width of the parent element, and has a forced break after the rendered element (is on a line to itself).
So, that leaves us with a number of approaches for having your menu items sit side-by-side:
Use inline-level elements for your menu items
Use block-level elements and float them
Use block-level elements and style them as inline-block
All of these approaches are detailed in the above link. Personally, I prefer to use floated block elements. I have a fiddle with some rough css to give you an idea. Note that there are some considerations in how to display your submenus as well. You'll note that I've implemented these as having display: block, with no float, because we want them to stack vertically.
HTML
<ul class="menu">
<li>
foo
<ul class="submenu">
<li>subfoo1</li>
<li>subfoo2</li>
</ul>
</li>
<li>
bar
<ul class="submenu">
<li>subbar1</li>
<li>subbar2</li>
</ul>
</li>
</ul>
CSS
ul.menu {
list-style: none;
}
ul.menu > li{
float: left;
position: relative;
}
ul.menu li {
background-color: #cccccc;
padding: 5px 20px;
}
ul.menu > li + li {
border-left: solid black 2px;
}
ul.menu li:hover > ul {
display: block;
}
ul.menu li a,ul.menu li a:link, ul.menu li a:hover, ul.menu li a:visited {
color: black;
text-decoration: none;
}
ul.submenu{
display: none;
list-style: none;
position:absolute;
left: 0;
padding: 0;
}
ul.submenu li {
float:none;
display: block;
}
ul.submenu > li + li {
border-top: solid black 1px;
}
You can just remove some <li> tags:
<ul>
<li>
abc
<ul>
abc
abc
</ul>
</li>
<li>
abc
<ul>
abc
abc
</ul>
</li>
</ul>
I have the following html
<ul>
<li class="main"> Main 1
<ul>
<li class="sub">Sub 1</li>
<li class="sub">Sub 2</li>
<li class="sub">Sub 3</li>
</ul>
</li>
<li class="main"> Main 2 </li>
<li class="main">Main 3 </li>
</ul>
I want the background-color of the first level change on mouse over. But when I try this code
.main:hover {
background-color: red;
}
.sub:hover {
background-color: none;
}
The sublevel menu also gets changed. Is there a way to change only the background of the outside element.
This code can be seen in action in this codepen.
http://codepen.io/anon/pen/Bvauf
What you're seeing is the background of .main, because the children's backgrounds are transparent. You could explicitly set it to white:
.main:hover {
background-color: red;
}
.main:hover > ul {
background-color: #fff;
}
Or
.main ul {
background-color: #fff;
}
.sub {
background-color: white;
}
You should go with setting background colors to ul and not li as others have suggested
I'm currently trying to create a drop-down menu from nested unordered lists. I have the menu working however I'm having some issues with regards to styling. The overall link that triggers the drop-down is clickable and needs to have a blue background with white text however, the drop-down elements need to have a grey background which is inherited from the overall navigation container. All I need to do is modify the text colour however whatever I method I try it always modifies the drop-down text colour as well as the heading link colour.
My CSS can be found below along with an example of the current display and the html used to generate the menu:
/*CSS*/
#coolMenu,
#coolMenu ul {
list-style: none;
}
#coolMenu {
float: right;
}
#coolMenu > li {
float: left;
}
#coolMenu li a {
display: block;
/*height: 2em;
line-height: 2em;
*/
/*padding: 0 1.5em;*/
text-decoration: none;
color: #ffffff;
}
#coolMenu ul {
position: absolute;
display: none;
z-index: 999;
}
#coolMenu li:hover ul {
display: block;
}
.dropdown a li{
color: #124162 !important;
}
#style_me > li > a{
color: #124162 !important;
}
/HTML/
<nav id="navigation" class="navigation">
<ul>
<li class="current">Home</li>
<li>Who Are We?</li>
<li>Why Join Us?</li>
<li>Contact Us</li>
</ul>
/* This is the menu element that needs styling */
<ul id="coolMenu">
/* THis should be blue background white text */
<li>Login / Register
<ul id="style_me">
/* These should be grey background blue text */
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
<li>Link 5</li>
<li>Link 6</li>
<li>Link 7</li>
</ul>
</li>
</ul>
</nav>
Any help would be greatly appreciated. It's been a couple of years since I've had to do any CSS and my memory is a bit flakey!
This should do what you want:
#style_me li a {
color: #124162 !important;
}
(just spaces instead of >) And, perhaps, you won't need that !important.
Update: try even more specific CSS selector if what you posted is being overridden.
#coolMenu li #style_me li a {
color: #124162 !important;
}