Anchor does not stretch across full width of the sidebar - css

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>

Related

How to do margin-top only in Firefox browser

I have menu bar which need to be margin-top: 150px;
But visually in Firefox looking different as on Chrome.
Header code: https://codepen.io/bugerman21/pen/rNxvyOv
Chrome:
Correct display
Firefox:
Incorrect display
HTML:
<nav>
<ul class="nav">
<li class="category"><span>Category <i class="fas fa-sort-down"></i></span>
<ul>
<li>Qwerty 1</li>
<li>Qwerty 2</li>
<li>Qwerty 3</li>
<li>Qwerty 4</li>
</ul>
</li>
<li>Cuntact us</li>
<li>FAQ</li>
</ul>
CSS:
* {
margin: 0;
pading: 0;
}
.nav li ul {
position: absolute;
margin-top: 150px;
min-width: 150px;
list-style-type: none;
display: none;
}
How to do margin-top only for the Firefox browser?
Unsuccessful attempt:
#-moz-document url-prefix() {
.nav li ul {
margin-top: 150px;
}
}
Here ya go buddy, sorry I left for the day yesterday but see the changes made and I left outlines on the elements to give a better visual reference. As it is now it will display as expected on all browsers even old internet explorer. Although you could accomplish the same thing cleaner overall, this at least gets you back on track. Cheers and welcome to StackOverflow! :)
PS : since the nav menu items don't have a fixed height you might want to consider making that something static so you can change the top: 56px to a value that places the drop down consistently no matter the width of the screen. If you make the example full screen you'll see what I mean.
header {
display: flex;
margin: 0;
padding: 0 20px;
justify-content: space-between;
align-items: center;
background-color: silver;
}
.header {
grid-area: header;
background-color: #1f1f1f;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
}
/*---------- Logo ----------*/
.logo {
font-family: 'Gentium Book Basic', serif;
font-size: 2.5em;
color: #808080;
}
/*---------- Nav menu ----------*/
.nav {
list-style-type: none;
display: flex;
justify-content: flex-start;
margin: 0;
}
.nav > li {
text-decoration: none;
font-family: 'Roboto', sans-serif;
color: #ffffff;
transition: background-color .25s ease;
}
.nav a {
display: block;
padding: 20px;
color: #ffffff;
font-size: 1em;
}
.category {
padding: 0 20px;
display: flex;
align-items: center;
position: relative;
overflow: visible;
border: red 1px solid;
}
/*---------- Sub menu ----------*/
.nav li ul {
position: absolute;
top: 56px;
left: 0;
min-width: 150px;
margin: 0;
padding: 0;
list-style-type: none;
display: none;
border: green 1px solid;
}
.nav li > ul li {
border-bottom: 1px solid #ffffff;
background-color: #1f1f1f;
}
.nav li > ul li a {
text-transform: none;
}
.nav li:hover > ul {
display: block;
}
.nav > li:hover {
background-color: #404040;
/* box-shadow: -5px 5px #1f1f1f; */
}
.nav li ul > li:hover {
background-color: #404040;
}
/*---------- Search & Profile----------*/
.search_and_profile {
display: flex;
align-items: center;
}
.search_and_profile > p {
margin: 0;
color: #ffffff;
}
.search-container button {
float: right;
padding: 6px 10px;
background: #e0e0e0;
font-size: 17px;
border: none;
cursor: pointer;
}
.search-container input[type=text] {
padding: 6px;
font-size: 17px;
border: none;
}
<header class="header">
<span class="logo">Qwerty</span>
<nav>
<ul class="nav">
<li class="category"><span>Category <i class="fas fa-sort-down"></i></span>
<ul>
<li><a href=#>Qwerty 1</a></li>
<li>Qwerty 2</li>
<li>Qwerty 3</li>
<li>Qwerty 4</li>
</ul>
</li>
<li>Cuntact us</li>
<li>FAQ</li>
</ul>
</nav><!-- .nav -->
<div class="search_and_profile">
<div class="search-container">
<form action="#">
<input type="text" placeholder="Search.." name="search">
<button type="submit"><i class="fa fa-search"></i></button>
</form>
</div><!-- .search-container -->
</div><!-- .search_and_profile -->
</header>
It will work for me, additionally i included color too to make sure.
Also you try this option too
#media screen and (-moz-images-in-menus:0) {
/* your style */
}
* {
margin: 0;
pading: 0;
}
.nav li ul {
position: absolute;
margin-top: 150px;
min-width: 150px;
list-style-type: none;
display: none;
}
/* Added */
#-moz-document url-prefix('') {
.nav li ul {
margin-top: 150px;
color: orange;
}
}
<div class="nav">
<ul>
<li>Home</li>
<li>About
<ul>
<li>Some text</li>
<li>Some more text</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div>

