Fading out/color overlay on background image - html

I have replicated a demo of my problem but solution to a relatively simple problem:
Fiddle
I have four circular divs each with a unique background image (That is why the bg image is inline) but I wish to fade out or overlay the image with a colour and ensure the text dosnt fade out but retains its full opacity.
I have tried numerous things such as simply just changing the opacity on the hover etc but struggling here.
<div class="faces-container">
<div class="faces" style="background-image: url('http://i.huffpost.com/gen/1697767/thumbs/o-GAME-OF-THRONES-facebook.jpg');">
<span class="name">Dan</span>
</div>
</div>
.faces-container{
height: auto;
overflow: auto;
text-align: center;
margin: 0;
box-sizing: border-box;
padding: 20px 20px;
display: inline-block;
-webkit-animation: fadein 3s; /* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 3s; /* Firefox < 16 */
-ms-animation: fadein 3s; /* Internet Explorer */
-o-animation: fadein 3s; /* Opera < 12.1 */
animation: fadein 3s;
}
.faces{
border-radius: 200px;
height: 200px;
width: 200px;
background-size: cover;
-webkit-transition : all 500ms ease-out;
-moz-transition : all 500ms ease-out;
-o-transition : all 500ms ease-out;
transition : all 500ms ease-out;
color: transparent;
line-height: 200px;
font-size: 2.5em;
}
.faces:hover{
cursor: pointer;
-moz-box-shadow: 0px 0px 10px 5px #aaa;
-webkit-box-shadow: 0px 0px 10px 5px #aaa;
box-shadow: 0px 0px 10px 5px #aaa;
color: #F7CA18;
}

JSFiddle
I removed your inline background-image for the .faces and replaced it with
background-image: linear-gradient( rgba(0,0,0,0.7), rgba(0,0,0,0.7) ), url('http://i.huffpost.com/gen/1697767/thumbs/o-GAME-OF-THRONES-facebook.jpg');
on your .faces class.
I didn't get the point about /unique/ name and inline style declaration. This makes no sense. You can just have it like that:
<div class="faces face-1"></div> and then face-2 and etc, where all the common styles for the elements will be stored in faces, and the hover state will be handeled in faces-x and faces-2.

Example
.faces:hover > span.name{
opacity: 0.5
}

Change your code to this
.faces-container,.faces,.name{transition : all 500ms ease-out;box-sizing: border-box}
.faces-container{
height: auto;
text-align: center;
margin: 0;
padding: 20px 20px;
display: inline-block;
animation: fadein 3s;
height: 200px;
width: 200px;
position: relative
}
.faces{
border-radius: 200px;
height: 100%;
width: 100%;
background-size: cover;
transition : all 500ms ease-out;
color: transparent;
line-height: 200px;
font-size: 2.5em;
position: absolute;
left: 0;
top: 0
}
.name{
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate3d(-50%,0,0)
}
.faces-container:hover .faces{
box-shadow: 0px 0px 10px 5px #aaa;
z-index: 1;
opacity: 0
}
.faces-container:hover .name{
cursor: pointer;
color: #F7CA18;
z-index: 2;
opacity: 1
}
<div class="faces-container">
<div class="faces" style="background-image: url('http://i.huffpost.com/gen/1697767/thumbs/o-GAME-OF-THRONES-facebook.jpg');"></div>
<span class="name">Dan</span>
</div>

Related

transition css top and bottom

