CSS Hover Not Working on Transformed Elements - html

I'm trying to have a skewed element change size on hover but for whatever reason, the elements only change whenever the mouse is about 200px below where it should be. I'm guessing this is either happening because of the way I transformed the elements or because of the way I positioned them on the page.
Code below
.layers {
margin: 150px 150px;
height: 500px !important;
width: 500px !important;
-webkit-perspective: 1000px; /* Chrome, Safari, Opera */
perspective: 1000px;
}
.layer img {
height: 500px;
width: 500px;
-webkit-box-shadow: 0px 0px 25px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 25px 0px rgba(0,0,0,0.75);
box-shadow: 0px 0px 25px 0px rgba(0,0,0,0.75);
background: rgba(255, 255, 255, 0.65);
-webkit-transform: rotateX(75deg); /* Chrome, Safari, Opera */
transform: rotateX(75deg);
display: inline;
transition: all .5s;
-webkit-transition: all .5s;
}
.layer:hover img {
-webkit-box-shadow: 0px 0px 65px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 65px 0px rgba(0,0,0,0.75);
box-shadow: 0px 0px 65px 0px rgba(0,0,0,0.75);
height: 510px;
width: 510px;
transition: all .5s;
-webkit-transition: all .5s;
}
.layer1 {
display: inline-block;
position: relative;
z-index: 3;
}
.layer2 {
display: inline-block;
position: relative;
z-index: 2;
bottom: 450px;
}
.layer3 {
display: inline-block;
z-index: 1;
position: relative;
bottom: 900px;
}
<div class="layers">
<div class="layer1 layer">
<img src="http://placehold.it/500x500" alt="">
</div><!-- layer1 -->
<div class="layer2 layer">
<img src="http://placehold.it/500x500" alt="">
</div><!-- layer2 -->
<div class="layer3 layer">
<img src="http://placehold.it/500x500" alt="">
</div><!-- layer3 -->
</div><!-- layers -->

Try putting the transform: rotateX(75deg); on .layer instead of its child image, like so:
.layers {
margin: 150px 150px;
height: 500px !important;
width: 500px !important;
-webkit-perspective: 1000px; /* Chrome, Safari, Opera */
perspective: 1000px;
}
.layer {
-webkit-transform: rotateX(75deg); /* Chrome, Safari, Opera */
transform: rotateX(75deg);
}
.layer img {
height: 500px;
width: 500px;
-webkit-box-shadow: 0px 0px 25px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 25px 0px rgba(0,0,0,0.75);
box-shadow: 0px 0px 25px 0px rgba(0,0,0,0.75);
background: rgba(255, 255, 255, 0.65);
display: inline;
transition: all .5s;
-webkit-transition: all .5s;
}
.layer:hover img {
-webkit-box-shadow: 0px 0px 65px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 65px 0px rgba(0,0,0,0.75);
box-shadow: 0px 0px 65px 0px rgba(0,0,0,0.75);
height: 510px;
width: 510px;
transition: all .5s;
-webkit-transition: all .5s;
}
.layer1 {
display: inline-block;
position: relative;
z-index: 3;
}
.layer2 {
display: inline-block;
position: relative;
z-index: 2;
bottom: 450px;
}
.layer3 {
display: inline-block;
z-index: 1;
position: relative;
bottom: 900px;
}
<div class="layers">
<div class="layer1 layer">
<img src="http://placehold.it/500x500" alt="">
</div><!-- layer1 -->
<div class="layer2 layer">
<img src="http://placehold.it/500x500" alt="">
</div><!-- layer2 -->
<div class="layer3 layer">
<img src="http://placehold.it/500x500" alt="">
</div><!-- layer3 -->
</div><!-- layers -->

