Hamburger Overlay Menu on Full Screen (Without Using JavaScript/Jquery) - html

I want to create a Hamburger overlay menu on full screen for my site. The point is I am creating this site in Google Amp so unable to use javascript. Please suggest a way to create this menu using pure CSS and HTML. I am a newbie so your help will be much appreciated.
Any Link or tutorial would be very helpful...
Code:
#nav-btn:checked~nav ul {
transform: translate(-50%, -50%);
}
nav {
background: rgba(52, 82, 113, 0.98) none repeat scroll 0% 0%;
height: 100%;
opacity: 0;
position: absolute;
top: 0px;
transition: opacity 0.5s ease 0s, visibility 0s ease 0.5s;
visibility: 0;
width: 100%;
z-index: -1;
}
nav ul {
left: 44%;
moz-transition: all 1s ease-in-out;
o-transition: all 1s ease-in-out;
position: absolute;
top: 30%;
transform: translate(-50%, 0%);
transition: all 1s ease-in-out;
webkit-transition: all 1s ease-in-out;
}
nav li {
font-size: 30px;
list-style: none;
padding-bottom: 10px;
text-align: center;
}
nav ul li a:hover {
color: #fff;
}
nav li a {
color: #ccc;
text-decoration: none;
}
.page-content-card.hidden {
display: none;
}
.overlay {
position: fixed;
background: $color-main;
top: 0;
left: 0;
width: 100%;
height: 0%;
opacity: 0;
visibility: hidden;
transition: opacity .35s, visibility .35s, height .35s;
overflow: hidden;
}
<div>
<input type="checkbox" name="nav-btn" id="nav-btn" />
<span></span>
<div class="overlay">
<nav>
<ul>
<li>Home</li>
<li>Service</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>

I thinks that's not possible without jQuery/javascript.
You should use this clean snippet:
$('#nav-btn').click(function() {
$('.overlay').toggleClass('open');
)};

You can try this...
/* CSS Document */
/*Strip the ul of padding and list styling*/
ul {
list-style-type: none;
margin: 0;
padding: 0;
position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display: inline-block;
float: left;
margin-right: 1px;
}
/*Style for menu links*/
li a {
display: block;
min-width: 140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
}
/*Hover state for top level links*/
li:hover a {
background: #19c589;
}
/*Style for dropdown links*/
li:hover ul a {
background: #f3f3f3;
color: #2f3036;
height: 40px;
line-height: 40px;
}
/*Hover state for dropdown links*/
li:hover ul a:hover {
background: #19c589;
color: #fff;
}
/*Hide dropdown links until they are needed*/
li ul {
display: none;
}
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/
li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
text-align: left;
}
/*Display the dropdown on hover*/
ul li a:hover+.hidden,
.hidden:hover {
display: block;
}
/*Style 'show menu' label button and hide it by default*/
.show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: #19c589;
text-align: center;
padding: 10px 0;
display: none;
}
/*Hide checkbox*/
input[type=checkbox] {
display: none;
}
/* Show menu when invisible checkbox is checked */
input[type=checkbox]:checked~#menu {
display: block;
}
/*Responsive Styles*/
#media screen and (max-width: 760px) {
/*Make dropdown links appear inline*/
ul {
position: static;
display: none;
}
/*Create vertical spacing*/
li {
margin-bottom: 2px;
}
/*Make all menu links full width*/
ul li,
li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display: block;
}
/*Pointer on Hover, so that the user knows of an active link*/
.show-menu:hover {
cursor: pointer;
}
/*Center the text*/
li ul li a {
text-align: center;
}
}
<label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li>Home</li>
<li>
About ↓
<ul class="hidden">
<li>Who We Are</li>
<li>What We Do</li>
</ul>
</li>
<li>
Portfolio ↓
<ul class="hidden">
<li>Photography</li>
<li>Web & User Interface Design</li>
<li>Illustration</li>
</ul>
</li>
<li>News</li>
<li>Contact</li>
</ul>
Source - http://bacsoftwareconsulting.com/blog/index.php/web-development/how-to-create-a-responsive-menu-without-jquery/

Related

Cant remove padding between nav-bar and banner css

