Menu is visible only if use hamburger - html

When I'm on the site the menu is hidden. Then when I resize the page and use the hamburger the menu is showing normally. When I resize the page back the menu is still visible. After refreshing site the problem is repeating.
U see the problem on my demo page:
I'll be really glad if you help me with this.
Thanks.
Code:
body {
min-height: 100%;
}
/* HEADER */
#header {
position: absolute;
top: 0px;
left: 0px;
height: 1000px;
right: 0px;
overflow: hidden;
}
.backgroundheader {
top: 0 !important;
position: relative !important;
height: 350px;
background-color: #333;
box-shadow: 0px 0px 50px 0px rgba(0, 0, 0, 1);
background-image: url("images/bamboo.png"), url("images/bamboo2.png");
background-repeat: no-repeat;
background-size: 560px, 195px;
width: 100%;
min-width: 100%;
background-position: top right, top left
}
.logo {
left: 0 !important;
position: absolute;
height: 200px;
width: 600px;
margin-top: 70px;
box-shadow: 0px 0px 50px 0px rgba(0, 0, 0, 0.8);
background-color: #AB2732;
float: left !important
}
/* HEADER */
/* MENU */
ul {
list-style-type: none;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
padding: 0;
overflow: hidden;
font-size: 220%;
font-family: menu
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 23px;
text-decoration: none;
}
li a:hover {
background-color: #111111;
}
.vyber {
position: absolute;
background-color: #AB2732;
background-size: 100%;
width: 100%;
height: 100px;
margin-top: 410px;
-webkit-animation-name: example;
/* Safari 4.0 - 8.0 */
-webkit-animation-duration: 4s;
/* Safari 4.0 - 8.0 */
animation-name: vysunuti;
animation-duration: 0.8s;
box-shadow: inset -0px 0 40px rgba(0, 0, 0, 0.7);
margin-bottom: 200px;
}
.hamburger {
visibility: hidden;
}
.hamburger-box {
margin-top: 80px;
}
#media screen and (max-width: 1246px) {
ul {
top: 345px;
z-index: 99
}
ul li {
;
background-color: #333;
display: block;
text-align: center;
width: 100%
}
.hamburger {
visibility: visible
}
.hamburger-box {
-webkit-animation: hamburger 0.5s ease-in-out;
animation: hamburger 0.5s ease-in-out;
}
}
#-webkit-keyframes hamburger {
from {
opacity: 0
}
to {
opacity: 1
}
}
#font-face {
font-family: menu;
src: url("fonty/menu.otf");
}
/* MENU */
/* MENU */
<div class="nav" id="header">
<div class="backgroundheader">
<div class="logo"></div>
<div class="simple-ss"></div>
<div id="container">
<div class="navbar-header">
<button style="right: 0 !important; position: absolute;margin-right: 30px;margin-top: 350px;z-index: 10" class="hamburger hamburger--spring navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" type="button">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
</button>
<div class="vyber">
<div class=" collapse " id="bs-example-navbar-collapse-1">
<div class="navbar-header">
<ul>
<li>
O nás
</li>
<li>
Restaurace
</li>
<li>
Running sushi
</li>
<li>
Kontakt
</li>
<li>
Fotogalerie
</li>
</ul>
<div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

The hamburger is not your problem.
Here is pseudo code how your website works now:
YOUR PSEUDO CODE
var showMenu = false;
var showButton = false;
if 1246px > windowWidth
showButton = true;
if buttonIsClicked == true
showMenu = !showMenu;
(if it is true it will set to false)
(if it is false it will set to true)
PROBLEM
So you need to show your menu when a user gets on the website.
When the windowWidth is smaller then the 1246px you stop showing the menu and shows the button.
Now when the user disables the menu and make the windowWidth bigger than 1246px you need to enable the menu again. this will look like this in pseudo code.
GOOD PSEUDO CODE
var showMenu = true;
var showButton = false;
if 1246px > windowWidth
showButton = true;
showMenu = false;
if 1246px < windowWidth
showMenu = true;
if buttonIsClicked == true
showMenu = !showMenu;
With this knowledge you should be able to solve your css

Related

Create a navbar whose background color changes when user hovers over a navbar item