Try replacing perspective: 1000px with transform: perspective(1000px)
.layers {
margin: 150px 150px;
height: 500px !important;
width: 500px !important;
//-webkit-perspective: 1000px; /* Chrome, Safari, Opera */
transform: perspective(1000px);
}
.layer img {
height: 500px;
width: 500px;
-webkit-box-shadow: 0px 0px 25px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 25px 0px rgba(0,0,0,0.75);
box-shadow: 0px 0px 25px 0px rgba(0,0,0,0.75);
background: rgba(255, 255, 255, 0.65);
-webkit-transform: rotateX(75deg); /* Chrome, Safari, Opera */
transform: rotateX(75deg);
display: inline;
transition: all .5s;
-webkit-transition: all .5s;
}
.layer:hover img {
-webkit-box-shadow: 0px 0px 65px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 65px 0px rgba(0,0,0,0.75);
box-shadow: 0px 0px 65px 0px rgba(0,0,0,0.75);
height: 510px;
width: 510px;
transition: all .5s;
-webkit-transition: all .5s;
}
.layer1 {
display: inline-block;
position: relative;
z-index: 3;
}
.layer2 {
display: inline-block;
position: relative;
z-index: 2;
bottom: 450px;
}
.layer3 {
display: inline-block;
z-index: 1;
position: relative;
bottom: 900px;
}
<div class="layers">
<div class="layer1 layer">
<img src="http://placehold.it/500x500" alt="">
</div><!-- layer1 -->
<div class="layer2 layer">
<img src="http://placehold.it/500x500" alt="">
</div><!-- layer2 -->
<div class="layer3 layer">
<img src="http://placehold.it/500x500" alt="">
</div><!-- layer3 -->
</div><!-- layers -->
Explanation from CSS-Tricks:
[...] the perspective property doesn't affect how the element is
rendered; it simply enables a 3D-space for children elements. This is
the main difference between the transform: perspective() function and
the perspective property. The first gives element depth while the
later creates a 3D-space shared by all its transformed children.

Related

Hover effect with box-shadow only, is it possible in my case?

As you can see below, I have two items with similar effect.
In the first case i use an overlay element in order to achieve the effect as you see it.
What I want is to have the same effect but with shadow not the overlay trick.
What I can't achieve is to make the shadow start 20px from top but have zero oveflow from the bottom as you see it in the first item.
Is it possible with css shadow to achieve the same thing or I have to go with the first option?
.container {
padding: 20px;
}
.item, .desired-item {
max-width: 300px;
height: 300px;
position: relative;
}
.desired-item {
padding-top: 25px;
}
figure {
width: 100%;
padding: 0;
margin: 0;
}
figure img {
width: 100%
}
.item .overlay {
position: absolute;
background-color: #ff6666;
width: 100%;
height: calc(100% - 20px);
visibility: visible;
opacity: 1;
z-index: -1;
right: -20px;
transition: all .25s;
margin-top: 20px;
}
.item figure:hover .overlay {
visibility: visible;
opacity: 0.3;
z-index: 1;
right: 0;
height: calc(100% - 0px);
margin-top: 0;
}
.desired-item figure:hover {
-webkit-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.75);
box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.75);
}
.desired-item figure {
-webkit-box-shadow: 20px 20px 0px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 20px 20px 0px 0px rgba(0,0,0,0.75);
box-shadow: 20px 20px 0px 0px rgba(0,0,0,0.75);
transition: all .5s;
}
<div class="container">
<h2>overlay effect:</h2>
<div class="item">
<figure>
<div class="overlay"></div>
<img src="https://via.placeholder.com/600x600.jpg/09f/fff">
</figure>
</div>
<h2>Shadow effect:</h2>
<div class="desired-item">
<figure>
<div class="overlay"></div>
<img src="https://via.placeholder.com/600x600.jpg/09f/fff">
</figure>
</div>
</div>
Apply the shadow on the image and rely on overflow to hide the non needed part:
figure img {
display:block;
box-shadow: 20px 20px 0px 0px rgba(0, 0, 0, 0.75);
transition: all .5s;
}
figure:hover img {
box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0.75);
}
figure {
display:inline-block;
padding-right:20px;
overflow: hidden;
}
<figure>
<img src="https://via.placeholder.com/150x150.jpg/09f/fff">
</figure>