I ran into a small problem while creating my website where an anonymous padding appears between my banner and nav-bar:
Here is my code:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<style>
#import 'https://fonts.googleapis.com/css?family=Work+Sans:400,500,900';
nav {
padding-top: 0px;
position: fixed;
width: 100%;
transition: top 0.2s ease-out;
}
.banner {
text-align: center;
width: 100%;
box-shadow: inset 0px -1px 0px 0px rgba(0, 0, 0, 0.13);
}
nav ul#menu {
padding-left: 0;
display: flex;
padding-top: 0px;
}
nav ul li {
flex-grow: 1;
}
.nav-bar {
/* Rectangle 1: */
background: #FFFFFF;
box-shadow: 0px 2px 2px 0px rgba(0, 0, 0, 0.11), 0px 4px 6px 0px rgba(0, 0, 0, 0.11);
width: 100%;
text-align: center;
}
//-------------------------------------------------------
/*Strip the ul of padding and list styling*/
ul {
list-style-type: none;
margin: 0;
position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display: inline-block;
float: center;
margin-right: 1px;
}
/*Style for menu links*/
li a {
display: block;
min-width: 140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
}
/*Hover state for top level links*/
li:hover a {
background: #19c589;
}
/*Style for dropdown links*/
li:hover ul a {
background: #f3f3f3;
color: #2f3036;
height: 40px;
line-height: 40px;
}
/*Hover state for dropdown links*/
li:hover ul a:hover {
background: #19c589;
color: #fff;
}
/*Hide dropdown links until they are needed*/
li ul {
display: none;
}
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/
li ul li a {
width: auto;
min-width: 100px;
padding-left: 0px;
padding-right: 0px;
}
/*Display the dropdown on hover*/
ul li a:hover+.hidden,
.hidden:hover {
display: block;
}
/*Style 'show menu' label button and hide it by default*/
.show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: #19c589;
text-align: center;
padding-left: 0px;
padding-right: 0px;
display: none;
}
/*Hide checkbox*/
input[type=checkbox] {
display: none;
}
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked~#menu {
display: block;
}
/*Responsive Styles*/
#media screen and (max-width: 760px) {
/*Make dropdown links appear inline*/
nav ul#menu {
position: static;
display: none;
}
/*Create vertical spacing*/
li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
ul li,
li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display: block;
}
}
.hero-image {
/* The image used */
/* Set a specific height */
height: 50%;
width: 100%;
/* Position and center the image to scale nicely on all screens */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
</style>
</head>
<body>
<nav>
<div class="banner animated"><img class="hero-image" src="https://picsum.photos/1080/200/?random"></div>
<div class="nav-bar"> <label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li>Home</li>
<li>
About
</li>
<li>
Portfolio
</li>
<li>News</li>
<li>Contact</li>
</ul>
</div>
</nav>
</body>
</html>
*View in full screen to see it.
Is there a way I can fix this? Thank you in advance!
As I have tried adding padding-top: 0px; to the nav bar so it could stick to the banner but it didn't work. My question is not a duplicate as the other questions problem is under a different circumstance.
You need to do two things. 1) set the vertical alignment on your image to top so it removes the gap reserved for descender text elements, and 2) remove the margin on your <ul>
#import 'https://fonts.googleapis.com/css?family=Work+Sans:400,500,900';
nav {
padding-top: 0px;
position: fixed;
width: 100%;
transition: top 0.2s ease-out;
}
.banner {
text-align: center;
width: 100%;
box-shadow: inset 0px -1px 0px 0px rgba(0, 0, 0, 0.13);
}
nav ul#menu {
padding-left: 0;
display: flex;
padding-top: 0px;
}
nav ul li {
flex-grow: 1;
}
.nav-bar {
/* Rectangle 1: */
background: #FFFFFF;
box-shadow: 0px 2px 2px 0px rgba(0, 0, 0, 0.11), 0px 4px 6px 0px rgba(0, 0, 0, 0.11);
width: 100%;
text-align: center;
}
//-------------------------------------------------------
/*Strip the ul of padding and list styling*/
ul {
list-style-type: none;
margin: 0;
position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display: inline-block;
float: center;
margin-right: 1px;
}
/*Style for menu links*/
li a {
display: block;
min-width: 140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
}
/*Hover state for top level links*/
li:hover a {
background: #19c589;
}
/*Style for dropdown links*/
li:hover ul a {
background: #f3f3f3;
color: #2f3036;
height: 40px;
line-height: 40px;
}
/*Hover state for dropdown links*/
li:hover ul a:hover {
background: #19c589;
color: #fff;
}
/*Hide dropdown links until they are needed*/
li ul {
display: none;
}
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/
li ul li a {
width: auto;
min-width: 100px;
padding-left: 0px;
padding-right: 0px;
}
/*Display the dropdown on hover*/
ul li a:hover+.hidden,
.hidden:hover {
display: block;
}
/*Style 'show menu' label button and hide it by default*/
.show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: #19c589;
text-align: center;
padding-left: 0px;
padding-right: 0px;
display: none;
}
/*Hide checkbox*/
input[type=checkbox] {
display: none;
}
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked~#menu {
display: block;
}
/*Responsive Styles*/
#media screen and (max-width: 760px) {
/*Make dropdown links appear inline*/
nav ul#menu {
position: static;
display: none;
}
/*Create vertical spacing*/
li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
ul li,
li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display: block;
}
}
.hero-image {
/* The image used */
/* Set a specific height */
height: 50%;
width: 100%;
/* Position and center the image to scale nicely on all screens */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
vertical-align:top;
}
#menu {
margin:0;
}
<nav>
<div class="banner animated"><img class="hero-image" src="https://picsum.photos/1080/200/?random"></div>
<div class="nav-bar"> <label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li>Home</li>
<li>
About
</li>
<li>
Portfolio
</li>
<li>News</li>
<li>Contact</li>
</ul>
</div>
</nav>
You can add
img.hero-image {
float: left;
}
img.hero-image {
float: left;
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<style>
#import 'https://fonts.googleapis.com/css?family=Work+Sans:400,500,900';
nav {
padding-top: 0px;
position: fixed;
width: 100%;
transition: top 0.2s ease-out;
}
.banner {
text-align: center;
width: 100%;
box-shadow: inset 0px -1px 0px 0px rgba(0, 0, 0, 0.13);
}
nav ul#menu {
padding-left: 0;
display: flex;
padding-top: 0px;
}
nav ul li {
flex-grow: 1;
}
.nav-bar {
/* Rectangle 1: */
background: #FFFFFF;
box-shadow: 0px 2px 2px 0px rgba(0, 0, 0, 0.11), 0px 4px 6px 0px rgba(0, 0, 0, 0.11);
width: 100%;
text-align: center;
}
//-------------------------------------------------------
/*Strip the ul of padding and list styling*/
ul {
list-style-type: none;
margin: 0;
position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display: inline-block;
float: center;
margin-right: 1px;
}
/*Style for menu links*/
li a {
display: block;
min-width: 140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
}
/*Hover state for top level links*/
li:hover a {
background: #19c589;
}
/*Style for dropdown links*/
li:hover ul a {
background: #f3f3f3;
color: #2f3036;
height: 40px;
line-height: 40px;
}
/*Hover state for dropdown links*/
li:hover ul a:hover {
background: #19c589;
color: #fff;
}
/*Hide dropdown links until they are needed*/
li ul {
display: none;
}
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/
li ul li a {
width: auto;
min-width: 100px;
padding-left: 0px;
padding-right: 0px;
}
/*Display the dropdown on hover*/
ul li a:hover+.hidden,
.hidden:hover {
display: block;
}
/*Style 'show menu' label button and hide it by default*/
.show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: #19c589;
text-align: center;
padding-left: 0px;
padding-right: 0px;
display: none;
}
/*Hide checkbox*/
input[type=checkbox] {
display: none;
}
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked~#menu {
display: block;
}
/*Responsive Styles*/
#media screen and (max-width: 760px) {
/*Make dropdown links appear inline*/
nav ul#menu {
position: static;
display: none;
}
/*Create vertical spacing*/
li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
ul li,
li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display: block;
}
}
.hero-image {
/* The image used */
/* Set a specific height */
height: 50%;
width: 100%;
/* Position and center the image to scale nicely on all screens */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
</style>
</head>
<body>
<nav>
<div class="banner animated"><img class="hero-image" src="https://picsum.photos/1080/200/?random"></div>
<div class="nav-bar"> <label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li>Home</li>
<li>
About
</li>
<li>
Portfolio
</li>
<li>News</li>
<li>Contact</li>
</ul>
</div>
</nav>
</body>
</html>
Add this to your styling to remove default margins and padding.
* {
padding: 0px;
margin: 0px;
}
ul is the culprit. You need to add margin-top to 0 to your ul menu selector.
nav ul#menu {
padding-left: 0;
display: flex;
padding-top: 0px;
margin-top: 0;
}
To remove the tiny gap, as #j08691 mentioned, add the vertical-align: top; to your hero-image class.