I am creating a navbar for a website where I want the behavior of navbar to be like this-
User hovers over a nav-item > nav-item's background image fades in into a sweet radial gradient > color of the whole navbar changes to the farthest color of the nav-item gradient.
Now I want this change in colors of two divs(navbar and nav-item) to appear as a single effect.
HTML Code
<html>
<body>
<div id="navbar">
<div class="navbar container">
<div class="logo">
<img src="./img/Mob-Asset 18.png" alt="">
</div>
<div class="navbar-items">
<div class="navbar-item all-caps text-light" id="services">Services</div>
<div class="navbar-item all-caps text-light" id="clients">Clients</div>
<div class="navbar-item all-caps text-light" id="about-us">About Us</div>
<div class="navbar-item all-caps text-light" id="contact-us">Contact Us</div>
</div>
</div>
</div>
</body>
</html>
CSS Styling
#import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght#300;400;700&family=Poppins:wght#100;200;300;500;600;700;800&display=swap');
html{
height: 100%;
overflow-y: hidden;
overflow-x: hidden;
font-family: 'Open Sans', sans-serif;
font-family: 'Poppins', sans-serif;
background-image: linear-gradient(to top, #3d7ad6, #009eea, #12bff3, #5bdef7, #97fbfb);
}
.all-caps{
text-transform: uppercase;
}
.text-light{
color: #ffffff;
}
#navbar .container{
position: absolute;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
max-height: 60px;
box-shadow: 0px 5px 5px 0px #ffffff5a;
background-color: #000000;
transition: background-color 250ms ease-in-out;
}
#navbar .logo{
display: flex;
margin-left: 10px;
align-items: center;
}
#navbar .logo img{
cursor: pointer;
height: 40px;
}
#navbar .navbar-items{
height: 60px;
display: flex;
flex-direction: row;
width: auto;
}
#navbar .navbar-item{
position: relative;
cursor: pointer;
font-size: large;
font-weight: 600;
display: flex;
align-items: center;
margin: 0;
padding: 0 45px;
z-index: 1;
}
#navbar .navbar-item:nth-child(1)::after{
position: absolute;
content: "";
height: 100%;
width: 100%;
left:0;
background-image: radial-gradient(circle, #009aff, #1ba1ff, #2ca8ff, #3caeff, #4ab5ff, #58bbff, #65c0ff, #71c6ff, #7fccff, #8dd1ff, #9ad7ff, #a7dcff);
opacity: 0;
transition: opacity 250ms ease-in-out;
z-index: -1;
}
#navbar .navbar-item:nth-child(1):hover::after{
opacity: 1;
}
/* Services Nav Item Hover End */
/* Clients Nav Item Hover Start */
#navbar .navbar-item:nth-child(2)::after{
position: absolute;
content: "";
height: 100%;
width: 100%;
left:0;
background-image: radial-gradient(circle, #00ff51, #23ff5f, #35fe6c, #43fe78, #4ffd83, #5bfd8c, #67fd94, #71fd9c, #7efea5, #8bfeae, #96ffb7, #a2ffbf);
opacity: 0;
transition: opacity 250ms ease-in-out;
z-index: -1;
}
#navbar .navbar-item:nth-child(2):hover::after{
opacity: 1;
}
/* Clients Nav Item Hover End */
/* Abouts Us Nav Item Hover Start */
#navbar .navbar-item:nth-child(3)::after{
position: absolute;
content: "";
height: 100%;
width: 100%;
left:0;
background-image: radial-gradient(circle, #ffa600, #feab1c, #feb12c, #fdb63a, #fdbb46, #fdbf51, #fcc45c, #fcc867, #fccc74, #fcd180, #fbd58d, #fbd999);
opacity: 0;
transition: opacity 250ms ease-in-out;
z-index: -1;
}
#navbar .navbar-item:nth-child(3):hover::after{
opacity: 1;
}
/* About Us Nav Item Hover End */
/* Abouts Us Nav Item Hover Start */
#navbar .navbar-item:nth-child(4)::after{
position: absolute;
content: "";
height: 100%;
width: 100%;
left:0;
background-image: radial-gradient(circle, #cf3dff, #d145ff, #d34dff, #d454fe, #d65bfe, #d865fe, #db6fff, #dd78ff, #e186ff, #e494ff, #e8a2ff, #ebafff);
opacity: 0;
transition: opacity 250ms ease-in-out;
z-index: -1;
}
#navbar .navbar-item:nth-child(4):hover::after{
opacity: 1;
}
/* About Us Nav Item Hover End */
Jquery
$(document).ready(function(){
$("#services").hover(function(){
$("#navbar .container").css({"background-color": "#a7dcff"})
},
function(){
$("#navbar .container").css({"background-color": "#000000"})
});
$("#clients").hover(function(){
$("#navbar .container").css({"background-color": "#96ffb7"})
},
function(){
$("#navbar .container").css({"background-color": "#000000"})
})
$("#about-us").hover(function(){
$("#navbar .container").css({"background-color": "#fbd999"})
},
function(){
$("#navbar .container").css({"background-color": "#000000"})
})
$("#contact-us").hover(function(){
$("#navbar .container").css({"background-color": "#ebafff"})
},
function(){
$("#navbar .container").css({"background-color": "#000000"})
})
});
Here's the jsfiddle of my current attempt at this. It's a mess but this will give you an idea.
I am doing something like this for the very first time. Any help will be appreciated :)
To do what you require you simply need to set the final colour of the gradient to be transparent. That way it will seamlessly merge in to the background colour set on the navbar.
One thing to note about this is that to make this more effective I removed most of the intermediary steps in the gradients. They were not needed, as the colour stops were the same as going straight from one colour at 0% to another at 100%.
However it's worth noting that there's several other improvements that can be made. Firstly you need to DRY up your code; there's a lot of repetition in the JS and CSS. Put the repeated CSS rules on common selectors, and you can genericise the JS by using a single event handler for all .navbar-item element. You can then create a class for each navbar item which toggles a specific class on the navbar container to set its class.
Here's a working example:
jQuery($ => {
let $container = $('#navbar .container');
$('.navbar-item').hover(e => $container.toggleClass(e.target.id));
});
#import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght#300;400;700&family=Poppins:wght#100;200;300;500;600;700;800&display=swap');
html {
height: 100%;
overflow-y: hidden;
overflow-x: hidden;
font-family: 'Open Sans', sans-serif;
font-family: 'Poppins', sans-serif;
background-image: linear-gradient(to top, #3d7ad6, #009eea, #12bff3, #5bdef7, #97fbfb);
}
.all-caps {
text-transform: uppercase;
}
.text-light {
color: #ffffff;
}
#navbar .container {
position: absolute;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
max-height: 60px;
box-shadow: 0px 5px 5px 0px #ffffff5a;
background-color: #000000;
transition: background-color 250ms ease-in-out;
}
#navbar .container.services {
background-color: #a7dcff;
}
#navbar .container.clients {
background-color: #96ffb7;
}
#navbar .container.about-us {
background-color: #fbd999;
}
#navbar .container.contact-us {
background-color: #ebafff;
}
#navbar .logo {
display: flex;
margin-left: 10px;
align-items: center;
}
#navbar .logo img {
cursor: pointer;
height: 40px;
}
#navbar .navbar-items {
height: 60px;
display: flex;
flex-direction: row;
width: auto;
}
#navbar .navbar-item {
position: relative;
cursor: pointer;
font-size: large;
font-weight: 600;
display: flex;
align-items: center;
margin: 0;
padding: 0 45px;
z-index: 1;
}
#navbar .navbar-item::after {
position: absolute;
content: "";
height: 100%;
width: 100%;
left: 0;
opacity: 0;
transition: opacity 250ms ease-in-out;
z-index: -1;
}
#navbar .navbar-item:hover::after {
opacity: 1;
}
#navbar .navbar-item:nth-child(1)::after {
background-image: radial-gradient(circle, #009aff 0%, rgba(167, 220, 255, 0) 100%);
}
#navbar .navbar-item:nth-child(2)::after {
background-image: radial-gradient(circle, #00ff51 0%, rgba(162, 255, 191, 0) 100%);
}
#navbar .navbar-item:nth-child(3)::after {
background-image: radial-gradient(circle, #ffa600 0%, rgba(251, 217, 153, 0) 100%);
}
#navbar .navbar-item:nth-child(4)::after {
background-image: radial-gradient(circle, #cf3dff 0%, rgba(235, 175, 255, 0) 100%);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div id="navbar">
<div class="navbar container">
<div class="logo">
<img src="./img/Mob-Asset 18.png" alt="">
</div>
<div class="navbar-items">
<div class="navbar-item all-caps text-light" id="services">Services</div>
<div class="navbar-item all-caps text-light" id="clients">Clients</div>
<div class="navbar-item all-caps text-light" id="about-us">About Us</div>
<div class="navbar-item all-caps text-light" id="contact-us">Contact Us</div>
</div>
</div>
</div>

Everything not related to navigation bar, overlaps and interrupts it

I wanted to create a navigation bar, at the top of my page, that would follow no matter what way you scroll.
I created it, and after that created a slideshow under it. The problem is, that everything related to my slideshow, will interrupt the navigation bar, when it scrolls through it, they overlap. I don't know how to fix this, and would like to get some help :)
CSS
/* HEADER - HEADER - HEADER */
/* Style the header */
.header {
background-color: lightgray;
padding: 20px;
text-align: center;
}
/* Style the top navigation bar */
.menu_navigation {
position: fixed;
overflow: hidden;
background-color: #333;
top: 0;
width: 100%;
}
/* Style the topnav links */
.menu_navigation a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 15px 25px;
text-decoration: none;
}
/* Change color on hover */
.menu_navigation a:hover {
background-color: rgb(0, 162, 255);
color: black;
}
/* Create three equal columns that floats next to each other */
.column {
float: left;
width: 33.33%;
padding: 10px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
#media screen and (max-width:600px) {}
.column {
width: 100%;
}
* {box-sizing: border-box}
body {font-family: Verdana, sans-serif; margin:0}
.mySlides {display: none}
img {
vertical-align: auto;
position: relative;
top: 52px;
}
#billede1, #billede2, #billede3 {
filter: blur(8px);
}
/* Slideshow container */
.slideshow-container {
width: 1500;
}
/* Next & previous buttons */
.prev, .next {
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -22px;
color: white;
transition: 0.6s ease;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
/* Caption text */
.text {
color: #000000;
font-size: 30px;
padding: 8px 12px;
position: absolute;
bottom: -1200px;
width: 100%;
text-align: center;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active, .dot:hover {
background-color: #717171;
}
/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
#-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
#keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
/* On smaller screens, decrease text size */
#media only screen and (max-width: 300px) {
.prev, .next,.text {font-size: 11px}
}
.footer {
background-color:blue;
text-align: center;
padding: 10px;
}
html
<!DOCTYPE html>
<html>
<title>W3.CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>
<div class="menu_navigation">
Men
Women
Children
About Us
News
</div>
<!-- Slideshow, for under navigationsbaren-->
<div class="slideshow-container">
<div class="mySlides fade">
<div class="numbertext">1 / 3</div>
<img src="C:\Users\Wahab\Desktop\hjemmesidenprojekt\billeder\1.jpg" id="billede1" style="width:100%" height="1000px">
<div class="text">Skjorte - 150 kr</div>
</div>
<div class="mySlides fade">
<div class="numbertext">2 / 3</div>
<img src="C:\Users\Wahab\Desktop\hjemmesidenprojekt\billeder\2.jpg" id="billede2" style="width:100%" height="1000px">
<div class="text">Mørke blå Chino bukser - 540 kr</div>
</div>
<div class="mySlides fade">
<div class="numbertext">3 / 3</div>
<img src="C:\Users\Wahab\Desktop\hjemmesidenprojekt\billeder\3.jpg" id="billede3" style="width:100%" height="1000px">
<div class="text">Hvide Chinos - 430 kr</div>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
<br>
<div style="text-align:center">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
<script>
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
</script>
</body>
</html>
You need to set the z-index of the navbar higher than any other z-index of any element.
The z-index provides a hierarchical structure of when elements are stacked amongst each other.
You can fix this by adding a z-index CSS property to your .menu_navigation class. The z-index property specifies the stack order of an element. An element with greater stack order is always in front of an element with a lower stack order.
.menu_navigation {
position: fixed;
overflow: hidden;
background-color: #333;
top: 0;
width: 100%;
z-index: 100;
}

Element shaking on Hover/Class Toggle only in Safari

I have a sidebar menu with logo toggle button which toggles the class "toggled" and on large screens also appears on hover.
The sidebar is left: 100% and on toggle/hover left: 0;
On all browsers except safari it works fine. Only on safari the logo button wiggles/shakes when letting the navigation appear.
Here a short overview of the code:
.main-navigation {
//Structure
display: inline-block;
width: 160px;
transition: all 250ms ease-in;
height: 100vh;
z-index: 100;
position: fixed;
left: -100%;
background-color: $color__primary;
&.toggled {
left: 0;
}
.menu-toggle {
margin-left: auto;
align-self: flex-end;
display: inline-block;
position: fixed;
background: none;
border: none;
border-radius: 0;
left: 20px;
top: 25px;
width: auto;
height: auto;
padding: 0;
z-index: 110;
&:focus, &:active {
outline: none;
}
}
}
And on large screens i just add the hover:
.main-navigation{
&:hover {
left: 0;
}
}
You can see it live under https://rocket.creos.agency/
I hope im just overlooking something small.
Thanks for the help!
In order to fix your problem you need to move your 'logo' from the nav element. If it is inside, like you have it's trying too animate all elements inside nav.
Here is your logic with simple code (logo is inside nav):
body {
margin: 0;
padding: 0;
}
nav {
position: fixed;
height: 100vh;
width: 160px;
left: -160px;
background-color: tomato;
-webkit-transition: all 250ms ease-in-out;
transition: all 250ms ease-in-out;
}
nav:hover {
left: 0;
}
button {
position: fixed;
top: 10px;
left: 10px;
}
.content {
margin-top: 50px;
}
<nav>
<button>
Hover me
</button>
<div class='content'>
<ul>
<li>
one
</li>
<li>
two
</li>
</ul>
</div>
</nav>
And this is when 'logo' is outside the nav:
(() => {
const btn = document.getElementById('animateNav');
const nav = document.getElementById('navigation');
const content = document.getElementById('content');
btn.addEventListener('mouseover', () => {
nav.classList.add("animate");
});
nav.addEventListener('mouseout', () => {
nav.classList.remove("animate");
});
nav.addEventListener('mouseover', () => {
nav.classList.add("animate");
});
content.addEventListener('mouseover', () => {
nav.classList.add("animate");
});
})();
body {
margin: 0;
padding: 0;
}
nav {
position: fixed;
height: 100vh;
width: 160px;
left: -160px;
background-color: tomato;
-webkit-transition: all 250ms ease-in-out;
transition: all 250ms ease-in-out;
}
nav.animate {
left: 0;
}
button {
position: fixed;
top: 10px;
left: 10px;
}
#content {
margin-top: 50px;
}
<nav id='navigation'>
<div id='content'>
<ul>
<li>
one
</li>
<li>
two
</li>
</ul>
</div>
</nav>
<button id='animateNav'>
Hover me
</button>
All difference is in second example that you need to toggle a class for nav using JavaScript. I provided not efficient logic to toggle a class, but I just wanted to present to you working solution.
P.S. don't use <a> tag inside of <button> tag