How can I make such animation ?
(https://i.stack.imgur.com/NTWjH.png)
please check link below
https://preview.themeforest.net/item/shopify-outstock-clean-minimal-drag-drop/full_screen_preview/21041667?_ga=2.52492833.847676305.1666954417-2031082058.1666954417
.wrap-img {
transition: all 200ms ease 0s;
-webkit-transition: all 200ms ease 0s;
-moz-transition: all 200ms ease 0s;
overflow: hidden;
margin: 0px auto;
position: relative;
background: #fff;
padding: 15px;
}
One option would be this:
.box {
/* Required for the position: absolute property of the overlay. */
position: relative;
}
/* Scroll up and down effect */
.scrolling {
background-size: cover !important;
width: 285px;
min-height: 500px;
border: 15px solid #fff; /* Border is white */
cursor: pointer;
transition: background-position 1.5s ease-out 0.5s
}
.scroll {
background: url("https://velatheme.com/demo/outstock/images/cosmetic2.jpg");
background-position: top center;
}
.scroll_top:hover {
background-position: bottom center !important;
transition: background-position 2s linear 0s;
}
/* Background separating the image and the button */
.overlay {
position: absolute;
display: flex;
justify-content: center;
align-items:center;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: rgba(0,0,0,0.4);
}
.box:hover .overlay {
opacity: 1;
}
/* Button */
button {
display: none;
}
.box:hover button {
display: inline-block;
height: 48px;
width: 158px;
border: 4px solid #fff;
text-align: center;
line-height: 30px;
font-size: 14px;
font-weight: 600;
text-transform: uppercase;
color: #333;
}
.box button:hover {
display: inline-block;
color: #fff;
background: #333;
cursor: pointer
}
<div class="box scrolling scroll scroll_top">
<div class="overlay">
<button>VIEW DEMO</button>
</div>
</div>
To do the opposite effect, you would first have to change the classes to scroll_bottom and it would just change:
In .scroll :
background-position: bottom center;
And in .scroll_top:hover (In this case it would be .scroll_bottom:hover):
background-position: top center !important;

CSS animated gradient border on a DIV

I'm trying to create a loading DIV that has a border that looks like an indeterminate progress ring spinner.
I'm pretty close based on one of the examples on https://css-tricks.com/gradient-borders-in-css/
This is great when the border doesn't rotate. When you set the border in the :before element to match the transparent border in the gradient-box element then the static gradient border looks perfect.
However, once the animation is added, because the whole :before element rotates you get a pretty odd effect - as shown in the example below.
.gradient-box {
display: flex;
align-items: center;
width: 90%;
margin: auto;
max-width: 22em;
position: relative;
padding: 30% 2em;
box-sizing: border-box;
border: 5px solid blue;
color: #FFF;
background: #000;
background-clip: padding-box; /* !importanté */
border: solid 5px transparent; /* !importanté */
border-radius: 1em;
}
.gradient-box:before {
content: '';
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
z-index: -1;
margin: -35px; /* !importanté */
border-radius: inherit; /* !importanté */
background: conic-gradient(#0000ff00, #ff0000ff);
-webkit-animation: rotate-border 5s linear infinite;
-moz-animation: rotate-border 5s linear infinite;
-o-animation: rotate-border 5s linear infinite;
animation: rotate-border 3s linear infinite;
}
#keyframes rotate-border {
to {
transform: rotate(360deg);
}
}
html { height: 100%; background: #000; display: flex; }
body { margin: auto; }
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Loading DIV Test</title>
</head>
<body>
<div id="loadingBox" class="gradient-box">
<p>Loading.</p>
</div>
</body>
I've tried playing about with overflow: hidden; but the border just disappears.. is there any way to 'mask' the :before element in a way that whatever is behind this loading Div is still visible behind it and so that the border stays as its intended width?
Basically, my goal is that the colour gradient in the border rotates to give the effect of a spinning/rotating edge.
I like your original idea with using overflow: hidden, but to make it work I had to include an extra wrapper div.
The outer wrapper defines a padding which serves as the display area for the gradient border
The inner div is just the content box with a black background
.loading-box-container {
--size: 200px;
--radius: 10px;
position: relative;
width: var(--size);
height: var(--size);
padding: var(--radius);
border-radius: var(--radius);
overflow: hidden;
}
.loading-box {
position: relative;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
background: #000;
border-radius: var(--radius);
}
.loading-box-container::before {
content: '';
width: 150%; /* The upscaling allows the box to fill its container even when rotated */
height: 150%;
position: absolute;
top: -25%; left: -25%;
background: conic-gradient(#0000ff00, #ff0000ff);
animation: rotate-border 5s linear infinite;
}
#keyframes rotate-border {
to {
transform: rotate(360deg);
}
}
<div class="loading-box-container">
<div class="loading-box">
<p>Loading</p>
</div>
</div>
An alternative: Using #property
There's a much more elegant solution using #property, but unfortunately it only works on Chrome. I'm including here in case one day it becomes more universally supported or support for other browsers isn't important for your use case.
The conic-gradient function has a parameter that allows you to specify at what angle the gradient starts. If we can animate just that parameter, perhaps using a CSS variable, then we can animate the border with just a single div and without actually rotating anything.
Unfortunately, without some hinting the browser doesn't know how to transition a CSS variable. Therefore, we use #property to indicate the variable is an angle, telling the browser how to transition it.
#property --rotation {
syntax: '<angle>';
initial-value: 0deg;
inherits: false;
}
.loading-box {
--size: 200px;
--radius: 10px;
position: relative;
width: var(--size);
height: var(--size);
display: flex;
align-items: center;
justify-content: center;
color: #fff;
background: #000;
border-radius: var(--radius);
margin: var(--radius);
}
.loading-box::before {
--rotation: 0deg;
content: '';
width: calc(100% + 2 * var(--radius));
height: calc(100% + 2 * var(--radius));
border-radius: var(--radius);
position: absolute;
top: calc(-1 * var(--radius)); left: calc(-1 * var(--radius));
background: conic-gradient(from var(--rotation), #0000ff00, #ff0000ff);
animation: rotate-border 5s linear infinite;
z-index: -1;
}
#keyframes rotate-border {
to {
--rotation: 360deg;
}
}
<div class="loading-box">
<p>Loading</p>
</div>
CanIUse for #property indicates this will only work in Chrome and Edge as of this post.
Hi is this what you are looking for?
What I did was I added a new div which will be the "mask" as well as a container div for both the mask and the loadingBox.
I then sized the mask to be a little larger than your visible area, make it a transparent background, and then gave it a large outline the same color as your background to effectively mask out a border. I then fiddled with z-indexs of the mask, the loadingbox and the before. I also added some actual borders on mask to box it out into a nice shape.
Take a look:
.gradient-box {
display: flex;
align-items: center;
width: 90%;
margin: auto;
max-width: 22em;
position: relative;
padding: 30% 2em;
box-sizing: border-box;
border: 5px solid blue;
color: #FFF;
background: #000;
background-clip: padding-box; /* !importanté */
border: solid 5px transparent; /* !importanté */
border-radius: 1em;
}
.gradient-box:before {
content: '';
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
z-index: -3;
margin: -35px; /* !importanté */
border-radius: inherit; /* !importanté */
background: conic-gradient(#0000ff00, #ff0000ff);
-webkit-animation: rotate-border 5s linear infinite;
-moz-animation: rotate-border 5s linear infinite;
-o-animation: rotate-border 5s linear infinite;
animation: rotate-border 3s linear infinite;
}
#keyframes rotate-border {
to {
transform: rotate(360deg);
}
}
html { height: 100%; background: #000; display: flex; }
body { margin: auto; }
.mask {
position: absolute;
box-sizing: border-box;
background-color: transparent;
outline: 65px solid black;
height: 100%;
width: 100%;
border: 2px solid black;
border-left: 7px solid black;
border-right: 7px solid black;
z-index: -1;
}
.container {
position: relative;
}
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Loading DIV Test</title>
</head>
<body>
<div class="container">
<div class="mask"></div>
<div id="loadingBox" class="gradient-box">
<p>Loading.</p>
</div>
</div>
</body>

Child div does not fill the parent div when using rounded corners

Per the title, you can see a demo of the issue here.
Here is the HTML code:
<div id="outer">
<div id="inner">
</div>
</div>
Here is the CSS code:
#inner{
height: 100%;
width: 100%;
border-radius: 20px;
text-shadow: 5px 5px 5px #000000;
background-color: white;
opacity: 0;
-webkit-transition: opacity .5s linear;
-moz-transition: opacity .5s linear;
transition: opacity .5s linear;
}
#inner:hover{
opacity: 1;
}
#outer{
border: 6px solid #dcc5c5;
border-radius: 20px;
text-shadow: 5px 5px 5px #000000;
position: relative;
display: inline-block;
transition: all 0.5s ease-in-out;
background-color: red;
height: 200px;
width: 200px;
}
I've tried various suggestions here and here with no solution.
you are using margin-top:20px;
in this element
#inner {
height: 100px;
background-color: #42749F;
width: 200px;
/* -1px here for to compansate for the outer border of the container */
-moz-border-radius: 0 0 9px 9px;
}
remove margin and it will fill inside parent element
Working fiddle
The problem in that is that the child takes priority, if the parent div says:
text-font: Sans-Serif
but the child says:
text-font: Arial
the elements in the child sector take priority. In other words, the parent is the "Default". The same happens to "rounded corners" and "margin-top". The "margin-top" takes priority.
Just make sure that those two are correct.
I guess the border you've set on the inside division is creating problems here. Removing the border makes the child element fully fill the parent.
Is this what you were looking for? You may elaborate more if you want, in comments.
.box {
position: relative;
overflow: hidden;
border-radius: 20px;
transition: all 0.5s ease-in-out;
background-color: red;
height: 200px;
width: 200px;
}
.scratcher{
height: 100%;
width: 100%;
background-color: white;
opacity: 0;
transition: opacity .5s linear;
}
.scratcher:hover{
opacity: 1;
}
<div class="box">
<div class="scratcher">Scratcher</div>
</div>
I noticed that if you offset the difference (6px) in border-width of the containing element (.box_1 / #outer), with the border-radius of the nested element (#scratcher / #inner), you will fill up the corner gaps.
Deduct 6px from the border-radius value of the nested element (#scratcher / #inner).
#inner {
height: 100%;
width: 100%;
border-radius: 13px;
text-shadow: 5px 5px 5px #000000;
background-color: white;
opacity: 0;
-webkit-transition: opacity .5s linear;
-moz-transition: opacity .5s linear;
transition: opacity .5s linear;
}
#inner:hover {
opacity: 1;
}
#outer {
border: 6px solid #dcc5c5;
border-radius: 20px;
text-shadow: 5px 5px 5px #000000;
position: relative;
display: inline-block;
transition: all 0.5s ease-in-out;
background-color: red;
height: 200px;
width: 200px;
}
<div id="outer">
<div id="inner">
</div>
</div>