Problems with CSS nav-bar

I am trying to create a nav-bar using HTML and CSS. However, the nav-Bar doesn't stretch to the end of the page like I would like it to. I have tried using padding-left-: 0px and padding-right: 0px; however this does not work.
Here is my work so far:
$banner-height: 50px;
#import 'https://fonts.googleapis.com/css?family=Work+Sans:400,500,900';
nav {
height: $banner-height * 2;
position: fixed;
width: 100%;
top: 0;
transition: top 0.2s ease-out;
}
.banner {
text-align: center;
line-height: $banner-height;
top: 0;
width: 100%;
background: #FEFFB7;
box-shadow: inset 0px -1px 0px 0px rgba(0,0,0,0.13);
}
.nav-bar {
top: $banner-height;
/* Rectangle 1: */
background: #FFFFFF;
box-shadow: 0px 2px 2px 0px rgba(0,0,0,0.11), 0px 4px 6px 0px rgba(0,0,0,0.11);
width: 100%;
line-height: $banner-height;
text-align: center;
}
.nav-up {
top: -$banner-height;
}
//-------------------------------------------------------
/*Strip the ul of padding and list styling*/
ul {
list-style-type:none;
margin:0;
position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display:inline-block;
float: center;
margin-right: 1px;
}
/*Style for menu links*/
li a {
display:block;
min-width:140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
}
/*Hover state for top level links*/
li:hover a {
background: #19c589;
}
/*Style for dropdown links*/
li:hover ul a {
background: #f3f3f3;
color: #2f3036;
height: 40px;
line-height: 40px;
}
/*Hover state for dropdown links*/
li:hover ul a:hover {
background: #19c589;
color: #fff;
}
/*Hide dropdown links until they are needed*/
li ul {
display: none;
}
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/
li ul li a {
width: auto;
min-width: 100px;
padding-left: 0px;
padding-right: 0px;
}
/*Display the dropdown on hover*/
ul li a:hover + .hidden, .hidden:hover {
display: block;
}
/*Style 'show menu' label button and hide it by default*/
.show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: #19c589;
text-align: center;
padding-left: 0px;
padding-right: 0px;
display: none;
}
/*Hide checkbox*/
input[type=checkbox]{
display: none;
}
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked ~ #menu{
display: block;
}
/*Responsive Styles*/
#media screen and (max-width : 760px){
/*Make dropdown links appear inline*/
ul {
position: static;
display: none;
}
/*Create vertical spacing*/
li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
ul li, li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display:block;
}
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<nav class="nav-down">
<div class="banner animated">I'm a banner</div>
<div class="nav-bar"> <label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu" >
<li>Home</li>
<li>
About
</li>
<li>
Portfolio
</li>
<li>News</li>
<li>Contact</li>
</ul></div>
</nav>
</body>
</html>
The problem:
(View in full screen to see the full problem).
Updated: Solution in snippet, flexbox and paddding left for the UL set to 0.
Seeing some inconsistent behavior with the embedded snippet, so here is a fiddle:
https://jsfiddle.net/2u1kzy3c/
$banner-height: 50px;
#import 'https://fonts.googleapis.com/css?family=Work+Sans:400,500,900';
nav {
height: $banner-height * 2;
position: fixed;
width: 100%;
top: 0;
transition: top 0.2s ease-out;
}
.banner {
text-align: center;
line-height: $banner-height;
top: 0;
width: 100%;
background: #FEFFB7;
box-shadow: inset 0px -1px 0px 0px rgba(0,0,0,0.13);
}
nav ul#menu {
padding-left: 0;
display: flex;
}
nav ul li {
flex-grow: 1;
}
.nav-bar {
top: $banner-height;
/* Rectangle 1: */
background: #FFFFFF;
box-shadow: 0px 2px 2px 0px rgba(0,0,0,0.11), 0px 4px 6px 0px rgba(0,0,0,0.11);
width: 100%;
line-height: $banner-height;
text-align: center;
}
.nav-up {
top: -$banner-height;
}
//-------------------------------------------------------
/*Strip the ul of padding and list styling*/
ul {
list-style-type:none;
margin:0;
position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display:inline-block;
float: center;
margin-right: 1px;
}
/*Style for menu links*/
li a {
display:block;
min-width:140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
}
/*Hover state for top level links*/
li:hover a {
background: #19c589;
}
/*Style for dropdown links*/
li:hover ul a {
background: #f3f3f3;
color: #2f3036;
height: 40px;
line-height: 40px;
}
/*Hover state for dropdown links*/
li:hover ul a:hover {
background: #19c589;
color: #fff;
}
/*Hide dropdown links until they are needed*/
li ul {
display: none;
}
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/
li ul li a {
width: auto;
min-width: 100px;
padding-left: 0px;
padding-right: 0px;
}
/*Display the dropdown on hover*/
ul li a:hover + .hidden, .hidden:hover {
display: block;
}
/*Style 'show menu' label button and hide it by default*/
.show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: #19c589;
text-align: center;
padding-left: 0px;
padding-right: 0px;
display: none;
}
/*Hide checkbox*/
input[type=checkbox]{
display: none;
}
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked ~ #menu{
display: block;
}
/*Responsive Styles*/
#media screen and (max-width : 760px){
/*Make dropdown links appear inline*/
nav ul#menu {
position: static;
display: none;
}
/*Create vertical spacing*/
li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
ul li, li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display:block;
}
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<nav class="nav-down">
<div class="banner animated">I'm a banner</div>
<div class="nav-bar"> <label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu" >
<li>Home</li>
<li>
About
</li>
<li>
Portfolio
</li>
<li>News</li>
<li>Contact</li>
</ul></div>
</nav>
</body>
</html>

