Here is the deal. I'm trying to create a mobile first navigation bar using css3, html5 and transition properties. I've been successful so far but I am unable to control the transition for when I resize the window (using media queries min-width) from desktop view to mobile view. I've add a Toggle button in the mobile view to create a burger menu that disappears at 600px and vice versa. when the button is unchecked (menu not visible) and I resize the view from desktop to mobile there is a very fast transition that I don't want. I've tried so far so many variants and nothing seems to work. Any suggestion would be greatly appreciated!
* {
margin: 0;
padding: 0;
outline: none;
box-sizing: border-box;
}
body {
background: #eee;
color: #444;
-webkit-font-smoothing: antialiased;
font-family: Arial, sans-serif;
font-weight: 400;
height: auto !important;
height: 100%;
min-height: 100%;
text-rendering: optimizeLegibility;
}
header {
display: block;
background-color: #FFF;
height: inherit;
}
nav {
text-align: center;
line-height: 3.5em;
}
nav ul {
background-color: rgba(255, 255, 255, 0.15);
float: none;
line-height: inherit;
margin: 0;
}
nav ul li {
display: block;
list-style-type: none;
}
nav ul li:hover {
background-color: #ededed;
}
nav ul li a {
text-decoration: none;
color: #313131;
}
nav ul li a:hover {
color: #b9b5b5;
}
#menuToggle {
display: none;
}
.menu {
width: 100%;
position: absolute;
top: 66px;
transition: all 300ms ease-in-out;
}
.menu-icon {
float: right;
color: #2f2f2f;
cursor: pointer;
padding-top: 0.46em;
padding-right: 1em;
padding-left: 1em;
padding-bottom: 0.46em;
text-decoration: none;
font-size: 30px;
}
.menu {
max-height: 0;
transition-property: max-height 0s ease-in-out;
overflow: hidden;
}
#menuToggle:checked ~ header .menu {
max-height: 300px;
transition-property: all 0.6s ease-in-out;
}
#logo {
float: none;
text-align: left;
padding-top: 7px;
padding-left: 2em;
height: inherit;
}
/*------------ MEDIUM BIG SCREEN -----------------------*/
#media screen and (min-width:600px) {
#logo {
float: left;
}
.menu {
position: relative;
top: -70px;
height: 100%;
max-height: 100%;
transition-property: none;
}
.menu-icon {
display: none;
}
header {
height: 70px;
background-color: #FFF;
margin: auto;
width: 100%;
}
nav {
width: 100%;
}
nav ul {
background-color: #FFF;
display: block;
float: right;
padding: 0.55em 2em 0 0;
height: inherit;
}
nav ul li {
display: inline-flex;
}
nav ul li:hover {
background-color: #FFF;
}
nav ul li a {
padding: 0 2em;
}
<!-- === MENUTOGGLE === -->
<input type="checkbox" name="checkbox" id="menuToggle" value="value">
<label for="menuToggle" class="menu-icon">☰</label>
<!-- ==== HEADER ==== -->
<header class="header">
<div id="logo">
<h1><img src="images/logo.png" alt="Hello"></h1>
</div>
<nav class="menu">
<ul>
<li>Work</li>
<li>About</li>
<li>Blog </li>
<li>Contact</li>
</ul>
</nav>
</header>
Put everything you only want to happen on the small screen inside:
#media screen and (max-width:599px) {
}
And everything you only want to happen on the large screen inside your:
#media screen and (min-width:600px) {
}
Related
My wordpress website (mustafasprojects.com) is missing its mobile navbar when I pull it up in wordpress. It is there in the html file when I inspect it but I cannot get the same navbar to appear in wordpress. as far as my html code it's the standard navbar stuff.
<header id="header">
<h1>Mustafa's Projects</h1>
<nav id="nav">
<ul>
<li>Home</li>
<li>My Work</li>
</ul>
</nav>
</header>
#header {
position: fixed;
z-index: 10000;
left: 0;
top: 0;
width: 100%;
background: rgba(255, 255, 255, 0.95);
height: 3em;
line-height: 3em;
box-shadow: 0 0 0.15em 0 rgba(0, 0, 0, 0.1);
animation: 1s ease-out 0s 1 SlideInFromTop;
}
#header h1 {
height: 3em;
left: 1em;
line-height: 3em;
margin: 0;
padding: 0;
position: absolute;
top: -.225em;
font-size: 1.2em;
}
#header h1 a {
color: #000
font-size: 1.1em;
border: 0;
}
#header nav {
position: absolute;
right: 0.5em;
top: .525em;
height: 1em;
line-height: 1em;
vertical-align: middle;
}
#header nav ul {
margin: 0;
}
#header nav ul li {
display: inline-block;
margin-left: 0.5em;
font-size: 0.95em;
}
#header nav > ul > li a {
display: inline-block;
height: 1.7em;
line-height: 1.7em;
padding: 0 .3em;
border-radius: 6px;
}
#header nav > ul > li a:not(.button) {
color: #000;
display: inline-block;
text-decoration: none;
border: 0;
}
#header nav > ul > li a:not(.button).icon:before {
color: #999;
margin-right: 0.5em;
}
#header nav > ul > li a:hover:not(.active) {
background-color: #266dd3;
}
#header nav > ul > li:first-child {
margin-left: 0;
}
#header nav > ul > li.active a:not(.button) {
background-color: rgba(153, 153, 153, 0.25);
}
#header nav > ul > li .button {
margin: 0 0 0 0.5em;
position: relative;
}
#media screen and (max-width: 736px) {
#header {
height: 2.5em;
line-height: 2.5em;
}
#header h1 {
text-align: center;
position: relative;
left: 0;
top: 0;
height: 2.5em;
line-height: 2.5em;
}
#header h1 a {
font-size: 1em;
}
#header nav {
display: none;
}
}
.header.onload-header-fade-down {
transform: 0.75s ease-in-out;
transition: opacity .75s ease-in-out, transform .75s ease-in-out;
}
So yeah if anyone can help me solve the case of the missing navbar it would be much appreciated. It doesn't appear in the tablet or mobile view on wordpress but it appears in the tablet/mobile view on the inspector btw.
Thanks
You are hiding the header at screen widths smaller than 840px:
#media screen and (max-width: 840px)
#header {
display: none;
}
on line 2906 of your html file.
Actually, something really bad is going on, as you have a duplicate <header id="header"> element.
If you look at your Media query, you're hiding the nav bar in any screen size under 736px.
#media screen and (max-width: 736px) {
#header nav {
display: none;
}
}
If you remove that, you will then see your nav bar. Depending on what the rest of your code looks like, you will either have to >
1) Remove the whole #header nav line from your max-width query
or
2) Change it to display:block.
I am not sure what the rest of your code looks like or what your trying to accomplish, but either of those will work.
This question already has answers here:
How can I transition width of content with width: auto?
(2 answers)
workaround for display block and css transitions not triggering
(4 answers)
Closed 5 years ago.
this is my very second question!
I also searched in the questions but nothing helps.
I have a problem with transitions. I am trying to apply a 300ms transition to the menu when the toggle button is checked on mobile view; I tried in vain with negative values in the class .menu. Now, doing so the menu slides up but I want it to slide down and nothing seems to help. I also tried with the z-index but nothing seems to work.
I really can't figure out what to do. Any help that could send me on the right direction would be greatly appreciated!
<!-- === MENUTOGGLE === -->
<input type="checkbox" name="checkbox" id="menuToggle" value="value">
<label for="menuToggle" class="menu-icon">☰</label>
<!-- ==== HEADER ==== -->
<header>
<div id="logo" class="brand">
<h1><img src="images/logo.png" alt="Hello"></h1>
</div>`enter code here`
<nav class="menu">
<ul>
<li>Work</li>
<li>About</li>
<li>Blog </li>
<li>Contact</li>
</ul>
</nav>
</header>
* {
margin: 0;
padding: 0;
outline: none;
box-sizing: border-box;
}
body {
background: #eee;
color: #444;
-webkit-font-smoothing: antialiased;
font-family: Arial, sans-serif;
font-weight: 400;
height: auto !important;
height: 100%;
min-height: 100%;
text-rendering: optimizeLegibility;
}
header {
display: block;
background-color: #FFF;
height: inherit;
}
nav {
text-align: center;
line-height: 3.5em;
}
nav ul {
background-color: rgba(255, 255, 255, 0.15);
float: none;
line-height: inherit;
margin: 0;
}
nav ul li {
display: block;
list-style-type: none;
}
nav ul li:hover {
background-color: #ededed;
}
nav ul li a {
text-decoration: none;
color: #313131;
}
nav ul li a:hover {
color: #b9b5b5;
}
#menuToggle {
display: none;
}
.menu {
width: 100%;
position: absolute;
top: 66px;
transition: all 300ms ease-in-out;
}
.menu-icon {
float: right;
color: #2f2f2f;
cursor: pointer;
padding-top: 0.46em;
padding-right: 1em;
padding-left: 1em;
padding-bottom: 0.46em;
text-decoration: none;
font-size: 30px;
}
.menu {
display: none;
}
#menuToggle:checked ~ header .menu {
display: block;
top;
66px;
}
#logo {
float: none;
text-align: left;
padding-top: 7px;
padding-left: 2em;
height: inherit;
}
#menuToggle:checked ~ header .menu {
display: block;
top;
66px;
}
should be
#menuToggle:checked ~ header .menu {
display: block;
top: 66px;
}
#media screen and (min-width:600px) {
#logo {
float: left;
}
.menu {
width: 100%;
height: 70px;
position: absolute;
display: block;
}
.menu-icon {
display: none;
}
header {
height: 70px;
background-color: #FFF;
margin: auto;
width: 100%;
}
nav {
height: -66px;
width: 100%;
}
nav ul {
background-color: #FFF;
display: inline;
float: right;
padding: 0.55em 2em 0 0;
height: inherit;
}
nav ul li {
display: inline;
margin: 0.2em auto;
}
nav ul li:hover {
background-color: #FFF;
}
nav ul li a {
padding: 0 2em;
}
<!-- === MENUTOGGLE === -->
<input type="checkbox" name="checkbox" id="menuToggle" value="value">
<label for="menuToggle" class="menu-icon">☰</label>
<!-- ==== HEADER ==== -->
<header>
<div id="logo" class="brand">
<h1><img src="images/logo.png" alt="Hello"></h1>
</div>`enter code here`
<nav class="menu">
<ul>
<li>Work</li>
<li>About</li>
<li>Blog </li>
<li>Contact</li>
</ul>
</nav>
</header>
I have a CSS responsive menu that I made. I would like to add a button that show menu when the screen is smaller. This is my link to my current code pen
here is the code in the stackoverflow code snippet
.nav ul {
list-style: none;
background-color: #00FFFF;
text-align: center;
padding: 0;
margin: 0;
}
.nav li {
font-family: Georgia;
font-size: 1.2em;
line-height: 40px;
height: 40px;
border-bottom: 1px solid #ffffff;
}
.nav a {
text-decoration: none;
color: #000000;
display: block;
transition: .3s background-color;
}
.nav a:hover {
background-color: #036;
color: #ffffff;
}
#media screen and (min-width: 600px) {
.nav li {
width: 120px;
border-bottom: none;
height: 50px;
line-height: 50px;
font-size: 1.4em;
}
/* Option 1 - Display Inline */
.nav li {
display: inline-block;
margin-right: -4px;
}
/* Options 2 - Float
.nav li {
float: left;
}
.nav ul {
overflow: auto;
width: 600px;
margin: 0 auto;
}
.nav {
background-color: ffffff;
}
*/
}
<div class="nav">
<ul>
<li>Home</li>
<li>Resume</li>
<li>Biography</li>
<li>Contact</li>
</ul>
</div>
You mean like a Hamburger Menu?
You'll need to use javascript for that. I don't think there's a way to hide and show a menu on button click with pure css. I could be wrong.
I'm trying to create a responsive, drop-down CSS menu, and I have a media query that targets mobile devices (760 pixels). I'm trying to make all the links occupy the entire width, and that goes well, but the problem is when I display the drop down menu when the width is less than 760 pixels, all of the links of the drop down menu are cramped into the navigation links. I would like to know how to solve this problem, because I have been thinking for a long time and haven't figured out a solution. I want the drop-down menu for services to be directly below services, and the final contact link to go below the drop-down menu. This is the problem:
Below is the HTML and the CSS, as well as a link to the JSFiddle.
HTML:
<div class="wrapper">
<ul class="links">
<li id="active">home
</li><li>about
</li><li>services
<ul class="links">
<li>web development
</li><li>design templates
</li><li>networking
</li><li>custom builds
</li>
</ul>
</li><li>contact</li>
</ul>
</div>
CSS:
html,
body {
margin: 0;
padding: 0;
font-family: Source Sans Pro, Helvetica, sans-serif;
}
.wrapper {
width: 100%;
height: auto;
}
ul.links {
margin: 0px;
padding: 0px;
list-style: none;
background-color: #EBEBEB;
}
ul.links a {
color: #737373;
text-decoration: none;
}
ul.links ul {
display: none;
position: absolute;
top: 100%;
left: 0;
background: #fff;
}
ul.links li {
background: none;
color: #737373;
display: inline-block;
position: relative;
font-size: 19px;
padding-top: 22px;
padding-bottom: 22px;
padding-left: 35px;
padding-right: 35px;
transition: background 0.2s linear 0s, color 0.2s linear 0s;
-webkit-transition: background 0.2s linear 0s, color 0.2s linear 0s;
}
ul.links ul li {
position: relative;
font-size: 18px;
display: block;
float: left;
width: 100%;
}
ul.links li:hover {
background-color: #6ECFFF;
}
ul.links li:hover ul {
display: block;
}
ul.links li:hover .link {
color: #F0F0F0;
}
ul.links ul li:hover .link2 {
color: #F0F0F0;
}
#active {
background-color: #6ECFFF;
}
#active a {
color: #F0F0F0;
}
#media screen and (max-width: 760px) {
ul.links li
{
width: 100%;
}
ul.links ul {
position: absolute;
left: 0;
}
ul.links ul li {
background: #EBEBEB;
}
}
JSFiddle: https://jsfiddle.net/7tkn7zzs/
You should make ul.links ul { to position: relative; in media query to display it proper.
ul.links ul {
position: relative;
left: 0;
}
Working Fiddle
ul.links ul {
position: relative;
left: -35px; /* equal to padding left */
}
I can't find a way to properly align a button in the middle of floating elements.
button {
float:left;
}
header {
overflow: hidden;
background: #222;
}
header a, header label {
display: block;
padding: 20px;
color: #fff;
text-decoration: none;
line-height: 20px;
}
header a:hover, header label:hover { color: #aaa; }
header label {
float: right;
padding: 18px 20px;
cursor: pointer;
}
header label:after {
content: "\2261";
font-size: 1.8em;
}
.logo {
float: left;
font-weight: bold;
font-size: 1.5em;
}
nav {
float: right;
max-height: 0;
width: 100%;
-webkit-transition: max-height 0.3s;
-moz-transition: max-height 0.3s;
-o-transition: max-height 0.3s;
transition: max-height 0.3s;
}
nav ul {
margin: 0;
padding: 0;
padding-bottom: 10px;
}
nav li {
display: block;
text-align: center;
}
nav a {
padding: 10px;
width: 100%;
}
#nav { display: none; }
#nav:checked ~ nav {
max-height: 200px; /* This can be anything bigger than your nav height. The transition duration works with this */
}
#media only screen and (min-width: 700px) {
header label { display: none; }
nav {
width: auto;
max-height: none;
}
nav ul {
padding: 0;
padding-right: 10px;
}
nav li {
display: inline-block;
text-align: left;
}
header nav a {
display: inline-block;
padding: 20px 10px;
width: auto;
}
}
<header>
<a class="logo" href="http://minimaldev.com">Minimal Menu</a>
<input id="nav" type="checkbox">
<label for="nav"></label>
<button>centered button ?</button>
<nav>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
</nav>
</header>
See example also on codepen
I tried the display-table trick, but it breaks the navbar behaviour on small device (responsive).
I also tried this technique , but I have the same problem.
Any idea ? I thought about using calc(), but I can't find the right formula.
I made a couple of edits:
added text-align: center to the parent element of the button
bumped the button off the top edge with manual pixel adjustments (assuming the design stays rigid in terms of logo size, it is not a responsive solution because of the non-responsive nature of font and padding sizing).
Here it is in a CodePen
HTML:
<header>
<a class="logo" href="http://minimaldev.com">Minimal Menu</a>
<input id="nav" type="checkbox">
<label for="nav"></label>
<button>centered button</button>
<nav>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
</nav>
</header>
CSS:
button{
margin-top: 18px;
}
header {
text-align: center;
overflow: hidden;
background: #222;
}
header a, header label {
display: block;
padding: 20px;
color: #fff;
text-decoration: none;
line-height: 20px;
}
header a:hover, header label:hover { color: #aaa; }
header label {
float: right;
padding: 18px 20px;
cursor: pointer;
}
header label:after {
content: "\2261";
font-size: 1.8em;
}
.logo {
float: left;
font-weight: bold;
font-size: 1.5em;
}
nav {
float: right;
max-height: 0;
width: 100%;
-webkit-transition: max-height 0.3s;
-moz-transition: max-height 0.3s;
-o-transition: max-height 0.3s;
transition: max-height 0.3s;
}
nav ul {
margin: 0;
padding: 0;
padding-bottom: 10px;
}
nav li {
display: block;
text-align: center;
}
nav a {
padding: 10px;
width: 100%;
}
#nav { display: none; }
#nav:checked ~ nav {
max-height: 200px; /* This can be anything bigger than your nav height. The transition duration works with this */
}
#media only screen and (min-width: 700px) {
header label { display: none; }
nav {
width: auto;
max-height: none;
}
nav ul {
padding: 0;
padding-right: 10px;
}
nav li {
display: inline-block;
text-align: left;
}
header nav a {
display: inline-block;
padding: 20px 10px;
width: auto;
}
}