how to make coin flip transform in css

So, I have an icon, a circle icon, I want to make this icon when it hovered it will has coin flip transform, just like https://desandro.github.io/3dtransforms/examples/card-02-slide-flip.html but it flip two times so it goes back to the first position.
This is the HTML code:
<div class="bg">
<div class="icon">
<img src="football.png">
</div>
</div>
This is the CSS code:
.bg {
padding: 6px 6px;
float: left;
width: 20%;
}
.icon {
width: 100px;
height: 100px;
overflow: hidden;
border-radius: 50%;
box-shadow: 3px 3px 10px black;
border: 0px;
background-color: white;
margin-left: auto;
margin-right: auto;
display: block;
}
.icon img{
left: 50%;
top: 50%;
height: 100%;
width: auto;
}
.icon:hover {
transform: translateX( -1px ) rotateY( 180deg );
}
so the transform is not soft like the example from the link, and when the first flip (or rotation) I want to change the icon with different image, but when the second rotate it will back to first image. Any suggestion? thanks before
You forgot to add the animation itself, the transition.
.bg {
padding: 6px 6px;
float: left;
width: 20%;
}
.icon {
width: 100px;
height: 100px;
overflow: hidden;
border-radius: 50%;
box-shadow: 3px 3px 10px black;
border: 0px;
background-color: white;
margin-left: auto;
margin-right: auto;
display: block;
/* TRANSITION HERE!! */
-webkit-transition: transform 1s ease;
-moz-transition: transform 1s ease;
-ms-transition: transform 1s ease;
-o-transition: transform 1s ease;
transition: transform 1s ease;
/* END OF TRANSITION */
}
.icon img{
left: 50%;
top: 50%;
height: 100%;
width: auto;
}
.icon:hover {
transform: translateX( -1px ) rotateY( 180deg ); /* ALSO EXTRA TRANSFORM PROPERTIES ADDED FOR COMPATIBILITY*/
-ms-transform: translateX( -1px ) rotateY(180deg); /* IE 9 */
-webkit-transform: translateX( -1px ) rotateY(180deg); /* Chrome, Safari, Opera */
}
<div class="bg">
<div class="icon">
<img src="https://i.stack.imgur.com/RVjde.jpg">
</div>
</div>
I hope this helped.
Cheers!
You can define an animation the following:
#keyframes flip_animation {
from {transform: rotateY(0deg);}
to {transform: rotateY(360deg);}
}
And add this animation you your CSS-Class
.icon:hover {
animation-name: flip_animation;
animation-duration: 1s;
}
See this link for more information about animations in CSS.