Hover Effect Not Showing Up on Two Menu Items

My hover effect is not showing up on my first two nav menu items unless the cursor touches the top of the item. I can't click on the first two items at all unless the cursor touches the top of the item. For the other three items, the hover effect is working properly and will show up when the cursor touches the bottom of the item. I've been mucking around with this and I know I did something to mess it up, but I can't figure out what. Everything worked fine before. Thank you for any help with this!
nav {
width: 450px;
margin-top: 1em;
float: right;
}
nav ul {
font-family: Arial, sans-serif;
font-size: .80em;
list-style: none;
text-align: right;
width: 100%;
margin: 0;
padding: 2% 0;
float: right;
}
nav ul ul {
width: 244px;
margin-top: 1.1%;
padding: 0;
position: absolute;
border-bottom: none;
z-index: 9999;
opacity: 0;
visibility: hidden;
transition: all .25s ease-in;
-o-transition: all .25s ease-in;
-ms-transition: all .25s ease-in;
-moz-transition: all .25s ease-in;
-webkit-transition: all .25s ease-in;
}
nav ul li:hover ul {
display: block;
border-top: none;
visibility: visible;
opacity: 1;
}
nav ul li { display: inline-block; text-align: left; }
nav ul li:nth-of-type(1) { width: 65px; }
nav ul li:nth-of-type(2) { width: 60px; }
nav ul li:nth-of-type(3) { width: 90px; }
/*Make link stay a certain color when hovered over and left*/
nav ul li:nth-of-type(3):hover > a { color: white; }
nav ul li:nth-of-type(3).current > a { color: white; }
nav ul li:nth-of-type(4) { width: 75px; }
nav ul li:nth-of-type(5) { width: 80px; text-align: right; }
nav ul li a {
color: silver;
font-size: .90em;
font-weight: bold !important;
text-decoration: none;
text-align: left;
}
nav ul li a.active-link {
color: white;
border-bottom: 1px solid #dad700;
}
nav ul li a:hover, nav ul li a.current {
color: white;
border-bottom: 1px solid #dad700;
}
nav ul li li {
background-color: #182248;
font-size: 1.2em !important;
text-align: left;
width: 100%;
display: block;
float: left;
}
nav ul li li:nth-of-type(1) {
width: 98%;
padding: 18px 0 20px 12px;
border-left: thin solid #696969;
border-right: thin solid #696969;
border-top: thin solid #696969;
}
nav ul li li:nth-of-type(2) {
width: 98%;
padding: 12px 0 20px 12px;
border-left: thin solid #696969;
border-right: thin solid #696969;
}
nav ul li li:nth-of-type(3) {
width: 98%;
padding: 12px 0 20px 12px;
border-left: thin solid #696969;
border-right: thin solid #696969;
border-bottom: thin solid #696969;
}
nav ul li li a {
color: silver;
font-size: .90em;
border: none;
}
/*Style 'show menu' label button and hide it by default*/
.show-menu {
cursor: pointer;
display: none;
}
/*Hide checkbox*/
input[type=checkbox] { display: none; }
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked ~ #menu { display: block; }
​
<nav>
<label for="show-menu" class="show-menu"><img src="img/buggy.png" alt="Buggy Silhouette" style="position: relative; top: .25em;"> Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li>Home</li>
<li>About</li>
<li>What's Up▾
<ul class="hidden">
<li>Meetings</li>
<li>Upcoming Events</li>
<li>Buggies & Bits</li>
</ul>
</li>
<li>Membership</li>
<li>Contact</li>
</ul>
</nav>​