Display div when container overflow is hidden

I have a divcontaining a lot of elements, so I must use a scroll. The idea is to show a popup on div's hover. But overflow: hidden is not enough to show popup. I tried many ways but failed and I run out of ideas.
This is my code:
https://codepen.io/Danica1986/pen/gVjvva?editors=0110
class Content extends React.Component {
render() {
return (
<div className="footer">
<div className="footer-content">
<div className="scene-list-contnet">
<div className="list-slide-items">
<div className="item-with-scene">
<div className="scene-placeholder">
<img src="https://images.unsplash.com/photo-1490077476659-095159692ab5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" className="scene-img" />
<div className="open-scene-options"><img src="https://cdn2.iconfinder.com/data/icons/minimalist-arrows-set/100/ARROW-expand__up_arrow-512.png"/></div>
<div className="scene-options">
<ul>
<li>Option 1</li>
<li>Option 2</li>
<li>Option 3</li>
<li>Option 4</li>
<li>Option 5</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
);
}
}
React.render(<Content />, document.getElementById('app'));
.footer
width: calc(100% - 64px)
height: 150px
position: fixed
top: 250px
background: #fff
margin-left: 64px
-webkit-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.1)
box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.1)
.scene-list-contnet
width: calc(100% - 92px)
float: right
height: 100px
overflow-y: scroll
.footer
.list-slide-items
margin: 7px 0px
list-style-type: none
display: -webkit-inline-box
display: -ms-inline-flexbox
display: inline-flex
-webkit-box-orient: horizontal
-webkit-box-direction: normal
-ms-flex-direction: row
flex-direction: row
margin-bottom: 0
.item-with-scene
width: 145px
height: 82px
margin-right: 15px
display: inline-block
.scene-placeholder
position: relative
width: 100%
padding-top: 56.25%
.scene-placeholder
img
max-width: 100%
.open-scene-options
position: absolute
width: 21px
top: 5px
right: 5px
background: #fff
z-index: 3
border-radius: 100%
text-align: center
-webkit-transition: all 0.2s linear
transition: all 0.2s linear
cursor: pointer
visibility: hidden
img
-webkit-transform: rotate(180deg)
transform: rotate(180deg)
width: 8px
-webkit-transition-duration: 1s
transition-duration: 1s
-webkit-transition-property: -webkit-transform
transition-property: -webkit-transform
transition-property: transform
transition-property: transform, -webkit-transform
&:hover
img
-webkit-transform: rotate(360deg)
transform: rotate(360deg)
& + .scene-options
visibility: visible
&:hover
.open-scene-options
visibility: visible
.list-slide-items
.scene-placeholder
.scene-img
max-width: 100%
max-height: 100%
width: 100%
position: absolute
top: 0
bottom: 0
left: 0
right: 0
z-index: 1
cursor: pointer
opacity: 0.6
-webkit-transition: all 0.2s linear
transition: all 0.2s linear
&:hover
opacity: 1
.scene-options
width: 141px
height: 165px
position: absolute
z-index: 11
background: #fff
bottom: 90px
left: 63px
background: #fff
border-radius: 18px
-webkit-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.1)
box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.1)
padding: 12px 17px
&:hover
visibility: visible
&:after
content: ""
width: 0px
height: 0px
position: absolute
border-left: 10px solid transparent
border-right: 10px solid transparent
border-top: 10px solid #fff
border-bottom: 10px solid transparent
left: 57px
bottom: -20px
ul
list-style-type: none
margin-bottom: 0
.open-scene-options
&:hover
.scene-options
visibility: visible

How do I position a png over another image and still be able to interact with both?