Animated, permanent dropdown from navigation like example. How to accomplish?

I really like the result of clicking the plus button at the end of the navigation on this page. http://demo.dinevthemes.com/planum/
I wanted to incorporate something similar into a site, but can't get it to work. From what I can tell, this is the code they're using, but when I test it out, the item stays visible and doesn't hide.
Any tips on why I am doing it wrong?
You can see the site I am incorporating it to here - http://dismantledesign.com/testsite/
.toggle-top::before {
content: none;
display: inline-block;
font-family: "FontAwesome";
font-size: 18px;
font-style: normal;
font-weight: normal;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.toggle-top:before {
content: '\f067';
}
.menu-toggle::before, .toggle-top::before {
color: #1CCCA0;
}
.toggle-top {
display: block;
position: absolute;
right: 72px;
top: 44px;
}
.toggle-top.top-display:before {
padding-left: 5px;
padding-top: 0;
content: '\f068';
}
.top-left {
width: 35%;
}
.top-left,.top-right {
float: left;
}
.top-right {
text-align: right;
width: 65%;
padding-right: 40px;
padding-top: 15px;
}
.top-wrapper {
display: none;
background: #DEDEDE;
padding: 24px 72px;
}
.top-wrapper form {
margin: 0;
}
.top-wrapper ul.menu li {
display: inline-block;
padding-left: 10px;
}
.top-wrapper ul.menu,.navigation-main ul {
padding-left: 0;
list-style: none;
margin: 0;
}
<div class="top-wrapper clearfix" style="display: block;">
<div class="top-left">
<form method="get" id="searchform" class="searchform" action="http://demo.dinevthemes.com/planum/" role="search">
<label for="s" class="screen-reader-text">Search</label>
<input type="search" class="field" name="s" value="" id="s" placeholder="Search">
<input type="submit" class="submit" id="searchsubmit" value="Search">
</form>
</div>
<div class="top-right">
<div class="menu-topic-container"><ul id="menu-topic" class="top-menu"><li id="menu-item-3084" class="menu-item menu-item-type-custom menu-item- object-custom menu-item-3084">+1 915 00-00-00</li>
<li id="menu-item-2967" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-2967">current location</li>
</ul></div> </div>
</div>
The site you are referring to is using jQuery for toggleClass and the slideDown effect. I created a small jsFiddle example that shows you how you can build it on your own.
Rather then adding a lot of animation with javascript, I implemented only one function for the toggle of classes .active for the plus-icon and .open for the subnav. The animation is done with css. In the beginning the subnav has top: 0 and is not visible because it is below the main-nav. But when we toggle the class open it will move below the main-nav and is visible.
If you have any remaining questions, use the comment section.
$(".subnav-toggle").click(function() {
$(this).toggleClass("active");
$(".subnav").toggleClass("open");
});
body {
margin: 0;
padding: 0;
}
ul {
margin: 0;
padding: 0;
}
ul li {
display: inline-block;
list-style-type: none;
}
.nav {
background: #fff;
position: relative;
z-index: 2;
}
.subnav {
position: absolute;
top: 0;
background: #ccc;
width: 100%;
z-index: 1;
transition: .25s all;
}
.subnav.open {
top: 58px;
}
.fa::before {
content: none;
display: inline-block;
font-family: "FontAwesome";
font-size: 18px;
font-style: normal;
font-weight: normal;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.nav--item a {
display: block;
padding: 20px;
text-decoration: none;
}
.subnav-toggle.active {
background: #ccc;
}
.subnav-toggle:before {
content: '\f067';
}
.subnav-toggle.active:before {
content: '\f068';
}
.nav--item.last {
float: right;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<nav>
<ul class="nav">
<li class="nav--item">Markup</li>
<li class="nav--item">Pages</li>
<li class="nav--item">Levels</li>
<li class="nav--item">Categories</li>
<li class="nav--item"></li>
</ul>
<div>
<ul class="subnav">
<li class="nav--item">Markup</li>
<li class="nav--item">Pages</li>
<li class="nav--item">Levels</li>
<li class="nav--item">Categories</li>
</ul>
</div>
</nav>

HTML5 & CSS3 Dropdown Menu & Google Fonts only working in Chrome

I'm pretty new to HTML5 and CSS3 and I've been developing a new website for my NGO. I'm pretty much done all the design, but I can't get my drop down menu to work in IE, and I can't get the Google Font I'm using to work in IE or Firefox.
I have a drop down menu with the org logo in the middle and the menu text floating at the vertical center of the logo on either side. In Chrome this works just as I want it to, but when I open it in IE11 the menu text is floating at the very top of the page, and the drop down boxes don't line up correctly. All of it lines up correctly in Firefox, but the Google Font 'Lato' that I'm using only works in Chrome.
Here is the HTML for the header:
/* Header */
* {margin: 0;padding: 0 ;outline: none;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;-o-box-sizing: border-box;-ms-box-sizing: border-box;box-sizing: border-box;}
*:after, *:before { -webkit-box-sizing: border-box;-moz-box-sizing: border-box;-o-box-sizing: border-box;-ms-box-sizing: border-box;box-sizing: border-box;}
article,aside,details,figcaption,figure,footer,header,hgroup,nav,section { display: block; }
html {font-size: 60%;height: auto; !important;height: 100%;-webkit-text-size-adjust: 100%;-ms-text-size-adjust: 100%;-o-box-sizing: border-box;-moz-box-sizing: border-box; }
.clear {display: block; }
.clear::after {clear: both;content: ".";display: block;height: 1px;visibility: hidden;}
/*GENERIC STYLES*/
body {background: url('../images/bg-tile-grey-2.png') font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 1.05em;font-weight: 400;height: auto !important;height: 100%;min-height: 100%;}
/*NAV*/
#logo {
display: inline;
margin: 0 auto;
padding: 0;
}
.menu {
position: relative;
}
#search {
float: left;
position: absolute;
}
#searchbox {
padding: 16px 15px 16px 15px;
font-family: 'Lato', Helvetica, Arial, sans-serif;
margin-left: 0;
color: #603a16;
position: relative;
right: -5px;
border: none;
border-color: white;
}
#go {
padding: 8px;
font-size: 1.5rem;
font-family: 'Lato', Helvetica, Arial, sans-serif;
letter-spacing: 1px;
text-transform: uppercase;
font-weight: bolder;
color: transparent;
background: url('../images/magnifying-glass.png') top right no-repeat;
border: #74b648;
margin-right: 0;
}
.facebook {
height: 32px;
width: 32px;
background: url('../images/facebook_colour_32-03.png') top right no-repeat;
text-indent: -9999px;
margin: 0 15px 0 10px;
display: inline-block;
float: right;
box-shadow: none;
border: none;
}
.twitter {
height: 32px;
width: 32px;
background: url('../images/twitter_colour_32-03.png') top right no-repeat;
text-indent: -9999px;
display:inline-block;
float: right;
}
.donate {
position: relative;
right:-695px;
}
header {
display: block;
width: 100%;
text-align: center;
}
header > nav > ul {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
list-style: none;
margin: 0;
padding: 0;
}
header > nav > ul > li {
flex: 0 1 auto;
margin: auto;
padding: 0;
position: relative;
transition: all linear 0.1s;
}
header > nav > ul > li:hover {
background-color: white;
}
header > nav > ul > li a + div {
background: white;
border-radius: 0 0 2px 2px;
box-shadow: 0 3px 1px rgba(0,0,0,.05);
display: none;
font-size: 1.1rem;
color: #603a16;
padding: .25rem 1.5rem;
letter-spacing: 1.5px;
text-transform: uppercase;
text-align: left;
position: absolute;
width: 220px;
}
header > nav > ul > li:hover a + div {
display: block;
}
header > nav > ul > li a + div > ul {
list-style-type: none;
}
header > nav > ul > li a + div > ul > li {
margin: 0;
padding: 0;
-webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased;
-o-font-smoothing: antialiased;
-ms-font-smoothing: antialiased;
font-smoothing: antialiased;
font-family: 'Lato', Helvetica, sans-serif;
font-weight: bolder;
line-height: 2rem;
}
header > nav > ul > li a + div > ul > li > a {
color: #603a16;
display: block;
font-size: 1.1rem;
letter-spacing: 1.5px;
padding: .25rem 1.5rem;
text-decoration: none;
text-transform: uppercase;
width: 200px;
background: white;
}
header > nav > ul > li a + div > ul > li:hover > a {
background-color: #bbbbbb;
}
header > nav > ul > li > a {
color: #603a16;
display: block;
font-size: 1.7rem;
max-width: 500px;
padding: .9rem ;
text-decoration: none;
font-weight: ;
text-transform: uppercase;
transition: all linear 0.1s;
text-align: center;
margin-right: auto;
margin-left: auto;
-webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased;
-o-font-smoothing: antialiased;
-ms-font-smoothing: antialiased;
font-smoothing: antialiased;
font-family: "Lato", Helvetica, Arial, sans-serif;
font-weight: bolder;
}
header > nav > ul > li > a > div > span {
color: rgba(255,255,255,.75);
display: block;
font-family: "Lato", Helvetica, Arial, sans-serif;
font-size: .7rem;
font-style: italic;
line-height: 1rem;
max-width: 260px;
}
<header class="main">
<nav role="navigation">
<ul style="position:relative; z-index:90;">
<li class="menu">
<a href="/about/index.html">
<div>
About
</div>
</a><div>
<ul style="position:relative; z-index:99;">
<li>Member Groups</li>
<li>Board of Directors</li>
<li>Bulletin</li>
<li>Brochure</li>
<li>Join</li>
<li>Contact</li>
</ul>
</div>
</li>
<li>
<li class="menu">
<a href="/events/index.html">
<div>
Events
</div>
</a>
<div>
<ul style="position:relative; z-index:99;">
<li>SEN World Rivers Day</li>
<li>SEN Environmental Film Festival</li>
<li>SEN Earth Overshoot</li>
<li>SEN Environmental Activist Awards</li>
<li>Events Calendar</li>
</ul>
</div>
</li>
<li>
<li class="menu">
<a href="/tools/index.html">
<div>
Tools
</div>
</a><div>
<ul style="position:relative; z-index:99;">
<li>Group Tools</li>
<li>Campaign Tools</li>
<li>Laws</li>
<li>Government Contacts</li>
<li>SEN's Grassroots Activism Fund</li>
</ul>
</div>
</li>
<li class="menu">
<a href="/solutions/energy/index.html">
<div>
Solutions
</div>
</a><div>
<ul style="position:relative; z-index:99;">
<li>Energy Policy</li>
<li>Energy Conservation and Efficiency</li>
<li>Alternate Energy Resources</li>
</ul>
</div>
</li>
<li class="menu">
<a href="/index.html">
<div id="top-logo">
<img src="images/EcoNet_logo_head2.png" height="180" width="180" title="Saskatchewan_Eco_Network" alt="Saskatchewan Eco Network">
</div>
</a>
</li>
<li class="menu">
<a href="/issues/index.html">
<div>
Issues
</div>
</a><div>
<ul style="position:relative; z-index:99;">
<li>Biodiversity</li>
<li>Biotechnology</li>
<li>Climate Change</li>
<li>Ethanol</li>
<li>Forests</li>
<li>Great Sand Hills</li>
<li>Intensive Livestock Operations</li>
<li>Mining</li>
<li>Pesticides</li>
<li>Water</li>
</ul>
</div>
</li>
<li>
<li>
<li class="menu">
<a href="/action/index.html">
<div>
Action
</div>
</a><div>
<ul style="position:relative; z-index:99;">
<li>Find your Representitive</li>
<li>Write a Letter to the Editor</li>
</ul>
</div>
</li>
<li>
<li>
<li class="menu">
<a href="/ecoed/index.html">
<div>
Eco-Education
</div>
</a><div>
<ul style="position:relative; z-index:99;">
<li>Teacher Resources</li>
<li>Eco-Education Stories</li>
<li>Indigenous Educators</li>
<li>Student Resources</li>
</ul>
</div>
</li>
<li>
</ul>
</nav>
</header>
and here is the CSS for the Header
The menu is in the correct position in Firefox, but the Google Font 'Lato' still isn't working correctly. Does anybody know what I'm doing wrong with my HTML and CSS that the menu and font are only working properly in Chrome?

Horizontal Table needed centering

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

Opacity on hover of parent is being transfered to submenu; how to prevent this using CSS

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.

Resources