Align Nav bar to right

Hi I have this navbar and wondering how to alight it to the right.
I've tried float:right but doesn't work. Also tried div align but not working
as well. I'm new to css though.
<div align="right">
<ul id="menu">
<li>Home</li>
<li>
About ↓
<ul class="hidden">
<li>Who We Are</li>
<li>What We Do</li>
</ul>
</li>
</ul>
</div>
css
/*
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
*/
/*
Created on : 01 27, 15, 9:58:38 AM
Author : jefloresca
*/
/*Strip the ul of padding and list styling*/
ul {
list-style-type:none;
margin:0;
padding:0;
position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display:inline-block;
float: right;
margin-right: 1px;
}
/*Style for menu links*/
li a {
display:block;
min-width:140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
}
/*Hover state for top level links*/
li:hover a {
background: #19c589;
}
/*Style for dropdown links*/
li:hover ul a {
background: #f3f3f3;
color: #2f3036;
height: 40px;
line-height: 40px;
}
/*Hover state for dropdown links*/
li:hover ul a:hover {
background: #19c589;
color: #fff;
}
/*Hide dropdown links until they are needed*/
li ul {
display: none;
}
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/
li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
}
/*Display the dropdown on hover*/
ul li a:hover + .hidden, .hidden:hover {
display: block;
}
/*Hide checkbox*/
input[type=checkbox]{
display: none;
}
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked ~ #menu{
display: block;
}
/*Responsive Styles*/
#media screen and (max-width : 760px){
/*Make dropdown links appear inline*/
ul {
position: static;
display: none;
}
/*Create vertical spacing*/
li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
ul li, li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display:block;
}
}
Here's the link to codepen: http://codepen.io/anon/pen/JoJqMZ
The align="right" attribute is deprecated. Don't use it!
Either remove the absolute positioning on the ul element, and then float the element to the right, or add right: 0.
Updated Example
<div>
<ul id="menu">
<li>Home</li>
<li>
About ↓
<ul class="hidden">
<li>Who We Are</li>
<li>What We Do</li>
</ul>
</li>
</ul>
</div>
ul {
list-style-type: none;
margin: 0;
padding: 0;
float: right;
}
li {
display: inline-block;
float: right;
margin-right: 1px;
}
li a {
display: block;
min-width: 140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
}
li:hover a {
background: #19c589;
}
li:hover ul a {
background: #f3f3f3;
color: #2f3036;
height: 40px;
line-height: 40px;
}
li:hover ul a:hover {
background: #19c589;
color: #fff;
}
li ul {
display: none;
}
li ul li {
display: block;
float: none;
}
li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
}
ul li a:hover + .hidden, .hidden:hover {
display: block;
}
input[type=checkbox] {
display: none;
}
input[type=checkbox]:checked ~ #menu {
display: block;
}
#media screen and (max-width : 760px) {
ul {
position: static;
display: none;
}
li {
margin-bottom: 1px;
}
ul li, li a {
width: 100%;
}
.show-menu {
display: block;
}
}
Found an answer on my position: relative not absolute
You need to add "width: 100%" in file css.
Code:
ul {
list-style-type:none;
margin:0;
padding:0;
position: absolute;
width: 100%;
}

