Element shaking on Hover/Class Toggle only in Safari - html

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

Related

Make a paragraph appear inside a picture on picture hover

basically all i want to do is: Have a picture and when someone hovers over it i want some text to appear in its position(in the middle to be exact). What I have done so far is make the picture disappear on hover but i cannot get the text to be appeared..
Html:
<div class="container">
<img id="atp "class="atp" src="atp.jpg">
<div class="center">Some text</div>
</div>
Css:
atp{
display:block;
margin-left:auto;
margin-right:auto;
width:27%;
height:50%;}
container{
position: relative;
text-align: center;
}
.center{
position: absolute;
top:50%;
left:50%;
opacity: 0;
}
So basically, what i seek to be done is .atp:hover{opacity:0;} and what I also want is on atp's hover the .center{opacity:1;] So is there a way to put the opacity of center's to 1 when I am in the atp:hover{} code block?
Hope everything looks fine, thanks in advance!
Here is the code. Hope it will help you. if any changes please let me know.
/********* Simple or original overlay *******/
/* Main container */
.overlay-image {
position: relative;
width: 100%;
}
/* Original image */
.overlay-image .image {
display: block;
width: 100%;
height: auto;
}
/* Original text overlay */
.overlay-image .text {
color: #fff;
font-size: 30px;
line-height: 1.5em;
text-shadow: 2px 2px 2px #000;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
}
/********* Overlay on hover *******/
/* New overlay on hover */
.overlay-image .hover {
position: absolute;
top: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
}
/* New overlay appearance on hover */
.overlay-image:hover .hover {
opacity: 1;
}
/********* Background and text only overlay on hover *******/
.overlay-image .normal {
transition: .5s ease;
}
.overlay-image:hover .normal {
opacity: 0;
}
.overlay-image .hover {
background-color: rgba(0,0,0,0.5);
}
<div class="overlay-image">
<a href="LINK_URL">
<div class="normal">
<div class="text">Image + text ORIGINAL</div>
</div>
<div class="hover">
<img class="image" src="https://dummyimage.com/200x150/00ccff/fff.png" alt="Alt text hover" />
</div>
</a>
</div>
#atp {
position: relative;
display: block;
margin-left: auto;
margin-right: auto;
width: 27%;
height: 50%;
z-index: 50;
}
.container {
position: relative;
text-align: center;
}
.center {
position: absolute;
top: 50%;
left: 50%;
z-index: 30;
}
#atp:hover {
opacity: 0;
}
try this, using z-index. It worked with me :)

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>

CSS pseudo :target element animation not working on slider

I am trying to build a simple css slider that shows specific text when in the :target state. The text actually appears fine but what's happening is it's just appearing instead of sliding in. I have left:0 set on the parent and the idea being that when the slide id is selected the parent should move to left: -100%/-200%/-300% depending on the slide targeted. Hope this makes sense, markup is below.
Appreciate any advice where I have gone wrong.
.slider__wrapper {
width: 300px;
margin: 50px auto 0 auto;
}
.slider {
position: relative;
overflow: hidden;
}
.slider__inner {
position: relative;
width: 300%;
left: 0;
transition: all .6s;
}
.slider__slides {
float: left;
width: 33.333%;
font-size: 25px;
}
.slider__toggle {
display: inline-block;
margin-right: 10px;
margin-top: 20px;
font-size: 16px;
}
#slide--1 {
background: red;
}
#slide--2 {
background: yellow;
}
#slide--3 {
background: green;
}
#slide--1:target~.slider__inner {
left: 0;
transition: all .6s;
}
#slide--2:target~.slider__inner {
left: -100%;
transition: all .6s;
}
#slide--3:target~.slider__inner {
left: -200%;
transition: all .6s;
}
<div class="slider__wrapper">
<div class="slider">
<div class="slider__inner">
<div class="slider__slides" id="slide--1">
slide 1
</div>
<div class="slider__slides" id="slide--2">
slide 2
</div>
<div class="slider__slides" id="slide--3">
slide 3
</div>
</div>
</div>
<div class="slider__toggle">
01
02
03
</div>
</div>

Css Animation "fullscreen" mode