I am building a portfolio website and I want a mockup on top of a background but when I hover over the mockup I cannot interact with the background. I want them to both scale, but the mockup should scale more than the background, therefore I need a :hover on both of them separately.
I tried fiddling around with the z-index but it did not work out. Here is what it looks like now: https://imgur.com/NPrHdAI
Here is my HTML and CSS:
.try {
display: flex;
justify-content: center;
flex-wrap: wrap;
margin: 80px 0px 60px 10px;
}
.bg {
height: 250px;
margin: 10px;
border-radius: 3px;
-webkit-box-shadow: 0px 5px 10px 0px rgba(214, 214, 214, 0.3);
-moz-box-shadow: 0px 5px 10px 0px rgba(214, 214, 214, 0.3);
box-shadow: 0px 5px 10px 0px rgba(214, 214, 214, 0.3);
transition: all .3s ease-in-out;
}
.mockup {
position: absolute;
height: 300px;
transition: all .3s ease-in-out;
}
.mockup:hover {
transform: scale(1.2);
}
<div class="try">
<div>
<img class="mockup" src="img/mockup.png">
<img class="bg" src="img/bg.jpg">
</div>
<div>
<img class="mockup" src="img/mockup.png">
<img class="bg" src="img/bg.jpg">
</div>
<div>
<img class="mockup" src="img/mockup.png">
<img class="bg" src="img/bg.jpg">
</div>
</div>
I want both elements to be scaling separately, but the mockup blocks the background from scaling on hover.
You could use a wrapper div that triggers the hover, and assign different effects to mockup and bg like this:
.wrapper:hover .mockup {
transform: scale(1.2);
}
.wrapper:hover .bg {
transform: scale(5.0);
}
Full snippet: (You can see they both resize different)
.try {
display: flex;
justify-content: center;
flex-wrap: wrap;
margin: 80px 0px 60px 10px;
}
.bg {
height: 250px;
margin: 10px;
border-radius: 3px;
-webkit-box-shadow: 0px 5px 10px 0px rgba(214,214,214,0.3);
-moz-box-shadow: 0px 5px 10px 0px rgba(214,214,214,0.3);
box-shadow: 0px 5px 10px 0px rgba(214,214,214,0.3);
transition: all .3s ease-in-out;
}
.mockup {
position: absolute;
height: 300px;
transition: all .3s ease-in-out;
}
.wrapper:hover .mockup {
transform: scale(1.2);
}
.wrapper:hover .bg {
transform: scale(5.0);
}
<div class="wrapper">
<img class="mockup" src="img/mockup.png">
<img class="bg" src="img/bg.jpg">
</div>

How to create a card with image as background in CSS diagonally sliced

