Getting rid of funny hover behaviour when changing div width - css

I have some videos with a background overlay and text over them and my goal is having this overlay and the text disappearing on hover. I've managed to achieve this but if I change the width of the div containing the text (class .project-content on code below), I get a funny transparency behaviour on hover.
Would anyone be able to help by letting me know how I can modify the width of said div while keeping the intended behavior on hover? Thank you very much!
Here's my code:
HTML
<div class="works-content">
<div class="video-background">
<a href="#" target="_bank">
<div class="video">
<video loop="" muted="muted" poster="" playsinline=""><source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4"></video>
</div>
</a>
<div class="project-content">
<p class="project-title">TITLE</p>
<p class="project-description">PROJECT DESCRIPTION</p>
</div>
</div>
</div>
CSS
.works-content {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 60px 30px;
padding: 0px 30px 100px 30px;
}
.video-background {
background: $black;
position:relative;
transition: 0.5s ease;
width: 100%;
}
.video-background:hover {
transform: scale(1.04);
transition: 0.5s ease;
background: white;
}
.video-background:hover .project-title a, .project-description a {
display: none;
}
.video {
transition: 0.5s ease;
opacity: 0.2;
}
.video:hover {
transition: 0.5s ease;
opacity: 1;
}
video {
width: 100%;
}
.project-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.project-content a {
color: white;
}
.project-title a {
font-size: 36px;
letter-spacing: 2px;
font-weight: bold;
border-bottom: 10px solid $yellow;
}
.project-title a:hover {
text-decoration: none;
}
.project-description {
font-size: 36px;
padding-top: 8px;
letter-spacing: 1px;
}
JS
jQuery('.video-background').mouseover(function(){
$('video', this).get(0).play();
}).mouseout(function(){
$('video', this).get(0).pause();
});

Related

Hover Effect Ideas

