I was finishing up creating this page using html and css after finishing up i was just checking the navigation menu in a mobile view and while scrolling down the menu the content of the page shows off and menu goes down and the content shows off
I want content not be shown while scrolling or not scrolling in the hamburger menu
code:
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#300&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background-color: #2f2f42;
}
nav {
display: flex;
height: 90px;
width: 100%;
align-items: center;
justify-content: space-between;
padding: 0 50px 0 100px;
flex-wrap: wrap;
}
nav .logo {
font-size: 20px;
font-weight: bold;
color: teal;
}
nav ul {
display: flex;
flex-wrap: wrap;
list-style: none;
}
nav ul li {
margin: 0 5px;
}
nav ul li a {
color: rgb(92, 156, 92);
text-decoration: none;
font-size: 18px;
font-weight: 500;
padding: 8px 15px;
border-radius: 5px;
letter-spacing: 1px;
transition: all 0.3s ease;
}
nav ul li a.active,
nav ul li a:hover {
color: teal;
background-color: white;
}
nav .menu-btn i {
color: #fff;
font-size: 22px;
cursor: pointer;
display: none;
}
input[type="checkbox"] {
display: none;
}
#media (max-width: 1000px) {
nav {
padding: 0 40px 0 50px;
}
}
#media (max-width: 920px) {
nav .menu-btn i {
display: block;
}
#click:checked~.menu-btn i:before {
content: "\f00d";
}
nav ul {
position: fixed;
top: 80px;
left: -100%;
z-index: 9999;
/** ADDED **/
height: 100vh;
width: 100%;
text-align: center;
display: block;
transition: all 0.3s ease;
background-color: #2f2f42;
/** ADDED **/
}
#click:checked~ul {
left: 0;
}
nav ul li {
width: 100%;
margin: 40px 0;
}
nav ul li a {
width: 100%;
margin-left: -100%;
display: block;
font-size: 20px;
transition: 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
#click:checked~ul li a {
margin-left: 0px;
}
nav ul li a.active,
nav ul li a:hover {
background: none;
color: teal;
}
}
.content {
position: relative;
background-color: #131314;
color: whitesmoke;
border: 5px solid grey;
border-radius: 12px;
width: auto;
height: 50rem;
margin-top: 1vw;
margin-left: 4vw;
margin-right: 4vw;
font-weight: bolder;
}
#media (max-width: 920px) {
.content {
display: block;
}
}
#media (max-width: 920px) {
.content #bor,
.det,
.clk {
display: block;
}
}
.bor {
justify-content: center;
text-align: center;
border-bottom: 0.7vw solid white;
}
.det {
display: inline-block;
margin-left: 1vw;
text-align: left;
border-bottom: 0.6vw solid whitesmoke;
}
.clk {
float: right;
width: fit-content;
height: fit-content;
margin-right: 1vw;
}
h2 {
box-sizing: border-box;
padding: 0.6vw;
margin: 0.8vw 0.8vw 0.8vw 0.8vw;
background-color: rgb(64, 80, 113);
text-align: left
}
#exp {
padding: 0.8vw;
margin: 0.8vw 0.8vw 0.8vw 1.9vw;
text-align: left;
}
footer {
background-color: rgb(104, 99, 25);
color: black;
margin: 15px;
padding: 15px;
border-radius: 8px;
}
#foo {
text-align: center;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" rel="stylesheet" />
<nav>
<div class="logo">Logo img</div>
<input type="checkbox" id="click">
<label for="click" class="menu-btn">
<i class="fas fa-bars"></i>
</label>
<ul>
<li><a class="active" href="#">Home</a></li>
<li>Services</li>
<li>About</li>
</ul>
</nav>
<div class="content">
<p class="bor"> this is content heading <br>
</p><br>
<span class="det">this is content side</span> <button class="clk">Watch</button><br><br>
<span class="det">this is content side</span><button class="clk">Watch</button><br><br><br>
<h2>this is demo</h2>
<p id="exp">this is content end</p>
</div>
<div id="foo">
<footer>
<p>Copyright © company 2022<br><br> All Rights Reserved</p>
</footer>
</div>
You could use JS to disable scroll when the menu shows up and enable when it's closed. Although, I don't understand why you wanted to use checkbox input for closing the menu. you could handle scrollbar like this
HTML
<label for="click" class="menu-btn" onclick={disableScroll()}>
<i class="fas fa-bars"></i>
</label>
<label for="click" class="close-btn" onclick={enableScroll()}>
<i class="fa-solid fa-xmark"></i>
</label>
Javascript
<script>
const disableScroll = () =>{
document.body.style.height = "100%";
document.body.style.overflow = "hidden";
document.querySelector("menu-btn").style.display = "none"
document.querySelector("close-btn").style.display = "block"
}
const enableScroll = () =>{
document.body.style.overflow = "auto";
document.querySelector("menu-btn").style.display = "block"
document.querySelector("close-btn").style.display = "none"
}
</script>
Related
I am trying to implement a hamburger menu. My expectation is when I will click on hamburger menu then the whole screen will contain only hamburger menu and there will be no scrolling and I don't want to see any content under body tag. Also I don't want any scroll option in hamburger menu. The whole screen after clicking the hamburger menu icon will contain only menu list.
below is the code for CSS: here #nav.active #menu I'm trying to control the displaying menu. Its connected with Javascript. But I don't get my expected output it always scroll y.
const btnMobile = document.getElementById('btn-mobile');
function toggleMenu(event) {
if (event.type === 'touchstart') event.preventDefault();
const nav = document.getElementById('nav');
nav.classList.toggle('active');
const active = nav.classList.contains('active');
event.currentTarget.setAttribute('aria-expanded', active);
if (active) {
event.currentTarget.setAttribute('aria-label', 'Fechar Menu');
} else {
event.currentTarget.setAttribute('aria-label', 'Abrir Menu');
}
}
btnMobile.addEventListener('click', toggleMenu);
btnMobile.addEventListener('touchstart', toggleMenu);
body,
ul {
margin: 0px;
padding: 0px;
}
a {
color: black;
text-decoration: none;
font-family: sans-serif;
}
a:hover {
background: rgba(0, 0, 0, 0.05);
}
#logo {
font-size: 1.5rem;
font-weight: bold;
}
#header {
box-sizing: border-box;
height: 70px;
padding: 1rem;
display: flex;
align-items: center;
justify-content: space-between;
background: #e7e7e7;
}
#menu {
display: flex;
list-style: none;
gap: 0.5rem;
}
#menu a {
display: block;
padding: 0.5rem;
}
#btn-mobile {
display: none;
}
#media (max-width: 600px) {
#menu {
display: block;
position: absolute;
width: 100%;
top: 70px;
right: 0px;
background: #e7e7e7;
transition: 0.6s;
z-index: 1000;
height: 0px;
visibility: hidden;
overflow-y: hidden;
}
#nav.active #menu {
height: calc(100vh - 70px);
visibility: visible;
overflow-y: auto;
}
#menu a {
padding: 1rem 0;
margin: 0 1rem;
border-bottom: 2px solid rgba(0, 0, 0, 0.05);
}
#btn-mobile {
display: flex;
padding: 0.5rem 1rem;
font-size: 1rem;
border: none;
background: none;
cursor: pointer;
gap: 0.5rem;
}
#hamburger {
border-top: 2px solid;
width: 20px;
}
#hamburger::after,
#hamburger::before {
content: '';
display: block;
width: 20px;
height: 2px;
background: currentColor;
margin-top: 5px;
transition: 0.3s;
position: relative;
}
#nav.active #hamburger {
border-top-color: transparent;
}
#nav.active #hamburger::before {
transform: rotate(135deg);
}
#nav.active #hamburger::after {
transform: rotate(-135deg);
top: -7px;
}
}
<header id="header">
<a id="logo" href="">Logo</a>
<nav id="nav">
<button aria-label="Abrir Menu" id="btn-mobile" aria-haspopup="true" aria- controls="menu" aria-expanded="false">Menu
<span id="hamburger"></span>
</button>
<ul id="menu" role="menu">
<li>Sobre</li>
<li>Produtos</li>
<li>Portfólio</li>
<li>Contato</li>
</ul>
</nav>
</header>
<div class="circle1"></div>
<div class="circle2"></div>
<div class="circle1"></div>
<div class="circle2"></div>
I did have the modal working and showing when I press the button. However, now (not sure how I've done it) I cannot get the modal box to open.
I have my page laid out as an image and then the button below the image to open the modal.
This is my HTML...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<script src="https://kit.fontawesome.com/454c24fdd9.js"></script>
<title>Elle and Belle Design</title>
</head>
<body>
<div class="logo">
<img src="logo.png" class="logoimg">
</div>
<nav class="main-nav">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Information</li>
<li class="products">
Products
<div class="dropdown-content">
Headbands
Earrings
Other
</div></li>
<li>Contact Us</li>
</ul>
</nav>
<div class="header">
<h1>Elle and Belle Design</h1>
<h2>Bespoke Handmade Headbands and Accessories</h2>
</div>
</div>
<div class="mainbody">
<div class="sidebar">
<h3>Updates</h3>
</div>
<div class="section-1">
<img src="silverband.jpg" class="previewimg"><br>
<button class="headbutton">Preview</button>
<div id="headmodal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<p7>Belle Band</p7><br>
<img src="silverband.jpg" class="headbands">
<img src="silverbandon.jpg" class="headbands">
<p6>£15</p6><br>
<p4>Our Belle Band is hand-crafted with love and care in both thick and thin sizes.</p4><br>
<p4>We use a range of small silver jewels incorporated with white pearls and flowers for that ultimate wedding look</p4>
</div>
</div>
<script>
// Get the modal
var modal = document.getElementById("headmodal");
// Get the button that opens the modal
var btn = document.getElementById("headbutton");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</div>
</div>
<div class="footer">
<div id="socialmedia">
<i class="fab fa-facebook-square fa-2x"><a style="padding-left: 15px;" href='#'></a></i>
<i class="fab fa-instagram fa-2x"><a style="padding-left: 15px;" href='#'></a></i>
<i class="fab fa-twitter-square fa-2x"><a style="padding-left: 15px;" href='#'></a></i>
</div>
<br>
<p3>Find Us on Social Media</p>
</div>
</body>
</html>
* {
box-sizing: border-box;
}
#media screen and (max-width: 600px) {
.main-body {
flex-direction: column;
}
}
/* Fonts */
#font-face {
font-family: 'greatvibes';
src: local('greatvibes.otf');
src: url('greatvibes.otf');
format: ('opentype');
}
#font-face {
font-family: 'tenderness';
src: local('tenderness.otf');
src: url('tenderness.otf');
format: ('opentype');
}
/* Headings and Paragraphs */
h1 {
font-family: 'greatvibes';
font-size: 7vw;
font-weight: bold;
}
h2 {
font-family: 'greatvibes';
font-size: 3.5vw;
}
h3 {
font-family: 'greatvibes';
font-size: 2vw;
text-align: center;
}
h4 {
font-family: 'greatvibes';
font-size: 2vw;
text-align: center;
margin-bottom: 0;
}
p2 {
font-family: 'greatvibes';
font-size: 1.9vw;
}
p3 {
font-family: 'greatvibes';
font-size: 2vw;
}
p4 {
font-family: 'tenderness';
font-size: 1.5vw;
line-height: 2.5vw;
}
p5 {
font-family: 'tenderness';
font-size: 1.5vw;
line-height: 2.5vw;
}
p6 {
font-family: 'greatvibes';
font-size: 4vw;
}
p7 {
font-family: 'greatvibes';
font-size: 4vw;
}
/* Sections */
.header {
padding: 17vw;
text-align: center;
height: auto;
background-image: url("decorhands.jpg");
background-size: 100%;
}
body {
margin: 0;
padding: 0;
background:whitesmoke;
font-family: 'tenderness';
}
.mainbody {
display: flex;
flex-wrap: wrap;
}
.sidebar {
flex: 20%;
background-color: #FEDCD2;
min-height: 500px;
text-align: center;
padding: 1vw;
}
.section-1 {
flex: 80%;
background-color:whitesmoke;
}
.bands {
flex: 50%;
padding: 1em;
}
.footer {
padding: 20px;
text-align: center;
background: #bfd8d2;
min-height: 10vw;
}
.socialmedia {
display: flex;
align-items: flex-end;
}
.home {
width: 100%;
height: auto;
opacity: 0.7;
}
/* Navigation bar */
.main-nav {
display: flex;
position: fixed;
top: 0;
background-color: rgba(0, 0, 0, 0.35);
z-index: 0.9;
height: 5vw;
width: 100%;
}
.main-nav ul {
list-style-type: none;
margin: 0 0 0 20vw;
padding: 0;
overflow: visible;
top: 0;
width: 100%;
height: 5vw;
}
.main-nav ul li {
display: inline-block;
text-align: center;
margin-left: 2vw;
height: 5vw;
}
.main-nav li {
float: left;
height: 5vw;
}
.logoimg {
height: 5vw;
width: auto;
float: left;
position: fixed;
margin-left: 1vw;
z-index: 1;
}
.main-nav li a, .dropdown {
display: block;
padding: 1.2em 2.2em;
text-decoration: none;
color: whitesmoke;
text-align: center;
font-family: 'tenderness';
font-size: 1.5vw;
height: 5vw;
border-bottom: 0.3vw solid transparent;
}
.main-nav li a:after {
display: block;
content: '';
border-bottom: 0.3vw solid whitesmoke;
transform: scaleX(0);
transition: transform 0.3s ease-in-out;
height: 1.2vw;
min-width: 6vw;
}
.main-nav li a:hover:after {
height: 1.2vw;
transform: scaleX(1);
}
.main-nav a:active {
border-bottom: 1vw solid whitesmoke;
}
li.products {
display: inline-block;
height: 5vw;
}
.dropdown-content {
display: none;
position: absolute;
background-color: rgba(0, 0, 0, 0.35);
min-width: 8vw;
z-index: 1;
}
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
text-align: center;
height: 5vw;
}
.products:hover .dropdown-content {
display: block;
}
/* Contact Form */
.contact-header {
margin-top: 5px;
}
.contact-header h3 {
font-size: 2.5vw;
text-align: center;
}
.contact-form {
text-align: center;
}
.form-control {
width: 80%;
background: transparent;
border: none;
outline: none;
color: black;
font-size: 1.2vw;
border-bottom: 0.2vw solid #DF744A;
margin-bottom: 1vw;
padding: 0.5vw;
}
form .submit {
background-color: #DF744A;
border-color: transparent;
color: whitesmoke;
font-size: 1.5vw;
text-align: center;
}
form .submit:hover {
background-color: rgb(209, 84, 35);
cursor: pointer;
}
/*Headband Modal*/
.modal {
display: none;
position: fixed;
z-index: 1;
padding: 10vw;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4);
}
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.headbands {
height: auto;
width: 30vw;
}
.previewimg {
width: 20vw;
height: auto;
margin: 1vw;
}
I am not sure why all of a sudden it wont let me open the modal.
Please help!
Thanks
Mary
As I can see, in JS code you are trying to get the button in a wrong way.
getElementById will not work in that case because your button does not have an id attribute
Maybe try to grab the button like so:
document.querySelector(".headbutton");
Let me know if it solved the issue.
For more information about querySelector see this link
and also see this link for querySelectorAll
It is just for a simple reason and that is you forget to get btn in the right way. You want to get your button with getElementById but there is no element with this id in your page and that is the error part!
So you can change the class attribute to id or you can get your button with getElementByClassName in your javascript code.
I hope this helps :)
You can change your btn.onclick function to a regular function such as:
function buttonClick() {
modal.style.display = "block";
}
and call the onclick method in the button tag:
<button class="headbutton" onClick="buttonClick()">Preview</button>
Working jsFiddle: https://jsfiddle.net/t29qh6f3/
I did this for your span.onclick function as well.
This should make your modal appear again. Hope this helps.
I have created a template with a horizontal navigation in desktop, and a vertical navigation in mobile. I am using one nav list and changing the styling of it for desktop to mobile.
The thing is, the jQuery that I have given it adds some strange transitions to it that I want removed. A fade in/fade out of the text and the sidebar and a weird slide in/slide out effect.
What I am trying to achieve is to make the mobile nav slide in/slide out with the width intact, with no fade effects. I think the toggle() class has something to do with it, but Im not sure.
Also, when you open then click the hamburger to open then close the mobile nav, then go to view the desktop mode, the desktop nav is gone also until you refresh the page.
Any help would be great. Thanks.
$('.toggle-menu').click(function() {
$('nav').toggle("nav");
});
:root {
--black: #212121;
--grey: #ccc;
--light-grey: #eee;
--grey-opacity: #ccc, 0.2;
--gutter: 30px;
}
html,
body {
min-height: 100%;
}
html {
box-sizing: border-box;
background-color: var(--grey);
}
body {
font-family: 'Poppins', sans-serif;
font-size: 14px;
line-height: 1.3;
color: var(black);
margin: 0;
}
a {
text-decoration: none;
color: var(--black);
}
a:hover,
a:focus {
color: var(--black);
}
ul {
padding: 0;
}
ul li {
display: inline;
list-style-type: none;
}
.container {
display: grid;
grid-template-columns: 1fr;
grid-template-areas: "header" "aside content" "overview overview" "footer footer";
}
.header-skin {
background-color: rgba(255, 255, 255, 0.1);
}
header {
grid-area: header;
display: flex;
justify-content: space-between;
padding: var(--gutter) 15px;
max-width: 1200px;
margin: 0 auto;
}
.toggle-menu span {
width: 20px;
height: 2px;
margin-bottom: 4px;
border-radius: 50px;
background: var(--black);
display: block;
}
#media (min-width: 839px) {
.toggle-menu {
display: none;
}
nav ul {
margin: 0;
}
nav ul li {
text-transform: capitalize;
padding-left: 20px;
}
nav ul li a {
position: relative;
}
nav ul li a.active {
color: var(--black);
font-weight: 700;
}
nav ul li a.active::after {
content: ' ';
width: 100%;
height: 2px;
display: block;
position: absolute;
left: 0;
bottom: -4px;
background-color: var(--black);
}
nav ul li:nth-child(4n) {
margin-right: 200px;
}
}
#media (max-width: 840px) {
nav {
height: 100%;
position: fixed;
background-color: rgba(255, 255, 255, 0.1);
left: 0;
top: 78px;
width: 300px;
margin-right: -300px;
display: none;
}
nav ul {
margin: 0;
padding: 40px 0 0 40px;
display: flex;
flex-direction: column;
}
nav ul li {
text-transform: capitalize;
padding-bottom: 40px;
}
nav ul li a {
position: relative;
}
nav ul li a.active {
color: var(--black);
font-weight: 700;
}
nav ul li a.active::after {
content: ' ';
width: 100%;
height: 2px;
display: block;
position: absolute;
left: 0;
bottom: -4px;
background-color: var(--black);
}
nav ul li:nth-child(4n) {
margin-right: 200px;
}
}
<div class="container">
<div class="header-skin">
<header>
<div class="logo">
logo
</div>
<div class="toggle-menu">
<span></span>
<span></span>
<span></span>
</div>
<nav>
<ul>
<li>home</li>
<li>about</li>
<li>news</li>
<li>contact</li>
<li>twitter</li>
<li>instagram</li>
</ul>
</nav>
</header>
</div>
<div class="aside"></div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="functions.js"></script>
</div>
I'm trying to create a responsive menu, I've got it to work on mobile but when it opens into desktop browser the menu buttons are wonky and not set to full width.
var geolifygeoredirect = document.createElement('script')
geolifygeoredirect.setAttribute('type', 'text/javascript')
geolifygeoredirect.async = 1
geolifygeoredirect.setAttribute('src', '//www.geolify.com/georedirectv2.php?id=32270&refurl=' + document.referrer)
document.getElementsByTagName('head')[0].appendChild(geolifygeoredirect);
/*Javascript*/
$(function() {
var $page = jQuery.url.attr("file");
$('ul.navigation li a').each(function() {
var $href = $(this).attr('href');
if (($href == $page) || ($href == '')) {
$(this).addClass('on');
} else {
$(this).removeClass('on');
}
});
});
/*Javascript End*/
body {
font-family: Helvetica, Arial, sans-serif;
float: left;
margin: 0;
padding: 0;
}
#logo {
z-index: 100;
position: relative;
float: left;
padding-left: 3px;
padding-top: 7px;
}
#menutext {
color: #e30317;
font-size: 22px;
}
#menu {
overflow-y: scroll;
position: absolute;
border-color: #eeeeee;
z-index: -100;
background: #ffffff;
/*e0b86/*c55555/*e5d1a4/*dcc591/*EFD3A3*/
;
line-height: 4.1em;
font-weight: 200;
width: 100%;
margin: inherit;
color: #c6c6c6;
padding-bottom: 0;
height: 300px;
}
#lines {
position: relative;
object-position: center;
border-color: #e30317;
}
ul.navigation {
background: #fff;
}
ul.navigation li a {
text-decoration: none;
}
ul.navigation li a.on {
background: #eeeeee;
padding: 2px 6px;
min-width: 100%;
}
.mobile-menu {
display: block;
background: #c6c6c6;
/*e0b86/*c55555/*e5d1a4/*dcc591/*EFD3A3*/
;
line-height: 100px;
font-weight: 200;
width: 100%;
text-align: center;
position: fixed;
margin: 0 auto;
color: #c6c6c6
}
/*Strip the ul of padding and list styling*/
.mobile-menu ul {
list-style-type: none;
padding-left: 0;
text-align: center;
width: 100%;
position: relative;
background: #c6c6c6;
position: relative;
height: 50px;
}
/*Create a horizontal list with spacing*/
.mobile-menu li {
display: inline-block;
/*float: left;
margin-right: 1px;*/
}
/*Style for menu links*/
.mobile-menu li a {
display: block;
min-width: 130px;
text-align: center;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #eee;
text-transform: uppercase;
background: #253746;
text-decoration: none;
margin-left: -15px;
padding: 20px 0;
-webkit-transition: all 0.4s ease 0s;
-moz-transition: all 0.4s ease 0s;
-ms-transition: all 0.4s ease 0s;
-o-transition: all 0.4s ease 0s;
transition: all 0.4s ease 0s;
font-size: 1.0em;
font-weight: bold;
border-color: #e30317;
border-left: 1px solid;
border-top: 1px solid;
border-right: 3px solid;
border-bottom: 0px solid;
height: 70px;
}
/*Hover state for top level links*/
.mobile-menu li:hover a {
color: #333;
background-color: #eee;
}
/*Style for dropdown links*/
.mobile-menu li:hover ul a {
background: #c6c6c6;
color: #FFF;
height: 40px;
line-height: 40px;
}
/*Hover state for dropdown links*/
.mobile-menu li:hover .mobile-menu ul a:hover {
color: #eee;
}
/*Hide dropdown links until they are needed*/
.mobile-menu li ul {
display: none;
color: #eee
}
/*Make dropdown links vertical*/
.mobile-menu li ul li {
display: none;
float: none;
}
/*Prevent text wrapping*/
.mobile-menu li ul li a {
width: auto;
min-width: 100px;
padding: 0 10px;
}
/*Style 'show menu' label button and hide it by default*/
.mobile-menu .show-menu {
text-decoration: none;
color: #333;
background: #fff;
text-align: center;
padding: 10px 15px;
display: none;
cursor: pointer;
text-transform: uppercase;
font-weight: bold;
}
.mobile-menu .show-menu span {
padding-left: 35px;
}
/*Hide checkbox*/
.mobile-menu input[type=checkbox] {
display: none;
}
/*Show menu when invisible checkbox is checked*/
.mobile-menu input[type=checkbox]:checked~#menu {
display: block;
color: #333333;
}
/*Responsive Styles*/
#media screen and (max-width: 916px) {
.mobile-menu .lines {
border-bottom: 15px double #f8f8f8;
border-top: 5px solid #f8f8f8;
content: "";
height: 5px;
width: 20px;
padding-right: 15px;
float: right;
}
/*Make dropdown links appear inline*/
.mobile-menu ul {
position: static;
display: none;
}
/*Create vertical spacing*/
.mobile-menu li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
.mobile-menu ul li,
.mobile-menu li a {
width: 100%;
}
/*Display 'show menu' link*/
.mobile-menu .show-menu {
display: inherit;
color: #fff;
}
}
/* Test CSS END*/
}
}
#media screen and (min-width: 481px) {
/* comes into effect for screens larger than or equal to 481 pixels */
#pager {
width: 481px;
}
#media screen and (min-width: 916px) {
/* comes into effect for screens larger than or equal to 481 pixels */
#page {
min-width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Face Masks</title>
<nav class="mobile-menu"><img id="logo" style="float: left;" src="http://go.jsp.co.uk/images/eyemenu.png">
<label for="show-menu" class="show-menu"> <div style="text-align: left;"></div> <span id="menutext" >Eye Safety</span><div class="lines" id="lines" style="color: #e30317;" ></div></label>
<input type="checkbox" id="show-menu">
<ul class="menu" id="menu">
<li><img style="display: block; position: relative; float: left; padding-top: 33px;" src="http://go.jsp.co.uk/images/Headmini.png">Head Safety</li>
<li><img style="display: block; position: relative; float: left; padding-top: 33px;" src="http://go.jsp.co.uk/images/hearingmini.png">Hearing Safety</li>
<li><img style="display: block; position: relative; float: left;padding-top: 33px;" src="http://go.jsp.co.uk/images/FullHalfmini.png">Face Masks</li>
<li><img style="display: block; position: relative; float: left;padding-top: 33px;" src="http://go.jsp.co.uk/images/disposablemini.png">Disp. Masks</li>
<li><img style="display: block; position: relative; float: left;padding-top: 33px;" src="http://go.jsp.co.uk/images/eyemini.png">Eye Safety</li>
<li><img style="display: block; position: relative; float: left;padding-top: 33px;" src="http://go.jsp.co.uk/images/Contactmini.png">Contact</li>
</ul>
</nav>
</head>
<body>
<div style="padding-top: 113px">
<img src="http://go.jsp.co.uk/images/eye.png" style="width:100%; background-color: #253746" border="0" alt="Null">
</div>
</body>
</html>
jQuery is missing in your document (I get a Uncaught ReferenceError: $ is not defined when I run your snippet).
To add jQuery, add this line to your <head> section:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
Thanks Guys its sorted the alignment out but just very bunched up in desktop browser not set to full width.
I'm trying to create dropdown menu that will open and collapse when the "mobile-nav" button gets clicked.
Please see this video or website as examples of the intended behavior:
https://www.youtube.com/watch?v=ozOSV75DgzU
http://travisneilson.com/
function mobileNav() {
$('.mobile-nav-toggle').on('click', function() {
var status = $(this).hasClass('is-open');
if (status) {
$('.mobile-nav-toggle, .mobile-nav').removeClass('is-open');
} else {
$('.mobile-nav-toggle, .mobile-nav').addClass('is-open');
}
});
}
/* ------------------------------------------ */
/* BASIC SETUP */
/* ------------------------------------------ */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
text-align: justify color: #fff;
font-family: 'Lato', 'arial', sans-serif;
font-size: 19px;
font-weight: 400;
text-rendering: optimizeLegibility;
background: #333;
background-position: center;
height: 100vh;
background-attachment: fixed;
}
/* ------------------------------------------ */
/* REUSABLE COMPONENTS */
/* ------------------------------------------ */
.row-basic {
max-width: 1216px;
}
.main-container {
max-width: 1216px;
margin: 0 auto;
}
/* ------------------------------------------ */
/* HEADER */
/* ------------------------------------------ */
.mobile-nav {
display: ;
position: ;
width: 1216px;
background: white;
padding: 31px 0px 21px;
transform: translateY(-100%);
transition: all 0.3s ease-in-out
}
.mobile-nav.is-open {
display: block;
transform: translateY(0%);
}
.mobile-nav ul {
list-style: none;
}
.mobile-nav ul li {
text-align: center;
margin-bottom: 10px;
}
.mobile-nav ul li a:link,
.mobile-nav ul li a:visited {
color: #999;
text-decoration: none;
text-transform: uppercase;
}
header {
background-color: rgba(246, 149, 149, 0.06);
height: 81px;
width: auto;
padding-top: 24px;
margin-top: 26px;
margin-bottom: 0px;
display: flex;
justify-content: space-between;
}
/* ----- NAVIGATION -----*/
nav {
display: flex;
align-items: center;
}
nav ul {
display: flex;
}
.main-nav {
list-style: none;
}
.main-nav li {
display: inline-block;
line-height: 31px;
border-right: 1px solid rgba(255, 255, 255, 0.24);
padding-right: 9px;
padding-left: 9px;
margin-right: 0px;
width: auto;
}
.main-nav li:last-child {
border-right: hidden;
margin-right: 31px;
}
.main-nav li a:link,
.main-nav li a:visited {
color: #fff;
text-decoration: none;
text-transform: uppercase;
}
.user-tools {
display: flex;
align-items: center;
}
.user-tools:focus {
outline: none;
}
/* ----- MENU BUTTON -----*/
.mobile-nav-toggle {
height: 50px;
width: 35px;
margin-right: 31px;
display: flex;
align-items: center;
cursor: pointer;
}
.mobile-nav-toggle span,
.mobile-nav-toggle span::before,
.mobile-nav-toggle span::after {
border-radius: 2px;
content: "";
display: block;
height: 6px;
width: 100%;
background: #fff;
position: relative;
}
.mobile-nav-toggle span::before {
top: 11px;
}
.mobile-nav-toggle span::after {
bottom: 17px;
}
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="resources/css/style.css">
<link href='https://fonts.googleapis.com/css?family=Lato:400,900' rel='stylesheet' type='text/css'>
<script src="resources/js/functions.js"></script>
</head>
<body>
<div class="main-container">
<div class="mobile-nav is-open">
<ul>
<li>Menu
</li>
<li>Services
</li>
<li>Gallery
</li>
<li>About Me
</li>
</ul>
</div>
<header class="row-basic">
<nav>
<ul class="main-nav">
<li>Menu
</li>
<li>Services
</li>
<li>Gallery
</li>
<li>About Me
</li>
</ul>
</nav>
<div class="user-tools">
<div class="mobile-nav-toggle">
<span></span>
</div>
</div>
</header>
</div>
</body>
</html>
You have to add link to jQuery script.
Delete declaration function mobileNav() { and it closing braket }.
$('.mobile-nav-toggle').on('click', function() {
var status = $(this).hasClass('is-open');
if (status) {
$('.mobile-nav-toggle, .mobile-nav').removeClass('is-open');
} else {
$('.mobile-nav-toggle, .mobile-nav').addClass('is-open');
}
});
Here is example of working code https://jsfiddle.net/efjz40ob/