I am trying to create a Card in HTML/CSS, that looks like:
BUT, what I want exactly is that the background, instead of being just grey like it is, is an image instead.
Here is what I've tried: JsFiddle
HTML:
<div class="card">
<img src="https://www.washingtonpost.com/resizer/9YWv-qOa9uW7CQZ9UGiW23eTZzU=/1484x0/arc-anglerfish-washpost-prod-washpost.s3.amazonaws.com/public/BTCNJJN2Y43KPHPXPQWPASXRKM.jpg" alt="Avatar" class='image'>
<div class="container">
<h3>John Doe</h3>
<p>Architect & Engineer</p>
</div>
</div>
CSS:
.card {
border: 1px solid #dadada;
box-shadow: 4px 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.2s;
width: 50%;
}
.card h3 {
padding: 2px;
margin: 8px 0;
}
.image {
width:100%;
clip-path: polygon(0 0, 100% 0, 100% 42%, 0 23%);
}
As you can see it works, but the problem is that there's space in between the image and the 'John Doe'.
I would like to know how to remove the space between the image and the John Doe.
Thanks
Here is a simple solution with css transform.
.wrapper {
position: relative;
width: 280px;
height: 350px;
background: url('https://upload.wikimedia.org/wikipedia/commons/e/e1/FullMoon2010.jpg') 0 0 no-repeat;
background-size: cover;
overflow: hidden;
}
.box {
position: absolute;
bottom: 0;
width: 100%;
height: 50%;
background: #cdcdcd;
}
.content {
position: absolute;
z-index: 10;
padding: 15px;
box-sizing: border-box;
}
.folder {
position: absolute;
top: -20px;
left: -10px;
width: 120%;
height: 60px;
background: #cdcdcd;
transform: rotate(8deg);
}
<div class="wrapper">
<div class="box">
<div class="content">Here is my content.</div>
<div class="folder"></div>
</div>
</div>
You can add the following to your css:
.container {
position: absolute;
top: 150px;
}
You will see that your card's height is influenced. You can the just give your card a height that you desire, like this:
.card {
height: 300px //this is your prefered height
}
.card {
border: 1px solid #dadada;
box-shadow: 4px 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.2s;
width: 50%;
height:200px;
position:relative;
}
.card h3 {
padding: 2px;
margin: 8px 0;
/* line-height: 20px !important;
font-size: 18px !important;
font-weight: 500 !important; */
}
.card:hover {
box-shadow: 8px 8px 16px 0 rgba(0, 0, 0, 0.2);
}
.card .container {
padding: 2px 14px;
position: absolute;
top: 45%;
}
.card p {
margin: 14px 0;
}
.card img {
position:absolute
}
//that's all..
Rely on background and you will have better support and less code:
.card {
border: 1px solid #dadada;
box-shadow: 4px 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.2s;
padding:100px 10px 5px;
width: 50%;
background:
linear-gradient(to bottom left,transparent 49.5%,#fff 50%) 0 50px/100% 100px,
linear-gradient(#fff,#fff) bottom/100% calc(100% - 150px),
url(https://www.washingtonpost.com/resizer/9YWv-qOa9uW7CQZ9UGiW23eTZzU=/1484x0/arc-anglerfish-washpost-prod-washpost.s3.amazonaws.com/public/BTCNJJN2Y43KPHPXPQWPASXRKM.jpg) top/100% auto no-repeat;
background-repeat:no-repeat;
}
.card h3 {
padding: 2px;
margin: 8px 0;
}
<div class="card">
<h3>John Doe</h3>
<p>Architect & Engineer</p>
</div>

iFrame only allows scroll downward in Safari 9.0.3 OSX

For some strange reason Safari only allows me to scroll downward with the two finger gesture inside an iFrame. However, if I use the scroll bar I can scroll up and down. WTF?!
This is the html and css for the iframe and its wrapper.
#iframe-wrapper {
-webkit-overflow-scrolling: touch !important;
overflow-y: scroll !important;
height: 312px;
}
#iframe-wrapper>iframe {
border-radius: 4px;
background-color: white;
border: none;
-webkit-box-shadow: inset 0px 0px 15px -5px rgba(0, 0, 0, 0.75);
-moz-box-shadow: inset 0px 0px 15px -5px rgba(0, 0, 0, 0.75);
box-shadow: inset 0px 0px 15px -5px rgba(0, 0, 0, 0.75);
}
.fixed-window {
position: fixed;
height: 100%;
width: 100%;
overflow-y: auto;
overflow-x: hidden;
left: 0;
right: 0;
}
.popup {
margin: -100px auto 100px;
position: absolute;
border: 0px solid white;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
box-shadow: 0px 0px 18px rgba(0, 0, 0, 0.4);
max-width: 720px;
width: 100%;
top: 50%;
left: 50%;
transform: translateX(-50%);
-ms-transform: translateX(-50%);
-webkit-transform: translateX(-50%);
}
#container {
padding: 0 40px;
}
<div class="fixed-window">
<div class="popup">
<div id="container">
<div class="on-submit-hide">
<div id="iframe-wrapper">
<iframe height="100%" width="100%" src="http://www.lipsum.com/feed/html">
</iframe>
</div>
</div>
</div>
</div>
</div>
Why is this happening, is it a Safari bug?? Does anyone else have this problem? In the rest of the browsers it works fine, including ie9 :weary:.