On-click transitioning <ul> does not respond

I have a responsive navigation which should display a menu when a button is clicked. When it is clicked, the ul containing the navigation list is added a class (.show-nav) to by jQuery/JS. When this happens a CSS-rule for .show-nav changes the opacity and top-values, so that the ul comes down. I tried adding a transition to this, but the ul refuses to respond to that.
On the other hand, I also have a header-element, which changes the background-color when a certain y scroll value is reached (also done by JS). This works in the exacly same way as the latter, by adding a class to the header and having the CSS applying a background-color.
function toggleClass(jqo, c) {
var o = $(jqo);
if (!o.hasClass(c)) {
o.addClass(c);
} else {
o.removeClass(c);
}
}
header {
width: 100%;
text-align: right;
position: fixed;
background-color: rgba(0, 0, 0, 0);
transition: background-color 0.3s;
}
header .mobile-list {
display: none;
}
.mobile-header .mobile-list {
width: 100%;
height: 100%;
padding-top: 90px;
right: 0;
top: -50%;
opacity: 0.5;
position: fixed;
z-index: -1;
background-color: #005163;
transition: top 2s, opacity 2s;
}
.show-nav .mobile-list {
display: block;
top: 0;
opacity: 1;
}
.compact {
background-color: #005163;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<nav>
<button class="hamburger" onclick="toggleClass('.hamburger', 'is-active'); toggleClass('header', 'show-nav')" type="button">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
</button>
<ul class="mobile-list">
<li>PHYSICS</li>
<li>CHEMISTRY</li>
<li>BIOLOGY</li>
<li>MATH</li>
<li>TOOLS</li>
</ul>
</nav>
</header>
.compact is assigned by JS, just like .show-nav. But header is responding to the transition and the ul is not!
Note that .mobile-header is active in every case, so that's no concern.
I also concluded that the ul does respond to all other CSS, just not the transition. I've looked at other websites (dashlane.com) that have the same kind of navigation system and tried to copy it's structure, but without much avail. How can I achieve the ul having a transition and why does my header react where my ul doesn't?
Thanks in advance.
EDIT:
Added transition line in CSS under .mobile-header .mobile-list.
EDIT: Added jQuery code.
You have to know that the css display property cannot be animated,
So you have to try another solution, best thing at the meanwhile is the visibility and opacity properties.
just remove the display: none / display: block and replace it with:
/*Element style when it's hidden*/
.elementStyle {
opacity: 0;
visibility: hidden;
}
/*Element style when it's visible*/
.elementStyle {
opacity: 1;
visibility: visible;
}
function toggleClass(jqo, c) {
var o = $(jqo);
if (!o.hasClass(c)) {
o.addClass(c);
} else {
o.removeClass(c);
}
}
header {
width: 100%;
text-align: right;
position: fixed;
background-color: rgba(0, 0, 0, 0);
transition: background-color 0.3s;
}
.mobile-header .mobile-list {
width: 100%;
height: 100%;
padding-top: 90px;
right: 0;
top: -50%;
opacity: 0.5;
position: fixed;
z-index: -1;
background-color: #005163;
transition: top 2s, opacity 2s;
}
header .mobile-list {
visibility: hidden;
transition: 1s;
/*Add whatever transition you want*/
opacity: 0;
display: block;
}
.show-nav .mobile-list {
top: 0;
opacity: 1;
visibility: visible;
}
.compact {
background-color: #005163;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<nav>
<button class="hamburger" onclick="toggleClass('.hamburger', 'is-active'); toggleClass('header', 'show-nav')" type="button">Test Button
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
</button>
<ul class="mobile-list">
<li>PHYSICS</li>
<li>CHEMISTRY</li>
<li>BIOLOGY</li>
<li>MATH</li>
<li>TOOLS</li>
</ul>
</nav>
</header>

Lines behind image (top and bottom)

I have a centered image on my website, where i need a top and bottom line.
The catch here, is that i need both lines 1px in behind the image, so that they are "align" in top and bottom of the image. I tried using box-shadow but it doesn't work in IE8 (i know it's terrible).
Anyone who has a answer and dying to tell me?
A quick UPDATE to show you my issue:
I'm using bootstrap 2 and displaying a carousel for images. And when there are only one image, the line should be visible. It need to be able to run in IE8 for the customer.
Image example:
http://postimg.org/image/xi3eurm81/
My example with shadow-box is here:
Html:
<div id="artist-carousel">
<div class="simple-carousel-window">
<div class="simple-carousel-rail">
#if (Model != null)
{
for (var i = 0; i < 3 * Model.Images.Count; i++) // times 3 due to infinite scrolling
{
var index = i % Model.Images.Count;
<div class="simple-carousel-div" data-index="#(i)" data-link="#Model.NativeImages[index]">
<a class="element">
<img src="#Model.Images[index]" />
</a>
<a class="fullsize">
<img src="~/content/images/carousel-fullsize.png" />
</a>
</div>
if (Model.Images.Count <= 2 && i >= 0) { break; }
}
}
</div>
#if (Model.Images.Count >= 3)
{
<a class="simple-carousel-prev" href="#" data-slide="prev">
<img src="~/content/images/carousel-left.png" /></a>
<a class="simple-carousel-next" href="#" data-slide="next">
<img src="~/content/images/carousel-right.png" /></a>
}
</div>
</div>
CSS:
.simple-carousel-window {
width: 820px;
white-space: nowrap;
overflow: hidden;
position: relative;
display: block;
margin-left: -20px;
box-shadow: inset 0 2px 2px -2px #ebebeb, inset 0 -2px 2px -2px #ebebeb;
line-height: 0;
margin-bottom: 20px;
.simple-carousel-rail {
font-size: 0;
}
.simple-carousel-prev {
position: absolute;
top: 150px;
left: 10px;
display: block;
opacity: 0.8;
}
.simple-carousel-next {
position: absolute;
top: 150px;
right: 10px;
display: block;
opacity: 0.8;
}
.simple-carousel-div {
display: inline-block;
position: relative;
.element {
img {
height: 360px;
float: left;
}
}
.fullsize {
display: block;
opacity: 0.5;
position: absolute;
// centering image
top: 150px;
margin-left: -85px;
left: 50%;
}
}
}
DEMO: http://jsfiddle.net/CXKrh/
HTML
<div>
<img src="http://placekitten.com/100" />
</div>
CSS
div {
width: 300px;
height: 98px;
overflow: visible;
border: 1px solid red;
}
div > img {
height: 100px;
margin-top: -1px;
}
The idea is that the height of the container = image height - border width (top and bottom)
We then apply a negative margin to the images to "bump" the image back over the border.