Im using a CSS navigation overlay menu, code below
When you click on the navigation menu and select which page you want to go to the overlay stays and does not disappear..
If i link it to another html page it works fine, but as i have all my pages on one page i'm linking it through href to a div like (href="#about")
Any idea how i can make the overlay menu hide once you click on your navigation pages?
Any help much appreciated, thank you
<nav id="menu">
<input type="checkbox" id="toggle-nav"/>
<label id="toggle-nav-label" for="toggle-nav"></label>
<div class="box">
<ul>
<li>About</li>
<li>Services</li>
<li>Work</li>
<li>Contact</li>
</ul>
</div>
</nav>
a { text-decoration: none; }
a:hover { text-decoration: underline; }
li { list-style: none; }
#menu .box {
position: fixed;
text-align: center;
overflow: hidden;
z-index: -1;
opacity: 0;
width: 100%;
height: 100%;
left: 0px;
top: 0px;
background: black;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#menu ul {
position: relative;
top: 20%;
-webkit-transform: scale(2);
-moz-transform: scale(2);
-ms-transform: scale(2);
transform: scale(2);
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#menu li {
margin: 60px;
}
#menu li a {
border-radius: 3px;
padding: 15px;
border: 1px solid transparent;
text-decoration: none;
font-family: 'Montserrat', sans-serif;
font-size: 18px;
color: #fff;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
#menu li a:hover { border-color: #fff; }
#menu li a i {
margin-right: 5px;
font-size: 24px;
}
#toggle-nav-label {
color: black;
text-align: center;
line-height: 30px;
font-size: 30px;
display: block;
cursor: pointer;
position: relative;
z-index: 500;
width: 30px;
height: 30px;
border-radius: 5px;
}
#toggle-nav { display: none; }
#toggle-nav:checked ~ .box {
opacity: 1;
z-index: 400;
}
#toggle-nav:checked ~ .box ul {
-webkit-transform: scale(1);
-moz-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
#toggle-nav:checked ~ #toggle-nav-label {
color: white;
position: fixed;
}
The easiest answer is to simply uncheck the checkbox using javascript ... but that kinda defeats the purpose of a checkbox hack doesn't it. I can't think of another way other than to simply make the user click the label again to close the menu. Kinda ruins the effect you're going for though. In case nothing better comes up here is a quick javascript solution:
window.onload = function() {
// Add a listener for any clicks on the menu
document.getElementById('menu').addEventListener('click', function(edit) {
var targetName = event.target.tagName;
// Make sure that the element being clicked is a link or an icon
if (targetName !== 'A' && targetName !== 'I') {
return;
}
// Uncheck the checkbox
document.getElementById('toggle-nav').checked = false;
});
}
And a codepen. If you want to allow the user to close the menu by clicking anywhere you could add && targetName !== 'DIV' to the if statement. Hope it helps, or that someone comes up with a better method, because personally, I'd love to find a way to do this with just CSS.
EDIT
Fixed JS code to use targetName. Added support for icons. Fixed codepen demo to match OP demo.
EDIT 2
Found a cross browser error. Fixed for Firefox by including event in the function parameters.
Related
I am trying to create 6 buttons of the same size as children of a flexbox element. Before showing the buttons there should be a plus exactly between the spot where the two middle buttons will apppear. For that I included the plus within the same div as the buttons and toggle the visibility of the plus and the buttons using JavaScript.
The problem I have is that the hidden plus takes up place within the parent element and changes the size of the other children elements. How can I include a hidden element that does not change the other child elements?
Here is my code:
<div class="button-wrapper" id="allButtons">
<button id="button0"><span></span><p></p></button>
<button id="button1"><span></span><p></p></button>
<button id="button2"><span></span><p></p></button>
<span id="fixation-cross"><strong>+</strong></span>
<button id="button3"><span></span><p></p></button>
<button id="button4"><span></span><p></p></button>
<button id="button5"><span></span><p></p></button>
</div>
#fixation-cross {
visibility: hidden;
font-size: 44px;
color: black;
font-family: Helvetica, Arial, sans-serif;
}
button span {
position: absolute;
top: 8px;
left: 50%;
transform: translateX(-50%);
-ms-transform: translateX(-50%);
-moz-transform: translateX(-50%);
-webkit-transform: translateX(-50%);
transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
-webkit-transition: all .2s ease-in-out;
opacity: 0;
font-weight: bold;
color: black;
}
button {
position: relative;
flex: 1 1 auto;
-webkit-flex: 1 1 auto;
font-family: Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 1.25em;
letter-spacing: 0.05em;
background: none;
border: 1px solid black;
height: 80px;
margin: 10px;
transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
-webkit-transition: all .2s ease-in-out;
}
.button-wrapper {
display: flex;
display: -webkit-flex;
height: 50vh;
align-items: flex-end;
}
button:disabled {
background: lightgrey;
}
button:disabled span {
opacity: 1;
}
#allButtons {
visibility:hidden;
}
Thank you a lot in advance!
try making the hidden 'plus' have a position: absolute and the flexbox element should have position: relative. You can then center the 'plus' usingtop bottom right and left properties
You can force the #fixation-cross element width to be 0, it will then not count into the flex spacing.
Doing so, the + sign is then shifted to the right, so we need to somehow move it of half of its size to the left. Unfortunately the transform: translateX(-50%) trick won't work as 50% of 0 is definitely 0.
To achieve the trick I forced the width of the inner strong element with a fixed width and set its display property to block to ensure it will be this size exactly. I also center align the text in order to be sure the + sign is in the middle.
All this allows me to transform the parent and translate it to the left of half the width of its content, as we now know exactly how much it will be.
The result in the snippet below:
#fixation-cross strong{
width: 30px;
display: block;
text-align:center;
}
#fixation-cross {
width: 0;
transform: translate(-15px);
font-size: 44px;
color: black;
font-family: Helvetica, Arial, sans-serif;
}
button span {
position: absolute;
top: 8px;
left: 50%;
transform: translateX(-50%);
-ms-transform: translateX(-50%);
-moz-transform: translateX(-50%);
-webkit-transform: translateX(-50%);
transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
-webkit-transition: all .2s ease-in-out;
opacity: 0;
font-weight: bold;
color: black;
}
button {
position: relative;
flex: 1 1 auto;
flex-grow: 1;
-webkit-flex: 1 1 auto;
font-family: Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 1.25em;
letter-spacing: 0.05em;
background: none;
border: 1px solid black;
height: 80px;
margin: 10px;
transition: all .2s ease-in-out;
-ms-transition: all .2s ease-in-out;
-moz-transition: all .2s ease-in-out;
-webkit-transition: all .2s ease-in-out;
}
.button-wrapper {
display: flex;
display: -webkit-flex;
height: 50vh;
align-items: flex-end;
}
.button-wrapper button{
background-color: red;
}
button:disabled {
background: lightgrey;
}
button:disabled span {
opacity: 1;
}
<div class="button-wrapper" id="allButtons">
<button id="button0"><span></span><p></p></button>
<button id="button1"><span></span><p></p></button>
<button id="button2"><span></span><p></p></button>
<span id="fixation-cross"><strong>+</strong></span>
<button id="button3"><span></span><p></p></button>
<button id="button4"><span></span><p></p></button>
<button id="button5"><span></span><p></p></button>
</div>
I am using the CSS transition ease-in-out on a navigation bar for mouse hover.
However the transition only eases in when the mouse cursor hovers, and snaps back immediately after the cursor leaves the hyperlink area, it does not ease out smoothly.
This is the CSS I've used:
nav {
position: fixed;
z-index: 1000;
top: 0;
bottom: 0;
width: 200px;
background-color: #036;
}
nav ul {
list-style: none;
margin-top: 15px;
}
nav ul li a {
text-decoration: none;
display: block;
text-align: center;
color: #fff;
padding: 10px 0;
}
.nav-logo {
margin-left: 20px;
background-color: #cacaca;
}
.nav-logo:hover {
transform: scale(1.1);
transition: all 1s ease-in-out;
}
nav ul li a:hover {
background-color: gold;
color: black;
border-radius: 10px;
transform: scale(1.1);
transition: .3s ease-in-out;
-moz-transition: all 1s ease-in-out;
-ms-transform: scale(1.1);
-webkit-transform: scale(1.1);
}
You need to take the transition styles:
transition: .3s ease-in-out;
-moz-transition: all 1s ease-in-out;
-ms-transform: scale(1.1);
-webkit-transform: scale(1.1);
And remove them from the nav ul li a:hover and add them to the actual element nav ul li a
Whilst they remain on the hover, you are essentially removing the transition when not hovered, therefore the transition does not apply after you leave the hover state.
You need to add the transitions on the root element, not on the hover state.
nav {
background-color: yellow;
position: relative;
overflow: auto;
transition: background-color .3s ease-in-out;
}
nav:hover {
background-color: pink;
}
http://codepen.io/mrshannonyoung/pen/BLzpNz
HTML
<input type="checkbox" id="op">
</input><div class="lower">
<label for="op">click the text</label>
</div>
<div class="overlay overlay-hugeinc">
<label for="op"></label>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Clients</li>
<li>Contact</li>
</ul>
</nav>
CSS
#import "http://webfonts.ru/import/notcourier.css";
body{ background:url('http://cs625217.vk.me/v625217712/1a11c/0QgZ5V0MWEo.jpg')
}
.lower{
width:340px;
margin:10% auto;
padding:50px;
background:white;
opacity:0.8;
color:black;
box-shadow:inset 0 0 0 1px black;
border:30px solid white;
}
.lower:hover{
background:black;
color:white;
box-shadow:inset 0 0 0 1px white;
border:30px solid black;
}
input{
display:none;
}
.lower label{
font-family: 'NotCourierSans';
text-transform:uppercase;
font-size:40px;
text-align:center;
}
.lower label:hover{
cursor:pointer;
}
.overlay{
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(0,0,0,0.9);
}
.overlay label{
width: 58px;
height:58px;
position: absolute;
right: 20px;
top: 20px;
background: url('http://tympanus.net/Development/FullscreenOverlayStyles/img/cross.png');
z-index: 100;
cursor:pointer;
}
.overlay nav {
text-align: center;
position: relative;
top: 50%;
height: 60%;
font-size: 54px;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.overlay ul {
list-style: none;
padding: 0;
margin: 0 auto;
display: inline-block;
height: 100%;
position: relative;
}
.overlay ul li {
display: block;
height: 20%;
height: calc(100% / 5);
min-height: 54px;
}
.overlay ul li a {
font-weight: 300;
display: block;
color: white;
text-decoration:none;
-webkit-transition: color 0.2s;
transition: color 0.2s;
font-family: 'NotCourierSans';
text-transform:uppercase;
}
.overlay ul li a:hover,
.overlay ul li a:focus {
color: #849368;
}
.lower~.overlay-hugeinc{
opacity: 0;
visibility: hidden;
-webkit-transition: opacity 0.5s, visibility 0s 0.5s;
transition: opacity 0.5s, visibility 0s 0.5s;
}
#op:checked~.overlay-hugeinc{
opacity: 1;
visibility: visible;
-webkit-transition: opacity 0.5s;
transition: opacity 0.5s;
}
.overlay-hugeinc nav {
-moz-perspective: 300px;
}
.overlay-hugeinc nav ul {
opacity: 0.4;
-webkit-transform: translateY(-25%) rotateX(35deg);
transform: translateY(-25%) rotateX(35deg);
-webkit-transition: -webkit-transform 0.5s, opacity 0.5s;
transition: transform 0.5s, opacity 0.5s;
}
#op:checked~.overlay-hugeinc nav ul {
opacity: 1;
-webkit-transform: rotateX(0deg);
transform: rotateX(0deg);
}
#op:not(:checked)~.overlay-hugeinc nav ul {
-webkit-transform: translateY(25%) rotateX(-35deg);
transform: translateY(25%) rotateX(-35deg);
}
Full screen overlay menu (pure css)
Hello, I'm using this code to make an overlay menu with just css. Its works fine but I want it to close when I click a menu link, not just the close icon.
This will be an one page design website, so the menu ideally will slide down and away and the new content displayed.
Try including data-toggle and data-target selectors on your menu list items.
<li>Home</li>
$('.overlay ul li a').click(function() {
$('#op').attr('checked', false); // Unchecks it
});
I was trying to fix it with just css but no progress. Then I try using jquery and it's working. If you have a better solution please post. Thanks all.
If you didn't want to use jQuery for the page load time/performance issue, you could have turned each menu item into a checkbox. Since your site is a single page, using checkbox for navigation would have simplified your code as well; killing two birds with one stone. :D
I'm working with a template that uses Font Awesome for social media icons. Since one of the icons I need is not included in Font Awesome I found a CSS trick to overwrite a certain icon by a custom image. This works fine (fa-toggle-on can be replaced with any random icon):
.home i.fa.fa-toggle-on {
content:url(\http://www.url.com/image1.png);
margin-top: 10px;
}
However, when hovering this image I need to show a different PNG (different color). Let's say "image2.png". I've been puzzling with this for an hour or so and can't seem to fix it. Commands like ".home i.fa.fa-toggle-on a:hover" don't seem to do the trick. Any ideas? Everything will be highly appreciated!
The CSS for the "normal" Social Media icons with Font Awesome is as follows:
/**
* SOCIAL ICONS
*/
#social-icons {
padding: 0;
margin: 0;
}
#social-icons li {
display: inline;
float: left;
margin-right: 1px;
line-height: 32px;
}
#social-icons li a {
display: inline-block;
width: 40px;
height: 40px;
text-align: center;
margin: 20px 0 0 0;
-webkit-transition: all 0.25s ease;
-moz-transition: all 0.25s ease;
-o-transition: all 0.25s ease;
transition: all 0.25s ease;
}
#social-icons li a:hover {
height: 80px;
margin-top: 0;
background: #fff;
}
#social-icons li a i:before {
position: relative;
top: 5px;
font-size: 18px;
color: #fff;
-webkit-transition: all 0.25s ease;
-moz-transition: all 0.25s ease;
-o-transition: all 0.25s ease;
transition: all 0.25s ease;
}
#social-icons li a:hover i:before { top: 25px; }
Based on this line in the CSS
#social-icons li a:hover i:before
You need
#social-icons li a:hover i.fa.fa-toggle-on {
content:url(\http://www.url.com/image2.png);
}
I'm trying to implement a menu nav bar that on hover highlights the menu item with an underline animation from LEFT to RIGHT.
Currently I have the underline animating from the center of the menu item to the outside.
I have tried searchng for a solution to this but can't figure out what I'm doing wrong.
Here is a link to the project on codepen http://codepen.io/anon/pen/JowgqP
HTML
<menu>
<p><strong>Home</strong>
<strong>About</strong>
<strong>Portfolio</strong>
<strong>Contact</strong> <strong>
<p class="note">This is a recreation of the link hover effect from factmag.com</small>
</menu>
CSS (SCSS)
#import url(http://fonts.googleapis.com/css?family=Noto+Serif:400,700,400italic);
$link-color: #E71818;
$text-color: black;
$article-font: Noto serif, serif;
menu {
color: $text-color;
font-family: $article-font;
max-width: 30em;
}
p {
font-size: 18px;
line-height: 1.5;
}
menu a {
#extend %fancy-link;
}
.note {
display: inline-block;
border-top: 1px solid $link-color;
color: #777;
font-size: .8em;
font-style: italic;
margin-top: 2em;
padding-top: 1em;
}
%fancy-link {
color: $link-color;
position: relative;
text-decoration: none;
transition: all 0.15s ease-out;
&:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0px;
left: 0;
background: #f00;
visibility: hidden;
transform: scaleX(0);
transition: all 0.3s ease-in-out 0s;
}
&:hover {
transition: all 0.15s ease-out;
&:before {
visibility: visible;
transform: scaleX(1);
}
}
}
The default transformation point is center center...or rather 50% 50% for ease of reference. (For 2 dimensions...we'll leave out z offsets for now.)
You would have to amend this so that the origin is now center left
&:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0px;
left: 0;
background: #f00;
visibility: hidden;
transform: scaleX(0);
transform-origin: center left; /* here */
transition: all 0.3s ease-in-out 0s;
}
Codepen Demo
Transform-Origin # MDN