I have a navbar made up of a ul and some li and a elements, as shown below:
/*Fonts*/
#import url(https://fonts.googleapis.com/css?family=Libre+Baskerville);
/*Header*/
.header-wrapper {
background-color: #696969;
height: 53px;
width: 100%;
top: 0;
margin: 0;
padding: 0;}
.header-nav {
background-color: darkblue;
top: 0;
height: 48px;
margin: 0;
padding: 0;
list-style-type: none;}
.header-nav-element {
float: left;}
.header-nav-element-logo {
height: 48px;}
.header-nav-element-link {
display: block;
text-decoration: none;
color: white;
padding: 14px 16px;
font-family: "Libre Baskerville", serif;
transition-duration: 0.3s}
.active {
background-color: #696969;}
.header-nav-element-link:hover:not(.active) {
background-color: #808080;}
<div class="header-wrapper">
<ul class="header-nav">
<li class="header-nav-element noselect"><img src="../img/indexlogo.JPG" alt="" class="header-nav-element-logo"></li>
<li class="header-nav-element noselect active">Home</li>
<li class="header-nav-element noselect">Bio</li>
<li class="header-nav-element noselect">Stances</li>
<li class="header-nav-element noselect">Solutions</li>
</ul>
</div>
As you can see, the active tab is lighting up on hover, even though I have specified not to. Why is this happening, and how can I fix it?
It's because your :not(.active) is being applied to the a but the active class is on its parent, the li
You could fix it by doing this -
.header-nav-element:not(.active):hover .header-nav-element-link
Or by modifying the HTML by moving the active class to the element with the class header-nav-element-link.
As per the MDN documentation of :not():
This selector only applies to one element; you cannot use it to exclude all ancestors.
.header-nav-element is ancestor of .header-nav-element-link.
Change:
.header-nav-element-link:hover:not(.active) {
background-color: #808080;}
to:
.header-nav-element:hover:not(.active) {
background-color: #808080;}
Corrected snippet:
.header-nav {
background-color: darkblue;
top: 0;
height: 48px;
margin: 0;
padding: 0;
list-style-type: none;
}
.header-nav-element {
float: left;
}
.header-nav-element-logo {
height: 48px;
}
.header-nav-element-link {
display: block;
text-decoration: none;
color: white;
padding: 14px 16px;
font-family: "Libre Baskerville", serif;
transition-duration: 0.3s
}
.active {
background-color: #696969;
}
.header-nav-element:hover:not(.active) {
background-color: #808080;
}
<ul class="header-nav">
<li class="header-nav-element noselect"><img src="../img/indexlogo.JPG" alt="" class="header-nav-element-logo"></li>
<li class="header-nav-element noselect active">Home</li>
<li class="header-nav-element noselect">Bio</li>
<li class="header-nav-element noselect">Stances</li>
<li class="header-nav-element noselect">Solutions</li>
</ul>
Related
I have hardcoded padding for each of the padding hierarchy level.
I need the solution for any of level without hardcoding padding for each level.
.jdm-nav li {
font-size: 16px;
position: relative;
}
.jdm-nav li a {
padding-left: 15px;
}
.jdm-nav li li a {
padding-left: 30px;
}
.jdm-nav li li li a {
padding-left: 45px;
}
.jdm-nav li li li li a {
padding-left: 60px;
}
li li li li ... a
Every next step could be increased by 15px.
Full code example.
There is the mobile menu with ability to dropdown each item by click dropdown icon in the right item corner. If there are the items to expand.
.jdm-nav {
background-color: white;
width: 100%;
padding: 0;
}
.jdm-nav ul {
padding: 0;
}
.jdm-nav {
list-style: none;
}
.jdm-nav li {
list-style: none;
}
.jdm-nav ul {
margin: 0;
}
.jdm-nav a {
text-align: left;
display: flex;
color: rgb(76, 92, 104);
font-weight: 500;
padding: .5em 0;
font-size: 16px;
border-bottom: 1px solid rgba(76, 92, 104, 0.1);
}
.jdm-nav li {
font-size: 16px;
position: relative !important;
}
.jdm-nav li a {
padding-left: 15px;
}
.jdm-nav li li a {
padding-left: 30px;
}
.jdm-nav li li li a {
padding-left: 45px;
}
.jdm-nav li li li li a {
padding-left: 60px;
}
.jdm-nav li {
position: relative;
}
.jdm-nav li>[data-jdm-sub-menu-switcher] {
font-size: 13px;
display: flex;
width: 100%;
height: 100%;
border-bottom: 1px solid rgba(76, 92, 104, 0.1);
position: relative;
}
.jdm-nav li {
position: relative !important;
}
.jdm-nav li.menu-item-has-children>ul {
max-height: 0;
overflow: hidden;
transition: 150ms max-height ease-out;
}
.jdm-nav li.menu-item-has-children>ul[data-jdm-state="expanded"] {
max-height: initial;
}
.jdm-nav li.menu-item-has-children> :first-child {
grid-column: 1;
}
.jdm-nav li.menu-item-has-children>[data-jdm-sub-menu-switcher] {
grid-column: 2;
}
.jdm-nav li.menu-item-has-children>ul {
grid-row: 2;
grid-column-start: 1;
grid-column-end: 3;
}
.jdm-nav li>[data-jdm-sub-menu-switcher]::after {
position: absolute;
}
.jdm-nav li>[data-jdm-sub-menu-switcher]::after {
position: absolute;
width: 1em;
height: 1em;
content: '';
clip-path: url(#prefix-mobile-dropdown-clip-mask);
font-size: 13px;
background-color: rgb(76, 92, 104);
display: inline-flex;
top: 50%;
right: 50%;
transform: translateY(-50%) translateX(50%);
}
.jdm-nav li.menu-item-has-children {
display: grid;
grid-template-columns: 100fr 15fr;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
<div id="prefix-mobile-menu" class="mobile-menu-area prefix-mobile-menu" data-prefix-status="collapsed">
<nav id="mobile-menu" class="jdm-nav">
<ul id="primary-menu" class="menu-overflow">
<li id="menu-item-2420" class="menu-item-has-children">
1
<button data-jdm-sub-menu-switcher=""></button>
<ul class="sub-menu" style="" data-jdm-state="expanded">
<li id="menu-item-2418" class="menu-item-has-children">1.1
<button data-jdm-sub-menu-switcher=""></button>
<ul class="sub-menu" style="" data-jdm-state="expanded">
<li id="menu-item-2434" class="menu-item-has-children">1.1.1
<button data-jdm-sub-menu-switcher=""></button>
<ul class="sub-menu">
<li id="menu-item-2435">
1.1.1.1
</li>
<li id="menu-item-2436">1.1.1.2
</li>
<li id="menu-item-2437">1.1.1.3
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li id="menu-item-1832">2</li>
</ul>
</nav>
<svg width="0" height="0" viewBox="0 0 448 512">
<defs>
<clipPath
viewbox="0 0 448 512"
transform="scale(0.00223, 0.00195)"
clipPathUnits="objectBoundingBox"
id="prefix-mobile-dropdown-clip-mask">
<path fill="#000000"
d="M441.9 167.3l-19.8-19.8c-4.7-4.7-12.3-4.7-17 0L224 328.2 42.9 147.5c-4.7-4.7-12.3-4.7-17 0L6.1 167.3c-4.7 4.7-4.7 12.3 0 17l209.4 209.4c4.7 4.7 12.3 4.7 17 0l209.4-209.4c4.7-4.7 4.7-12.3 0-17z"
class=""></path>
</clipPath>
</defs>
</svg>
</div>
Put the padding on the li and stretch the left of the a out by a large fixed amount.
Illustrated:
body > ul {
border: 1px solid #eee;
border-radius: 2px;
margin: 1em;
padding: 1em;
overflow: hidden;
}
ul {
list-style: none;
padding: 0;
}
li {
padding-left: 15px;
}
a {
display: block;
margin-left: -150px;
margin-right: -1em;
padding-left: 150px;
}
a:hover {
background-color: #cff;
}
<ul>
<li>
nested
<ul>
<li>
navigation
<ul>
<li>
forever
<ul>
<li>
and
<ul>
<li>
ever
</ul>
</ul>
</ul>
<li>
foo
<li>
bar
</ul>
<li>
baz
</ul>
(Notice how the clickable area of each link extends all the way to the left.)
you can use this code for solve your problem
.jdm-nav li {
font-size: 16px;
position: relative;
}
.jdm-nav li{
font-size:1.2em;
padding-left: 3em;
}
.jdm-nav li a {
background-color:red;
font-size:16px;
}
<ul class="jdm-nav">
<li>
<a>Item1</a>
<ul>
<li>
<a>Item2</a>
<ul>
<li>
<a>Item3</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
use pseudo function of css to increase the padding of every children by 15px.
I'm having an issue with my anchors not covering full width of the sidebar (for instance, 'Search'). I realise that this is because of padding, but I'm not sure how to overcome the issue whilst keeping the padded effect. I have tried to add a class (like, '.no-submenu) on the <li> and did .no-submenu a { margin: 0 -1.5rem; padding: 0 3rem; }, but it only partially solved the problem - my icons were off, they go all the way to the left:
I couldn't find the place online to upload SVG files (my icons are SVG), so I created a minimal example without icons. Icons are handled as background-image on the anchors.
<div class="sidebar">
<nav>
<ul class="menu">
<li id="search">
<a class="sidebar-icon" href="/search/notes/">Search</a>
</li>
<li id="dashboard">
<a class="sidebar-icon">Dashboard</a>
</li>
<li id="notebooks" class="has-submenu">
<div class="menu-item">
<span class="sidebar-icon">Notebooks</span>
<span class="arrow"></span>
</div>
<ul class="submenu">
<li id="new-notebook"><a class="sidebar-icon" href="/notebooks/create/">New Notebook</a></li>
<li id="view-notebooks"><a class="sidebar-icon" href="/notebooks/">View Notebooks</a></li>
</ul>
</li>
<li id="tags" class="has-submenu">
<div class="menu-item">
<span class="sidebar-icon">Tags</span>
<span class="arrow"></span>
</div>
<ul class="submenu">
<li id="view-tags"><a class="sidebar-icon" href="/tags/">View Tags</a></li>
</ul>
</li>
<li id="account" class="has-submenu">
<div class="menu-item">
<span class="sidebar-icon">Account</span>
<span class="arrow"></span>
</div>
<ul class="submenu">
<li id="settings"><a class="sidebar-icon" href="/accounts/settings/">Settings</a></li>
<li id="logout"><a class="sidebar-icon" href="/accounts/logout/">Logout</a></li>
</ul>
</li>
</ul>
</nav>
</div>
CSS:
#import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,300,600);
#font-face { font-family: "ionicons"; src: url("https://code.ionicframework.com/ionicons/2.0.1/fonts/ionicons.eot?v=2.0.1"); src: url("https://code.ionicframework.com/ionicons/2.0.1/fonts/ionicons.eot?v=2.0.1#iefix") format("embedded-opentype"), url("https://code.ionicframework.com/ionicons/2.0.1/fonts/ionicons.ttf?v=2.0.1") format("truetype"), url("https://code.ionicframework.com/ionicons/2.0.1/fonts/ionicons.woff?v=2.0.1") format("woff"), url("https://code.ionicframework.com/ionicons/2.0.1/fonts/ionicons.svg?v=2.0.1#Ionicons") format("svg"); font-weight: normal; font-style: normal; }
.sidebar {
width: 200px;
height: 100vh;
padding: 1rem 1.5rem;
background-color: #348ceb;
font-family: 'Source Sans Pro';
font-size: 14px;
position: fixed;
box-sizing: border-box;
}
ul {
list-style: none;
}
ul, li {
padding: 0;
margin: 0;
}
li {
padding: 0.5rem 0;
}
.submenu {
display: none;
overflow-y: hidden;
margin: 0 -1.5rem;
background-color: #3287e3;
}
.submenu li:first-child {
padding: 0.1rem 0 0 1.5rem;
}
.submenu li:last-child {
padding: 0 0 0.1rem 1.5rem;
}
.submenu li {
padding: 0.5rem 1.5rem;
}
.menu > li:hover {
background-color: #3287e3;
}
.menu > li {
position: relative;
color: #F9FAFC;
font-weight: bold;
margin: 0 -1.5rem;
padding: 0.5rem 1.5rem;
}
.menu > li > a {
display: block;
color: #F9FAFC;
text-decoration: none;
font-weight: bold;
}
.menu > li > a:hover {
color: white;
}
.submenu > li > a {
display: block;
color: #F9FAFC;
text-decoration: none;
}
.submenu > li > a:hover {
color: white;
}
.submenu > li {
font-weight: normal !important;
}
.arrow {
display: inline-block;
width: 10px;
transition: all 0.5s ease-in-out;
transform-origin: left center;
font-size: 0.5em;
position: absolute;
right: 0.75em;
}
.arrow:after {
content: '\f125';
font-family: 'ionicons';
color: white;
}
.rotated {
transform: rotate(90deg);
transition: transform 0.5s ease;
}
.menu-item {
display: flex;
align-items: center;
}
.menu-item > span:first-child {
flex: 1;
}
.sidebar-icon {
background-repeat: no-repeat;
padding-left: 25px;
}
JS (jQuery):
$(document).ready(function() {
$('.has-submenu').click(function() {
$(this).toggleClass('active');
$(this).children('.menu-item').children('.arrow').toggleClass('rotated');
if ($(this).hasClass('active')) {
$(this).children('.submenu').slideDown("slow");
}
else {
$(this).children('.submenu').slideUp("slow");
}
});
});
How can I overcome the issue?
Here is the demo.
#EDIT:
so, I want this:
but the menu item has to be fully clickable, i.e. you can click on any part of it and it brings you to, say, Search. To see the area it currently covers, right-click on the anchor or inspect the element.
I guess this is what you want:
<li style="padding: 0.5rem 0" id="search">
<a style="width: 100% !important; padding: none" class="sidebar-icon" href="/search/notes/">
<i style="padding-right: 10px">#</i>Search</a>
</li>
link to codepen
I'm trying to make it so there is a max-height (or height) set to this very long list, and for the rest to scroll. I was able to easily achieve that with
height:800px;
overflow:scroll;
The Problem I have is that the "#subcategory" items stop displaying on hover when I apply overflow:scroll
Any ideas are greatly appreciated!
Basic HTML Structure
<!-- Start Auto Transport -->
<li id="topCategory">Auto Transport
<ul id="subContainer">
<li id="subCategory">Auto Insurance</li>
<li id="subCategory">Auto Payment</li>
<li id="subCategory">Gas</li>
<li id="subCategory">Parking</li>
<li id="subCategory">Public Transportation</li>
<li id="subCategory">Service Parts</li>
<!-- add new becomes text field, user enters text then it becomes added as category -->
<li class="hideNewCategory">
<a class="mmNewCat" data-number="1" href="#"><i class="icon ion-plus-circled"></i>Add New Category</a>
<input id="mmCat1" class="mmCatInpt" type="text" placeholder="Enter New Category" maxlength="25"></input>
</li>
</ul>
</li>
<!-- End Auto Transport -->
<!-- Start Bills Utilities -->
<li id="topCategory">Bills & Utilities
<ul id="subContainer">
<li id="subCategory">Domain Names</li>
<li id="subCategory">Fraud Protection</li>
<li id="subCategory">Home Phone</li>
<li id="subCategory">Hosting</li>
<li id="subCategory">Mobile Phone</li>
<li id="subCategory">Television</li>
<li id="subCategory">Utilities</li>
<!-- add new becomes text field, user enters text then it becomes added as category -->
<li class="hideNewCategory">
<a class="mmNewCat" data-number="2" href="#"><i class="icon ion-plus-circled"></i>Add New Category</a>
<input id="mmCat2" class="mmCatInpt" type="text" placeholder="Enter New Category" maxlength="25"></input>
</li>
</ul>
</li>
<!-- End Bills Utilities -->
relevant CSS
ul li:hover #topContainer{
display: block;
}
ul li a {
display: block;
color: $blue;
text-decoration: none;
font-family: verdana;
font-size: 14px;
}
#topContainer{
list-style: none;
color: $blue;
width: 260px;
height: auto;
background: $white;
opacity: 0.9;
position: absolute;
z-index: 1000;
height:800px;
overflow:scroll;
}
#topCategory {
float: none;
width: auto;
height: 20px;
text-align: left;
margin-left: 15px;
}
#topCategory a:hover {
color: $white;
background-color: $blue;
}
#topCategory:hover #subContainer {
display: block;
}
#topCategory a {
font-size: 16px;
position: relative;
bottom: 41px;
margin-top: 46px;
margin-left: -15px;
padding: 20px 0 20px 20px;
border-bottom:1px solid $grey-10;
}
#topCategory a:hover {
color: $white;
}
#subContainer {
list-style: none;
color: $blue;
display: none;
font-size: 12px;
min-width: 230px;
width: 150px;
height: auto;
background: $white;
opacity: 0.9;
margin: -107px 0 0 245px; position: absolute;
z-index: 1000;
white-space:nowrap;
}
#subContainer a{
border-bottom:1px solid $grey-10;
margin-top: 41px;
}
#subCategory {
float: none;
width: auto;
height: 20px;
text-align: left;
margin-left: 10px;
}
#subCategory:hover {
background: none;
}
.active {
background: $white;
}
#subCategory {
float: none;
// hover length
width:215px;
// hover length
text-align: left;
height: 25px;
margin-left: 15px;
margin-right: -43px;
}
Subcategory should be a Class name not an Id element, change that and things will look cleaner.
.subcategory {
}
<div class="subcategory"></div>
Bit new at CSS and been looking around at various sites and bits of code trying to get a centered drop down menu which I managed to get :).
However as soon as I added some images to make up the heading the menu shifted off to the left and I have not been able to budge it ever since, any help? Code is below.
<style type="text/css">
<!--
body {
background-image: url();
background-color: #0099FF;
}
.style1 {color: #FFCC00}
.style2 {color: #FF9900}
.style3 {
color: #FFCC00;
font-weight: bold;
font-size: 12px;
}
.style4 {
color: #000099;
font-weight: bold;
}
.style5 {color: #000099; font-weight: bold; font-size: 12px; }
.style6 {color: #000099}
* { padding: 0; margin: 0; }
body { padding: 5px; }
ul { list-style: none; margin: auto}
ul li { float: left; padding-right: 0px; position: relative; }
ul a { display: table-cell; vertical-align: middle; width: 100px; height: 50px; text-align: center; background-color: #0099EE; color: #000000; text-decoration: none; border: 1px solid #000000;}
ul a:hover { background-color: #0066FF; }
li > ul { display: none; position: absolute; left: 0; top: 100%; }
li:hover > ul { display: inline; }
li > ul li { padding: 0; padding-top: 0px; }
#menu-outer {
height: 84px;
background: url(images/bar-bg.jpg) repeat-x;
}
.table {
display: table;
margin: 0 auto;
}
ul#horizontal-list {
min-width: 696px;
list-style: none;
padding-top: 20px;
}
ul#horizontal-list li {
display:inline
}
-->
</style></head>
<body>
<div id="menu-outer"></div>
<div class="table"></div>
<div align="center"><img src="logo_with_words_3.jpg" width="172" height="145"><img src="heading.gif" width="557" height="69"><img src="logo_with_words_3.jpg" width="172" height="145">
</div>
<ul id="horizontal-list">
<li>
Home
</li>
<li>About Us
<ul>
<li>History</li>
<li>Guest Comments</li>
</ul>
<li>News</li>
<li>Accommodation
<ul>
<li>Rooms</li>
<li>Bedrooms</li>
<li>St Joseph's Annexe</li>
</ul>
<li>Visiting St Katharine's
<ul>
<li>Retreats</li>
<li>B&B</li>
<li>Events</li>
<li>Conferences</li>
<li>Catering</li>
</ul>
<li>Contact Us
<ul>
<li>Find Us</li>
</ul>
<li>Walled Garden</li>
<li>Sue Ryder Legacy
<ul>
<li>Sue Ryder</li>
<li>Prayer Fellowship</li>
<li>LRWMT</li>
</ul>
</ul>
</body>
You aren't really using a table, but you can add something like this: #horizontal-list {margin: auto; width: 850px;}
JS Fiddle with your code
Right now the parent menu has an opacity shift on hover, this is being transferred to the sub menu (current & previous) as well. I want the sub menu to have a clear background so that the opacity band of the parent is the only thing that is visible. Is there a way to use an li class for the submenu that makes it exempt from the li class that is governing the parent. I've been trying different things but can't seem to make it work properly.
Demo
HTML
<div>
<ul id="mainmenu">
<li class="liHome">
<a class="maintextcolour" href="#item-x1y1" id="Home" rel=
"none">INFO</a>
</li>
<li class="liServices">
<a class="maintextcolour" href="#item-x1y2" id="Services" rel=
"SubMenuY2">EXHIBITIONS</a>
<ul class="submenu" id="SubMenuY2">
<li class="sub1">
<a class="maintextcolour" href="#">CURRENT</a>
</li>
<li class="sub1">
<a class="maintextcolour" href="#">PREVIOUS</a>
</li>
</ul>
</li>
<li id="liEnvironment">
<a class="maintextcolour" href="#item-x1y3" id="Environment"
rel="none">CV</a>
</li>
<li id="liCareer">
<a class="maintextcolour" href="#item-x1y4" id="Career" rel=
"none">NEWS</a>
</li>
<li id="liContact">
<a class="maintextcolour" href="#item-x1y5" id="Contact" rel=
"none">MORE</a>
</li>
</ul>
</div>
CSS:
#charset UTF-8;
/* CSS Document */
body {
background-color: #666;
background-size: 100%;
background-repeat: no-repeat;
}
#mainmenu {
margin: 0;
padding: 0;
list-style-type: none;
position: relative;
}
#mainmenu li {
clear: left;
position: relative;
}
#mainmenu a {
display: block;
overflow: hidden;
float: left;
width: 100%;
position: relative;
opacity: 1;
-webkit-transition: all .4s ease-in-out;
padding-left: 20px;
}
#mainmenu li:hover a {
background-position: 0 0;
background-color: clear;
background-color: rgba(255,255,255,0.5);
width: 100%;
opacity: 0;
-webkit-transition: none;
}
#mainmenu li.active a {
background-position: 0 0;
background-color: clear;
width: 100%;
}
.submenu {
list-style-type: none;
float: left;
display: none;
position: absolute;
left: 135px;
top: 0;
width: auto;
}
#mainmenu li a:hover + .submenu,.submenu:hover {
display: block;
}
.submenu li {
display: inline-block;
clear: none !important;
}
.submenu li a {
float: right;
margin-left: 10px;
}
.maintextcolour {
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
color: #FFF;
text-decoration: none;
}
.maintextcolour:hover {
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
color: #0FF;
text-decoration: none;
}
.headertext {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #FFF;
text-decoration: none;
}
Here is the updated Fiddle link. I have just added color to the following css:
#mainmenu > li:hover > a {
background-position: 0 0;
background-color:clear;
color:#0fffff;
background-color:rgba(255,255,255,0.5);
width:100%;
\
opacity: 0;
-webkit-transition: none;
}
Hope you want this.