Conflicting Hover Pseudo Classes - css

I have a situation where I am modifying an element using a hover pseudo class both when its parent is hovered over and when it is hover over. Unfortunately, they have a conflicting property (both trying to define the property transform), which is why -- I assume -- the scaling is not working when the button is hovered over but the cursor change is. Is there a work around using just CSS?
body {
overflow: hidden;
}
#action-panel {
align-items: center;
box-sizing: border-box;
display: flex;
flex-direction: column;
justify-content: center;
padding: 20px 20px 20px 20px;
position: absolute;
right: 0;
transform: translateY(-50%);
top: 50%;
}
#action-panel:hover .action-button {
opacity: 1;
transform: translateX(0);
}
.action-button {
background-color: lightblue;
border-radius: 25px;
height: 50px;
margin-bottom: 20px;
opacity: 0;
transition: opacity 200ms ease-in-out, transform 200ms ease-in-out;
transform: translateX(calc(100% + 20px));
width: 50px;
}
.action-button:hover {
cursor: pointer;
transform: translateX(0) scale(1.2);
}
.action-button span {
font-size: 30px;
left: 50%;
position: relative;
transform: translate(-50%, -50%);
top: 50%;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div id="action-panel">
<div class="action-button"><span class="material-icons">3d_rotation</span></div>
<div class="action-button"><span class="material-icons">compare_arrows</span></div>
<div class="action-button"></div>
</div>
Note:
If you cannot tell from the code, you need to move your cursor to the middle of the right edge to see the effects I am describing.

Increased the specificity of the following style by adding #action-panel before it. In your code the hover styles of parent were overriding the hover styles of child.
#action-panel .action-button:hover {
cursor: pointer;
transform: translateX(0) scale(1.2);
}
body {
overflow: hidden;
}
#action-panel {
align-items: center;
box-sizing: border-box;
display: flex;
flex-direction: column;
justify-content: center;
padding: 20px 20px 20px 20px;
position: absolute;
right: 0;
transform: translateY(-50%);
top: 50%;
}
#action-panel:hover .action-button {
opacity: 1;
transform: translateX(0);
}
.action-button {
background-color: lightblue;
border-radius: 25px;
height: 50px;
margin-bottom: 20px;
opacity: 0;
transition: opacity 200ms ease-in-out, transform 200ms ease-in-out;
transform: translateX(calc(100% + 20px));
width: 50px;
}
#action-panel .action-button:hover {
cursor: pointer;
transform: translateX(0) scale(1.2);
}
.action-button span {
font-size: 30px;
left: 50%;
position: relative;
transform: translate(-50%, -50%);
top: 50%;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div id="action-panel">
<div class="action-button"><span class="material-icons">3d_rotation</span></div>
<div class="action-button"><span class="material-icons">compare_arrows</span></div>
<div class="action-button"></div>
</div>

Related

Center modal with fade in scale up

I'm struggling with centering the modal together with fade in and scale up:
$('#md-trigger').on('click', function(e) {
$('#modal-1').toggleClass("md-show"); //you can list several class names
e.preventDefault();
});
$('#md-close').on('click', function(e) {
$('#modal-1').toggleClass("md-show"); //you can list several class names
e.preventDefault();
});
.md-modal {
width: 100%;
max-width: 550px;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
position: absolute;
z-index: 9999;
visibility: hidden;
padding: 25px;
border: 1px solid rgba(0,0,0,.2);
border-radius: .3rem;
background-color: #fff;
font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
box-shadow: 0 4px 8px 0 rgba(0,0,0,.2),0 6px 20px 0 rgba(0,0,0,.19);
outline: 0;
}
.md-show {
visibility: visible;
}
.md-overlay {
position: fixed;
width: 100%;
height: 100%;
visibility: hidden;
top: 0;
left: 0;
z-index: 9998;
opacity: 0;
background: rgba(40,43,49,.8);
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.md-show ~ .md-overlay {
opacity: 1;
visibility: visible;
}
.md-content {
color: #333;
}
.md-effect-1 {
-webkit-transform: scale(0.7);
-ms-transform: scale(0.7);
transform: scale(0.7);
opacity: 0;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.md-show.md-effect-1 {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="md-trigger">Show</button>
<div class="md-modal md-effect-1" id="modal-1">
<div class="md-content">
<h3>Modal Dialog</h3>
<p>This is a modal window. You can do the following things with it:</p>
<button class="md-close" id="md-close">Close me!</button>
</div>
</div>
<div class="md-overlay"></div>
The absolute positioning approach with transform:translate(-50%,-50%); isn't working for me. It has to be responsive so I can't use the margin-left approach. Do you have an idea why it is simply not displayed in the middle?
Please try this,
Add this style to md-modal-wrapper class. added a md-modal-wrapper div to cover md-modal class
.md-modal-wrapper{
width:100vw;
height:100vh;
display: flex;
justify-content: center;
align-items: center;
}
Remove this style
.md-modal {
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
position: absolute;
}
$('#md-trigger').on('click', function(e) {
$('#modal-1').toggleClass("md-show"); //you can list several class names
e.preventDefault();
});
$('#md-close').on('click', function(e) {
$('#modal-1').toggleClass("md-show"); //you can list several class names
e.preventDefault();
});
.md-modal {
width:100%;
max-width: 550px;
z-index: 9999;
visibility: hidden;
padding: 25px;
border: 1px solid rgba(0,0,0,.2);
border-radius: .3rem;
background-color: #fff;
font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
box-shadow: 0 4px 8px 0 rgba(0,0,0,.2),0 6px 20px 0 rgba(0,0,0,.19);
outline: 0;
}
.md-show {
visibility: visible;
}
.md-overlay {
position: fixed;
width: 100%;
height: 100%;
visibility: hidden;
top: 0;
left: 0;
z-index: 9998;
opacity: 0;
background: rgba(40,43,49,.8);
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.md-show ~ .md-overlay {
opacity: 1;
visibility: visible;
}
.md-content {
color: #333;
}
.md-effect-1 {
-webkit-transform: scale(0.7);
-ms-transform: scale(0.7);
transform: scale(0.7);
opacity: 0;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.md-show.md-effect-1 {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
opacity: 1;
}
.md-modal-wrapper{
width:100vw;
height:100vh;
display: flex;
justify-content: center;
align-items: center;
}
body{
margin:0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<button id="md-trigger">Show</button>
<div class="md-modal-wrapper">
<div class="md-modal md-effect-1" id="modal-1">
<div class="md-content">
<h3>Modal Dialog</h3>
<p>This is a modal window. You can do the following things with it:</p>
<button class="md-close" id="md-close">Close me!</button>
</div>
</div>
<div class="md-overlay"></div>
</div>
</body>
scale(1) was overriding the other transform property, translate(-50%,-50%).
It can be easily fixed by combining them both: transform: translate(-50%,-50%) scale(1).
$('#md-trigger').on('click', function(e) {
$('#modal-1').toggleClass("md-show"); //you can list several class names
e.preventDefault();
});
$('#md-close').on('click', function(e) {
$('#modal-1').toggleClass("md-show"); //you can list several class names
e.preventDefault();
});
.md-modal {
width: 100%;
max-width: 550px;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
position: absolute;
z-index: 9999;
visibility: hidden;
padding: 25px;
border: 1px solid rgba(0,0,0,.2);
border-radius: .3rem;
background-color: #fff;
font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
box-shadow: 0 4px 8px 0 rgba(0,0,0,.2),0 6px 20px 0 rgba(0,0,0,.19);
outline: 0;
}
.md-show {
visibility: visible;
}
.md-overlay {
position: fixed;
width: 100%;
height: 100%;
visibility: hidden;
top: 0;
left: 0;
z-index: 9998;
opacity: 0;
background: rgba(40,43,49,.8);
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.md-show ~ .md-overlay {
opacity: 1;
visibility: visible;
}
.md-content {
color: #333;
}
.md-effect-1 {
-webkit-transform: scale(0.7);
-ms-transform: scale(0.7);
transform: scale(0.7);
opacity: 0;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.md-show.md-effect-1 {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: translate(-50%,-50%) scale(1);
opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="md-trigger">Show</button>
<div class="md-modal md-effect-1" id="modal-1">
<div class="md-content">
<h3>Modal Dialog</h3>
<p>This is a modal window. You can do the following things with it:</p>
<button class="md-close" id="md-close">Close me!</button>
</div>
</div>
<div class="md-overlay"></div>
How about using flex?
Remove position: absolute; and transform: translate(-50%,-50%); from md-modal
and cover the modal with flex div
.md-container {
display:flex;
justify-content:center;
align-items:center
}
<div class="md-container">
<div class="md-modal">
~~
</div>
</div>
I don't know how to use snippet so I'm attaching a codePen link 😂
https://codepen.io/seongmin0801/pen/MWyrYvm
Make transform: translate(-50%,-50%) !important;. There is .md-show.md-effect-1 { transform: scale(1); } that overrides it that's why you should use important

how to create hover animation on a div

I wanted to create a div which has a background image and a transparent background color over it with some text. When hover, the transparent background color should slide out towards the bottom of the div as shown in the image:
https://i.ibb.co/pJFPvFB/Screenshot-2019-03-26-Zeplin-Project.png
Left block is default. Right block is hover state.
I modified this snippet: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_image_overlay_fade
I modified the provided style to:
<style>
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
}
.container .overlay {
opacity: 0.75;
}
.container:hover .overlay {
opacity: 0;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
</style>
Edited:
My Problem
I tried to achieve a simple slideout animation on my as shown in the image I provided. See this: https://i.ibb.co/pJFPvFB/Screenshot-2019-03-26-Zeplin-Project.png
I have tried something like this - https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_image_overlay_fade
I edited the css they provided to the css I provided above.
Please see the image I provided. I wanted to achieve that.
Try this.
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
transition: .5s ease;
background-color: #008CBA;
}
.container:hover .overlay {
transition: .5s ease;
height: 0;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
<div class="container">
<img src="https://i.ibb.co/pJFPvFB/Screenshot-2019-03-26-Zeplin-Project.png" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
Hope this code may help you.
Hi hope this is what you are looking for
Try this fiddle
.container:hover .overlay {
animation-name: slideDown;
-webkit-animation-name: slideDown;
animation-duration: 1s;
-webkit-animation-duration: 1s;
animation-timing-function: ease;
-webkit-animation-timing-function: ease;
opacity: 1 !important;
}
hope this is what you are looking
.box {
width: 200px; height: 100px;
background-size: 100% 200%;
background-image: linear-gradient(to bottom, red 50%, black 50%);
-webkit-transition: background-position 1s;
-moz-transition: background-position 1s;
transition: background-position 1s;}
http://jsfiddle.net/jxgrtmvy

CSS on hover out text disappears instead of sliding out like image

Can someone explain why does the image slide back nicely and the text disappears right away when you hover out?
.wrapper {
position: relative;
overflow: hidden;
width: 100px;
height: 100px;
border: 1px solid black;
}
#image {
position: absolute;
left: 0;
width: 100px;
height: 100px;
background: blue;
transition: 1s;
}
.wrapper:hover #image {
transition: 1s;
left: -100px;
}
.wrapper:hover .text {
transition: 1s;
left: 50%;
}
.text {
white-space: nowrap;
//color: black;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 150%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="wrapper">
<img id="image" src="http://lorempixel.com/output/cats-q-c-100-100-4.jpg" />
<div class="text">text</div>
</div>
So what I want is that the text also slides out nicely on hover out and not just disappear.
You also need to add the transition property to the .text:
.wrapper {
position: relative;
overflow: hidden;
width: 100px;
height: 100px;
border: 1px solid black;
}
#image {
position: absolute;
left: 0;
width: 100px;
height: 100px;
background: blue;
transition: 1s;
}
.wrapper:hover #image {
transition: 1s;
left: -100px;
}
.wrapper:hover .text {
transition: 1s;
left: 50%;
}
.text {
white-space: nowrap;
//color: black;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 150%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transition: 1s;
}
<div class="wrapper">
<img id="image" src="http://lorempixel.com/output/cats-q-c-100-100-4.jpg" alt="">
<div class="text">text</div>
</div>

Keyframe animation works on chrome but partly broken on safari

I've been trying to learn css animations by making a little personal site.
Joseph.how
I wanted the title to start large and near the page center, move up, then shrink and move to the left. Unfortunately when using safari the title moves to the left but instead of staying vertically centered, rises slightly, then pops back to center after the animation is done.
You can see the intended behavior on chrome (haven't tested with other browsers yet).
EDIT The problem persists with prefixes
(used auto-prefix extension in brackets)
Link to repo: https://github.com/JoeHowarth/joehowarth.me
EDIT 2 The problem is really just with the title-over keyframe, so I isolated that one
.header-container {
width: 100%;
border-bottom: 1px #000 solid;
height: 40vh;
position: relative;
background-color: #000;
color: #eee;
-webkit-animation: banner-up 1s 2s ease-in-out forwards;
animation: banner-up 1s 2s ease-in-out forwards;
font-family: 'Lato';
.title {
font-size: 30px;
position: absolute;
top: 90%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
font-weight: 700;
letter-spacing: .5em;
font-size: 60px;
-webkit-animation: title-over 4s 2s ease-in-out forwards;
animation: title-over 4s 2s ease-in-out forwards;
span {
font-weight: 100;
letter-spacing: .1em;
font-style: italic;
}
}
nav {
width: 40vw;
height: 10%;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
position: absolute;
top: -5vw;
right: 20px;
-webkit-transform: translate(0, -50%);
transform: translate(0, -50%);
-webkit-animation: nav 1s 7s ease-out forwards;
animation: nav 1s 7s ease-out forwards;
-webkit-transition : all 2s ease;
transition: all 2s ease;
div {
width: 15vw;
height: 100%;
margin: 0 2px;
// border: 1px #333 solid;
background: #111;
&:hover {
background: #222;
}
&:active {
background: #2a2a2a;
font-size: 38px;
}
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
font-size: 35px;
p {
text-align: center;
color: #eee;
display: block;
font-weight: 100;
}
}
}
}
// move title to left, make smaller
#keyframes title-over {
30% {
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
45% {
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
letter-spacing: .5em;
font-size: 60px;
}
65% {
letter-spacing: .5em;
}
100% {
top: 50%;
left: 10px;
-webkit-transform: translate(0%, -50%);
transform: translate(0%, -50%);
letter-spacing: .1em;
font-size: 40px;
}
}
#-webkit-keyframes title-over {
30% {
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
45% {
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
letter-spacing: .5em;
font-size: 60px;
}
65% {
letter-spacing: .5em;
}
100% {
top: 50%;
left: 10px;
-webkit-transform: translate(0%, -50%);
transform: translate(0%, -50%);
letter-spacing: .1em;
font-size: 40px;
}
}
HTML
<div class="header-container">
<header class="title">
JOSEPH.HOW<span>ARTH</span>
</header>
<!-- nav defaults to display:none, comes in w/ animation-->
<nav>
<div id="about-nav" href="#"><p>About Me</p></div>
<div id="proj-nav" href="#"><p>Projects</p></div>
<div id="resume-nav" href="#"><p>Resume</p></div>
</nav>
Use #-webkit-keyframes for safari
#keyframes banner-up {
50% {
border-bottom: 1px #111 solid;
}
100% {
height: 80px;
border-bottom: 3px #111 solid;
}
}
/* Safari */
#-webkit-keyframes banner-up {
50% {
border-bottom: 1px #111 solid;
}
100% {
height: 80px;
border-bottom: 3px #111 solid;
}
}

Disable transform of child in CSS

I want to disable transform in my child div. Here is fiddle. Is it possible to disable scale for class .image-text ?
.photo:hover{
transform: scale(1.4);
-moz-transform: scale(1.4);
-webkit-transform: scale(1.4);
-o-transform: scale(1.4);
-ms-transform: scale(1.4);
}
.photo:hover >*{
transform: none;
}
make a new child element and call your image on it.
here you can see http://jsfiddle.net/rajjuneja49/s3hWj/879/
May be you were looking for this....
You can see these example.
.element{
width: 400px;
height: 550px;
}
img {
max-width: 100%;
height: auto;
vertical-align: middle;
border: 0;
}
.main-photo-area {
position:relative;
display: block;
overflow: hidden;
}
.main-photo-area img.photo{
transition: all 0.3s ease;
width: 100%;
}
.main-photo-area:hover img.photo{
transform: scale(1.4);
}
.image-text {
background: rgba(34, 90, 159, 0.6);
bottom: 0;
color: white;
font-size: 1em;
left: 0;
opacity: 0;
overflow: hidden;
padding: 3em 3em 4.25em 3em;
position: absolute;
text-align: center;
top: 0;
right: 0;
-webkit-transition: 0.6s;
transition: 0.6s;
}
.image-text:hover {
opacity: 1;
}
<div class="element">
<div class="main-photo-area">
<img class="photo" src="http://heavytable.com/wp-content/uploads/2012/11/wine-glasses-650-325.jpg"/>
<a class="over" href="/szablon/?id=single">
<div class="image-text">
<h2>Titel</h2>
<p>Desc</p>
<span class="icon">Look</span>
</div>
</a>
</div>
</div>

Resources