I have an element on screen that i would like to go full screen. I have done this, by using the following css
.fullscreen {
z-index: 2000;
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
padding: 15px;
background-color: white;
}
Now i would like to have a nice animation when my element is clicked, so it looks a bit sexy as it maximizes and the same when it minimizes.
Can this be done??
I have tried transition: top .15s linear; but that doesnt seem to work
NOTE
I cannot have the element start with position:fixed using css, unless i had to use javascript to toggle it, as this is a normal html element, so i do not always want it fixed.
here is the fiddle where i got the css from to go fullscreen, so you can see what i mean. http://jsfiddle.net/a7nzy6w6/1/
The position property can't be animated. If you start with position: fixed, it's no problem.
Fiddle: http://jsfiddle.net/a7nzy6w6/299/
#myDiv.fullscreen {
z-index: 9999;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
#myDiv {
position: fixed;
width: 500px;
height: 400px;
top: 20px;
left: 20px;
transition: all .15s linear;
background: #cc0000;
}
Note that using JavaScript you could find the position on the page and set it to fixed at the position as to not have to start with position: fixed, but that's outside the scope of this question.
Following up on comments to include a fade transition with CSS transition and jQuery for class toggles:
CSS:
#myDiv.fullscreen {
z-index: 9999;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#myDiv.fade {
opacity: 0;
}
#myDiv {
width: 500px;
height: 400px;
top: 20px;
left: 20px;
background: #cc0000;
transition: opacity .15s linear;
}
JS:
$('button').click(function(e) {
var $div = $('#myDiv');
$div.toggleClass('fade');
setTimeout(function(){
$div.toggleClass('fade fullscreen');
}, 150);
});
Fiddle: http://jsfiddle.net/a7nzy6w6/308/
You need to use transition
$('button').click(function(e){
$('#myDiv').toggleClass('fullscreen');
});
#myDiv{
background:#c99;
top: 0;
left: 0;
position: fixed;
width:500px;
height:400px;
transition: all 1s ease;
}
#myDiv.fullscreen{
z-index: 9999;
width: 100%;
height: 100%;
transition: all 1s ease;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="col-lg-12">
<div id="myDiv">
my div
<button>Full Screen</button>
</div>
</div>
</div>
Try this
<div class="row">
<div class="col-lg-12">
<div id="myDiv">
my div
<button>Full Screen</button>
</div>
</div>
</div>
#myDiv.fullscreen{
z-index: 9999;
min-width: 100%;
min-height: 100%;
position: fixed;
top: 0;
left: 0;
}
#myDiv{
background:#cc0000;
min-width:500px;
max-width: 500px;
min-height:400px;
transition: all 500ms;
}
live demo - http://jsfiddle.net/a7nzy6w6/306/

How to place an object next to another, and horizontally center and right-align it?

What is happening
What I want to happen
I want the icon-x-circle to be horizontally centered and on the same line as "Rename" but be right-aligned (probably 30px away from the right end of the header). If someone could let me know how to do that it would be greatly appreciated!
Something to note:
The icon-x-circle itself is not centered. For some reason Fontastic icons seem to add extra space at the bottom. So this is another reason why I'm struggling to horizontally center icon-x-circle.
My Code
HTML
<div id="popup-rename" class="overlay">
<div class="popup">
<header>
<h1>Rename</h1>
<a class="close icon-x-circle" href="#"></a>
</header>
<div class="content">
<div class="student-name student-rect">
<h1>Student Name</h1>
</div>
<div class="save-button center-children">
<a class="save icon-check-circle" href="#"></a>
</div>
</div>
</div>
</div>
CSS
header{
background-color: #F5F5F5;
padding-top: 15px;
padding-bottom: 15px;
text-align: center;
text-transform: uppercase;
}
header h1 {
margin-top: 10px;
margin-bottom: 10px;
font-weight: 300; /*100, 200*/
}
.icon-x-circle{
color: #E1E1E1;
}
.overlay {
position: absolute;
z-index: 2;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
transition: opacity 500ms;
visibility: hidden;
opacity: 0;
}
.overlay:target {
visibility: visible;
opacity: 1;
}
.popup {
margin: 70px auto;
background: white;
width: 50%;
position: relative;
transition: all 200ms ease-in-out;
}
.popup header{
padding: 20px;
}
.close, .save{
transition: all 200ms;
}
.icon-x-circle:hover {
color: #B6B6B6;
}
JSFiddle
One method for aligning elements is to use position: absolute;:
.icon-x-circle {
position: absolute;
right: 0px;
width: 300px;
border: 3px solid #73AD21;
padding: 10px;
}
You can use absolute positioning and put the button wherever you want.
first, make header a relative container
header{
position: relative;
}
Then you can make the button absolute
header a{
position: absolute;
right: 30px;
top: 10px
}
You can mess with right and top to move the button wherever.
https://jsfiddle.net/49abesy2/1/