Pure CSS3 Responsive Lightbox Appears Half-Off Screen

Created a LightBox effect using pure CSS and HTML, no JS. The image appears, but on the right side of the screen, halfway cut off, and partially underneath my Nav bar. Half of the screen is shaded behind the image.
It appears like it would work, aside from it being off-center and behind the navigation. From the code at hand, is there anything that appears it could be doing this? I'd be happy to post more code if necessary. Thank you!
/*Eliminates padding, centers the thumbnail */
body,
html {
padding: 0;
margin: 0;
text-align: center;
float: left;
}
/* Styles the thumbnail */
a.lightbox img {
height: 150px;
border: 3px solid white;
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
margin: 94px 20px 20px 20px;
}
/* Styles the lightbox, removes it from sight and adds the fade-in transition */
.lightbox-target {
position: fixed;
top: -100%;
width: 100%;
background: rgba(0, 0, 0, 0.7);
width: 100%;
opacity: 0;
-webkit-transition: opacity .5s ease-in-out;
-moz-transition: opacity .5s ease-in-out;
-o-transition: opacity .5s ease-in-out;
transition: opacity .5s ease-in-out;
overflow: hidden;
clear: both;
}
/* Styles the lightbox image, centers it vertically and horizontally, adds the zoom-in transition and makes it responsive using a combination of margin and absolute positioning */
.lightbox-target img {
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
max-height: 0%;
max-width: 0%;
border: 3px solid white;
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
box-sizing: border-box;
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
}
/* Styles the close link, adds the slide down transition */
a.lightbox-close {
display: block;
width: 50px;
height: 50px;
box-sizing: border-box;
background: white;
color: black;
text-decoration: none;
position: absolute;
top: -80px;
right: 0;
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
}
/* Provides part of the "X" to eliminate an image from the close link */
a.lightbox-close:before {
content: "";
display: block;
height: 30px;
width: 1px;
background: black;
position: absolute;
left: 26px;
top: 10px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
/* Provides part of the "X" to eliminate an image from the close link */
a.lightbox-close:after {
content: "";
display: block;
height: 30px;
width: 1px;
background: black;
position: absolute;
left: 26px;
top: 10px;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
/* Uses the :target pseudo-class to perform the animations upon clicking the .lightbox-target anchor */
.lightbox-target:target {
opacity: 1;
top: 0;
bottom: 0;
}
.lightbox-target:target img {
max-height: 100%;
max-width: 100%;
}
.lightbox-target:target a.lightbox-close {
top: 0px;
}
<div id="gravel-button">
<a class="lightbox" href="#gravel-1">
<h7>Photo & Info</h7>
</a>
</div>
<div class="lightbox-target" id="gravel-1">
<img src="http://www.sbsg.com/wp-content/uploads/2010/02/58minus.jpg">
<a class="lightbox-close"></a>
</div>