Drop down menu on hover exceeds container width

I have this drop down menu which is responsive. When media query kicks in and I hover over my links, my drop down menu width sticks out of my container.
<!-- Navigation Menu -->
<div class="container">
<div id="navigation">
<label for="show-menu" class="show-menu">Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li>| Home</li>
<li>
| SERMONS <span>&#x25BC</span>
<ul class="hidden">
<li>Link 1</li>
<li>Link 1</li>
</ul>
</li>
<li>
| EVENTS<span>&#x25BC</span>
<ul class="hidden">
<li>slam Link 1</li>
<li>Link 1</li>
<li>LINK2</li>
</ul>
</li>
<li>| CONNECT<span>&#x25BC</span></li>
<li>| STAFF<span>&#x25BC</span></li>
<li>| LOCATIONS <span>&#x25BC</span></li>
<li>| OTHERS</li>
</ul>
</div>
</div>
<!-- End of Navigation Menu -->
Here is the css:
#navigation {
background-color: #bg-color;
height: 50px;
margin: 0px auto;
}
/*Arrow down style */
#navigation span{
font-size: 10px;
padding-left: 4px;
line-height: 50px;
}
/*Strip the ul of padding and list styling*/
ul {
list-style-type:none;
margin:0;
padding:0;
width: 100%;
position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display:inline-block;
float: left;
margin-right: 1px;
width:100px;
}
/*Style for menu links*/
li a {
display:block;
height: 50px;
text-align: center;
line-height: 50px;
font-family:#Oswald;
font-size: 16px;
color: #fff;
background: #bg-color;
text-decoration: none;
}
/*Hover state for top level links*/
li:hover a {
background: #light-gray;
}
/*Style for dropdown links*/
li:hover ul a {
background: #light-gray;
color: #white;
height: 40px;
line-height: 40px;
width: 100%;
}
/*Hover state for dropdown links*/
li:hover ul a:hover {
background: #bg-color;
color: #white;
}
/*Hide dropdown links until they are needed*/
li ul {
display: none;
position: absolute;
z-index: 100;
}
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/
li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
text-align: left;
}
/*Display the dropdown on hover*/
ul li a:hover + .hidden, .hidden:hover {
display: block;
min-width: 100%;
}
/*Style 'show menu' label button and hide it by default*/
.show-menu {
font-family:#Oswald;
text-decoration: none;
color: #fff;
background: #bg-color;
text-align: center;
padding: 10px 0;
display: none;
}
/*Hide checkbox*/
input[type=checkbox]{
display: none;
}
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked ~ #menu{
display: block;
}
input[type='text']{
color: #bg-color;
}
/*Responsive Styles*/
#media screen and (max-width : 760px){
/*Make dropdown links appear inline*/
ul {
position: static;
display: none;
}
/*Create vertical spacing*/
li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
ul li, li a {
width: 100%;
}
li ul li a {
text-align: center;
}
/*Display 'show menu' link*/
.show-menu {
display:block;
}
.hide-tab {
display: none;
}
#logo h1, #logo p {
text-align: center;
}
#testr form {
float: none;
}
#testr > form > input[type='text'] {
margin: 0 auto;
width:60%;
line-height: 60px;
}
}
I am not sure how to fix it as I have tried everything. A simple width:100% should fix it, but it hasn't.
I don't see where you defined .container