I'm using a development named "Hover Effect Ideas" (Warm Oscar) available on internet, the purpose of which is to add an effect to hovering an image :
https://codepen.io/anon/pen/zapzzE
*,
*:after,
*:before {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.clearfix:before,
.clearfix:after {
content: "";
display: table;
}
.clearfix:after {
clear: both;
}
body {
background: #f6f9fa;
color: #536d76;
font-weight: 400;
font-size: 1em;
font-family: "Raleway", Arial, sans-serif;
}
a {
color: #4f7f90;
text-decoration: none;
outline: none;
}
a:hover,
a:focus {
color: #39545e;
}
.grid {
overflow: hidden;
margin: 0;
padding: 3em 0 0 0;
width: 100%;
list-style: none;
text-align: center;
}
/* Common style */
.grid figure {
position: relative;
z-index: 1;
display: inline-block;
overflow: hidden;
margin: -0.135em;
width: 33.333%;
height: 400px;
background: #3085a3;
text-align: center;
cursor: pointer;
}
.grid figure img {
position: relative;
display: block;
min-height: 100%;
opacity: 0.8;
}
.grid figure figcaption {
padding: 2em;
color: #fff;
text-transform: uppercase;
font-size: 1.25em;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.grid figure figcaption::before,
.grid figure figcaption::after {
pointer-events: none;
}
.grid figure figcaption,
.grid figure a {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* Anchor will cover the whole item by default */
/* For some effects it will show as a button */
.grid figure a {
z-index: 1000;
text-indent: 200%;
white-space: nowrap;
font-size: 0;
opacity: 0;
}
.grid figure h2 {
font-weight: 300;
}
.grid figure h2 span {
font-weight: 800;
}
.grid figure h2,
.grid figure p {
margin: 0;
}
.grid figure p {
letter-spacing: 1px;
font-size: 68.5%;
}
/* Individual effects */
/*---------------*/
/***** Oscar *****/
/*---------------*/
figure.effect-oscar {
background: -webkit-linear-gradient( 45deg, #22682a 0%, #9b4a1b 40%, #3a342a 100%);
background: linear-gradient(45deg, #22682a 0%, #9b4a1b 40%, #3a342a 100%);
}
figure.effect-oscar img {
opacity: 0.9;
-webkit-transition: opacity 0.35s;
transition: opacity 0.35s;
}
figure.effect-oscar figcaption {
padding: 3em;
background-color: rgba(58, 52, 42, 0.7);
-webkit-transition: background-color 0.35s;
transition: background-color 0.35s;
}
figure.effect-oscar figcaption::before {
position: absolute;
top: 30px;
right: 30px;
bottom: 30px;
left: 30px;
border: 1px solid #fff;
content: "";
}
figure.effect-oscar h2 {
margin: 20% 0 10px 0;
-webkit-transition: -webkit-transform 0.35s;
transition: transform 0.35s;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
}
figure.effect-oscar figcaption::before,
figure.effect-oscar p {
opacity: 0;
-webkit-transition: opacity 0.35s, -webkit-transform 0.35s;
transition: opacity 0.35s, transform 0.35s;
-webkit-transform: scale(0);
transform: scale(0);
}
figure.effect-oscar:hover h2 {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
figure.effect-oscar:hover figcaption::before,
figure.effect-oscar:hover p {
opacity: 1;
-webkit-transform: scale(1);
transform: scale(1);
}
figure.effect-oscar:hover figcaption {
background-color: rgba(58, 52, 42, 0);
}
figure.effect-oscar:hover img {
opacity: 0.4;
}
#media screen and (max-width: 69.5em) {
.grid figure {
width: 50%;
}
.grid figure figcaption {
font-size: 90%;
}
}
#media screen and (max-width: 41.5em) {
.grid figure {
width: 100%;
}
}
<div class="container">
<div class="grid">
<figure class="effect-oscar">
<img src="https://tympanus.net/Development/HoverEffectIdeas/img/8.jpg" alt="img08" />
<figcaption>
<h2><span>Single line</span></h2>
<p>Oscar is a decent man. He used to clean porches with pleasure.</p>
View more
</figcaption>
</figure>
<figure class="effect-oscar">
<img src="https://tympanus.net/Development/HoverEffectIdeas/img/8.jpg" alt="img08" />
<figcaption>
<h2>Here I have <span>two lines</span>or more .......................</h2>
<p>Oscar is a decent man. He used to clean porches with pleasure.</p>
View more
</figcaption>
</figure>
<figure class="effect-oscar">
<img src="https://tympanus.net/Development/HoverEffectIdeas/img/8.jpg" alt="img08" />
<figcaption>
<h2><span>Single line</span></h2>
<p>Oscar is a decent man. He used to clean porches with pleasure.</p>
View more
</figcaption>
</figure>
</div>
</div>
<!-- /container -->
I have titles sometimes on one line and sometimes on two lines.
I'm having trouble aligning these titles like this :
Alignement of titles
When there are two or more text lines, the titles are shifted.
CSS is not for me! Can you help me please ?
The h2 is initially offset from the top using transform: translate3d(0, 100%, 0).
This moves the element on the y axis, and is causing a different displacement depending on the overall height of the element (I think).
You could transition the top value instead. To do this, add position: relative to the h2, and give it an initial value (top: 50px in the example below). On hover set top: 0.
*,
*:after,
*:before {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.clearfix:before,
.clearfix:after {
content: "";
display: table;
}
.clearfix:after {
clear: both;
}
body {
background: #f6f9fa;
color: #536d76;
font-weight: 400;
font-size: 1em;
font-family: "Raleway", Arial, sans-serif;
}
a {
color: #4f7f90;
text-decoration: none;
outline: none;
}
a:hover,
a:focus {
color: #39545e;
}
.grid {
overflow: hidden;
margin: 0;
padding: 3em 0 0 0;
width: 100%;
list-style: none;
text-align: center;
}
/* Common style */
.grid figure {
position: relative;
z-index: 1;
display: inline-block;
overflow: hidden;
margin: -0.135em;
width: 33.333%;
height: 400px;
background: #3085a3;
text-align: center;
cursor: pointer;
}
.grid figure img {
position: relative;
display: block;
min-height: 100%;
opacity: 0.8;
}
.grid figure figcaption {
padding: 2em;
color: #fff;
text-transform: uppercase;
font-size: 1.25em;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.grid figure figcaption::before,
.grid figure figcaption::after {
pointer-events: none;
}
.grid figure figcaption,
.grid figure a {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* Anchor will cover the whole item by default */
/* For some effects it will show as a button */
.grid figure a {
z-index: 1000;
text-indent: 200%;
white-space: nowrap;
font-size: 0;
opacity: 0;
}
.grid figure h2 {
font-weight: 300;
}
.grid figure h2 span {
font-weight: 800;
}
.grid figure h2,
.grid figure p {
margin: 0;
}
.grid figure p {
letter-spacing: 1px;
font-size: 68.5%;
}
/* Individual effects */
/*---------------*/
/***** Oscar *****/
/*---------------*/
figure.effect-oscar {
background: -webkit-linear-gradient( 45deg, #22682a 0%, #9b4a1b 40%, #3a342a 100%);
background: linear-gradient(45deg, #22682a 0%, #9b4a1b 40%, #3a342a 100%);
}
figure.effect-oscar img {
opacity: 0.9;
-webkit-transition: opacity 0.35s;
transition: opacity 0.35s;
}
figure.effect-oscar figcaption {
padding: 3em;
background-color: rgba(58, 52, 42, 0.7);
-webkit-transition: background-color 0.35s;
transition: background-color 0.35s;
}
figure.effect-oscar figcaption::before {
position: absolute;
top: 30px;
right: 30px;
bottom: 30px;
left: 30px;
border: 1px solid #fff;
content: "";
}
figure.effect-oscar h2 {
margin: 20% 0 10px 0;
transition: top 0.35s;
position: relative;
top: 50px;
}
figure.effect-oscar figcaption::before,
figure.effect-oscar p {
opacity: 0;
-webkit-transition: opacity 0.35s, -webkit-transform 0.35s;
transition: opacity 0.35s, transform 0.35s;
-webkit-transform: scale(0);
transform: scale(0);
}
figure.effect-oscar:hover h2 {
top: 0;
}
figure.effect-oscar:hover figcaption::before,
figure.effect-oscar:hover p {
opacity: 1;
-webkit-transform: scale(1);
transform: scale(1);
}
figure.effect-oscar:hover figcaption {
background-color: rgba(58, 52, 42, 0);
}
figure.effect-oscar:hover img {
opacity: 0.4;
}
#media screen and (max-width: 69.5em) {
.grid figure {
width: 50%;
}
.grid figure figcaption {
font-size: 90%;
}
}
#media screen and (max-width: 41.5em) {
.grid figure {
width: 100%;
}
}
<div class="container">
<div class="grid">
<figure class="effect-oscar">
<img src="https://tympanus.net/Development/HoverEffectIdeas/img/8.jpg" alt="img08" />
<figcaption>
<h2><span>Single line</span></h2>
<p>Oscar is a decent man. He used to clean porches with pleasure.</p>
View more
</figcaption>
</figure>
<figure class="effect-oscar">
<img src="https://tympanus.net/Development/HoverEffectIdeas/img/8.jpg" alt="img08" />
<figcaption>
<h2>Here I have <span>two lines</span>or more .......................</h2>
<p>Oscar is a decent man. He used to clean porches with pleasure.</p>
View more
</figcaption>
</figure>
<figure class="effect-oscar">
<img src="https://tympanus.net/Development/HoverEffectIdeas/img/8.jpg" alt="img08" />
<figcaption>
<h2><span>Single line</span></h2>
<p>Oscar is a decent man. He used to clean porches with pleasure.</p>
View more
</figcaption>
</figure>
</div>
</div>
<!-- /container -->

transition width not working?

I have this HTML:
.orderData_button {
background-color: #FF5733;
border: none;
color: white;
padding: 5px 60px;
text-align: center;
display: inline-block;
font-size: 16px;
transition: width 1s ease-in-out
}
.slideDown_orderData {
display: none;
position: relative;
z-index: 3;
transition: width 1s ease-in-out
}
.orderData_button:hover .slideDown_orderData {
display: block;
width: 100%;
}
.orderData_button:hover {
width: 50%;
}
#orderData_2 {
font-size: 20px;
text-align: center;
}
<div class="orderData_button">
<p>Your Orders</p>
<p></p>
<div class="slideDown_orderData">
<p id="orderData_2"></p>
</div>
</div>
My orderData_button and slideDown_orderData will not transition width, but will change instantly. Why is this? (Yes I have look all over google, with no success)
-CSS noob

Height Transition Not Working CSS

My codes are pretty simple yet I've failed to get how a transition works and how it doesn't work on my HTML right here:
<div id="footer">
<div id="footer1">
<p> This should be a footer </p>
</div>
</div>
and my CSS
#footer {
position: fixed;
bottom: 0;
background-color: black;
min-width: 100%;
font-family: Agency FB;
transition: width 3s;
}
#footer1 {
text-align: center;
color: #4e4e4e;
}
#footer:hover {
opacity: .8;
color: white;
height: 100px;
}
I don't see anything wrong with my code. That or I'm still inexperienced. Thanks!
Try this
#footer {
position: fixed;
bottom: 0;
background-color: black;
min-width: 100%;
font-family: Agency FB;
transition: height 3s;
height: 50px;
}
#footer1 {
text-align: center;
color: #4e4e4e;
}
#footer:hover {
opacity: .8;
color: white;
height: 100px;
}
If it doesn't work please tell me
#footer {
position: absolute;
bottom:0;
background-color: black;
min-width: 100%;
height:50px;
font-family: Agency FB;
transition: width 3s, height 1s, transform 1s;
}
#footer1 {
text-align: center;
color: #4e4e4e;
}
#footer:hover {
opacity: .8;
color: white;
height: 100px;
}
<div id="footer">
<div id="footer1">
<p> This should be a footer </p>
</div>
</div>
Just play around with the values of transition: width 3s, height 1s, transform 1s;
Cheers!

How to get text to appear cleanly after widening div through transition in CSS?

Here you can see my issue. I assume it has to do with the block and inline-block. I want to cleanly make the text appear when hovering over the area. Preferably all in CSS. If anyone can point me in the right direction, that'd be amazing. Thank you!
HTML
<div class="contact-icon icongrow" id="github">
<span class="fa fa-github icon"></span>
<span class="contact-icon-text">#username</span>
</div>
CSS
#github {
border-radius: 15px 10px;
padding: 8px 5px 5px 8px;
background: #000000;
color: #FFFFFF;
}
.icon {
float:none;
}
.icongrow {
font-size:24px;
width: 24px;
transition:width 1s;
display: block;
}
.icongrow:hover {
font-size: 28px;
width: 300px;
}
.icongrow:hover .contact-icon-text {
display: inline-block;
}
.contact-icon-text {
display: none;
}
https://jsfiddle.net/sfpfka64/
Add white-space: nowrap to .icongrow
.icongrow {
font-size:24px;
width: 24px;
transition:width 1s;
display: block;
white-space: nowrap;
}
and add an opacity transition to contact-icon-text :
.icongrow:hover .contact-icon-text {
opacity: 1;
}
.contact-icon-text {
opacity: 0;
display:inline-block;
transition: all 0.5s;
}
Also make the font-size on hover same as the initial font-size to provide more smoothness :
.icongrow:hover {
font-size: 24px;
width: 300px;
}
Snippet
#github {
border-radius: 15px 10px;
padding: 8px 5px 5px 8px;
background: #000000;
color: #FFFFFF;
}
.icon {
float:none;
}
.icongrow {
font-size:24px;
width: 24px;
transition:width 1s;
display: block;
white-space: nowrap;
}
.icongrow:hover {
font-size: 24px;
width: 300px;
}
.icongrow:hover .contact-icon-text {
opacity: 1;
}
.contact-icon-text {
opacity: 0;
display:inline-block;
transition: all 0.5s;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="contact-icon-container">
<div class="contact-icon icongrow" id="github">
<span class="fa fa-github icon"></span>
<span class="contact-icon-text">#username</span>
</div>
</div>
Just add the following rules to the .icongrow
white-space: nowrap;
overflow: hidden;
Working fiddle: https://jsfiddle.net/yvqga0ja/
An easy way would be to put your "contact-icon-text" as a position absolute, so that he would always be placed at the right place.
Demo
.contact-icon-container{
position:relative;
}
.contact-icon-text {
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 10px;
opacity: 0;
}
.icongrow:hover .contact-icon-text {
opacity: 1;
transition: .3s ease-in;
You can add transition-delay in order to make your text appear a bit later, but you get the way I would do it :)

CSS – Blurring image with un-blurred text

I have div elements that are 200px tall and 200px wide, and I am filling each div element with an image of a person.
Upon hovering on the image, I want the image to be blurred, but I simultaneously want text to appear on the image (unblurred) that gives a description of who they are. Does anyone know how to do this?
So far, this is what I am getting:
Here is the CSS code:
.mem1 {
height: 200px;
width: 200px;
margin: 0px 31px;
display: inline-block;
border-radius: 10px;
border: solid;
border-width: thin;
border-color: #d6d6d6;
background-image: url(members/giles.png);
}
.mem1 p {
text-align: center;
position: absolute;
margin: 70px 30px;
visibility: hidden;
}
.mem1:hover {
-webkit-filter: blur(2px);
}
.mem1:hover p {
text-align: center;
position: absolute;
margin: 70px 30px;
color: #ffffff;
text-shadow: 1px 1px #000000;
-webkit-filter: blur(0px);
visibility: visible;
}
It sounds like the text is a child of the element that you are blurring. You can't do that. You need to do something like this:
<div class="container">
<div class="blurredPhoto"></div>
<div class="text">Your Text</div>
</div>
.container {
width: 200px;
height: 200px;
position: relative;
}
.blurredPhoto {
position: absolute;
width: 200px;
height: 200px;
}
.text {
position: absolute;
width: 200px;
height: 200px;
}
Then apply your blurring logic only to the .blurredPhoto object.
Here is a code snippet that does what you are looking for - blurring an image when you mouse over it, while simultaneously showing a textual description.
The key is that you need to use the :hover pseudoclass on the div, then when the div is hovered, you blur the image only, and show the description text span.
.blur {
width: 350px;
height: 350px;
}
.blur img {
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
.blur span {
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
.blur:hover img {
-webkit-filter: blur(5px);
}
.blur span {
opacity: 0;
position: absolute;
top: 30px;
left: 30px;
}
.blur:hover span {
opacity: 1;
}
<div class="blur pic">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97350&w=350&h=350">
<span>This is a photo of something.</span>
</div>
As #DA explained you need to get a parent container involved. Here's a working fiddle using your example code: https://jsfiddle.net/m25gkqkL/1/
<div class="parent">
<div class="mem1"></div>
<p>Hello World!</p>
</div>
.mem1 {
height: 200px;
width: 200px;
margin: 0px 31px;
display: inline-block;
border-radius: 10px;
border: solid;
border-width: thin;
border-color: #d6d6d6;
background-image: url(members/giles.png);
z-index: 1;/* added */
position: relative;/* added */
}
.parent {/* added this */
position: relative;
height: 200px;
width: 262px;
}
.parent p {/* modified */
text-align: center;
position: absolute;
visibility: hidden;
top: 50%;/* modified */
margin-top: -0.5em;/* added */
width: 262px;/* added */
z-index: 2;/* added */
}
.parent:hover .mem1 {/* modified */
-webkit-filter: blur(2px);
}
.parent:hover p {/* modified */
color: #ffffff;
text-shadow: 1px 1px #000000;
-webkit-filter: blur(0px);
visibility: visible;
}
.parent{
position: relative;
}
.text-child{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
opacity: 0;
transition: all .3s ease;
z-index: 1;
}
.text-child h1{
color: black;
text-decoration: none;
font-size: 40px;
}
.parent:hover img{
filter: blur(4px);
}
.parent:hover .text-child{
opacity: 1;
}
<div class="parent">
<div class="text-child">
<h1> hi this is text.<h1>
</div>
<img src="/images/excel.png" alt="">
</div>

Resources