A glow around a circular image with CSS on hover - css

I want there to be a "glow" effect around a circular image I have (it appears as a circle, but it really is a square image with transparent pixels to make it appear as a circle).
Is there an easy and efficient way to do this with CSS? I have tried box shadow, but it doesn't seem to be working correctly.

You can do something like this with box-shadow and CSS animation
img {
margin: 30px;
border-radius: 50%;
box-shadow: 0px 0px 9px 4px #747DE8;
animation: glow 1.5s linear infinite alternate;
}
#keyframes glow{
to {
box-shadow: 0px 0px 30px 20px #535FED;
}
}
<img src="http://placehold.it/150x150/000000/ffffff">
Also you could use some Filters on img. Support
.element {
margin: 50px;
border-radius: 50%;
width: 150px;
height: 150px;
box-shadow: 0px 0px 9px 4px #747DE8;
animation: glowShadow 1.5s linear infinite alternate;
}
img {
width: 100%;
height: 100%;
animation: glowImage 1.5s linear infinite alternate;
}
#keyframes glowShadow{
to {
box-shadow: 0px 0px 35px 15px #535FED;
}
}
#keyframes glowImage{
to {
-webkit-filter: brightness(2);
filter: brightness(2);
}
}
<div class="element">
<img src="http://www.officialpsds.com/images/thumbs/Blue-Planet-psd85316.png">
</div>

This should help you.
.box-shadow {
-webkit-box-shadow: 0px 0px 8px 5px black;
-moz-box-shadow: 0px 0px 8px 2px light green;
box-shadow: 0px 0px 8px 2px light blue;
}
<div class="box-shadow">
<img src="path to image" />
<h1> Text In a Glowing Box.</h1>
</div>

You need to use a combination of the border-radius: property and the :hover pseudo class to get the desired effect.
Basically, set the images border-radius to 50% - this will make your image a perfect circle. Using the :hover psuedoclass will allow you to set the styling of a mouse:hover event.
HTML:
<img src="https://aedesnoyers.files.wordpress.com/2011/12/night11.jpg" class="round-hover" />
Your CSS will look something like:
.round-hover {
height: 200px; /*Resize for Fiddle*/
width: 200px;
border-radius: 50%;
}
.round-hover:hover{
/* thank you #Morgan Clark */
-webkit-box-shadow: 0px 0px 8px 5px black;
-moz-box-shadow: 0px 0px 8px 2px light green;
box-shadow: 0px 0px 8px 2px light blue;
}
Seen here in the fiddle:
Shadow over image when hovering
--SIDE NOTE-- the first two 0's of the box-shadow: property make it so there's no offset in your box shadow. This makes it appear to "glow"
EDIT
After seeing #NENAD's answer, I may have misinterpreted what was asked of a "glowing" effect.

Related

How to make a disappearing glow effect

Let's say i have a button class
.mat-cancel-color {
width: 160px;
border: 1px solid #dddddd;
color: #dddddd;
background-color: white;
border-radius: 25px;
}
and whenever i click something(not the 'mat-cancel-color' button) i want this class to gain a glow effect which would fade away over .4s.
should i create a new class and then give that class the box-shadow(glow) property, then below transition-duration property and then the the box-shadow(no glow) property again? as such:
click-class {
-webkit-box-shadow: 0px 0px 15px 10px rgba(255,255,0,1);
-moz-box-shadow: 0px 0px 15px 10px rgba(255,255,0,1);
box-shadow: 0px 0px 15px 10px rgba(255,255,0,1);
transition-duration: .4s;
-webkit-box-shadow: 0px 0px 0px 0px rgba(255,255,0,1);
-moz-box-shadow: 0px 0px 0px 0px rgba(255,255,0,1);
box-shadow: 0px 0px 0px 0px rgba(255,255,0,1);
}
or does transition-duration only work when switching classes or does it also work when switching properties inside a class? if it as such, how should i go about it?
EDIT: mistook transition-delay with transition-duration.
What you are looking for is a CSS animation. Mainly because you don't want the default state with the glow, that's why transition won't work here.
.mat-cancel-color {
width: 160px;
border: 1px solid #dddddd;
color: #dddddd;
background-color: white;
border-radius: 25px;
}
.mat-cancel-color:hover {
animation-name: glow;
animation-duration: .4s;
}
.mat-cancel-color-trans {
width: 160px;
border: 1px solid #dddddd;
color: #dddddd;
background-color: white;
border-radius: 25px;
transition: all .4s ease;
box-shadow: 0px 0px 15px 10px rgba(255, 255, 0, 0);
}
.mat-cancel-color-trans:hover {
box-shadow: 0px 0px 0px 0px rgba(255, 255, 0, 1);
}
/* Standard syntax */
#keyframes glow {
0% {
box-shadow: 0px 0px 15px 10px rgba(255, 255, 0, 1);
}
100% {
box-shadow: 0px 0px 0px 0px rgba(255, 255, 0, 1);
}
}
<button class="mat-cancel-color">Button</button>
<button class="mat-cancel-color-trans">Button</button>
You could use some psudo classes like this:
:active:not(*element/class*) {...}
and then put the glow animation that you want within the brackets. :active is a psudo class that is only applied when the element named is clicked. :not() excludes the class listed in the parentheses. As long as you have the glow animation working fine, then this should work.
This is a snippet of my test code:
a:active:not(.mat-cancel-color) {...}

Background of button dont align with shadow in vertical menu

I'm doing a project to see how well elders handle flat- vs skeuomorphic design. To do this I want to make the menu 3D and realistic. I found a pre made button that suited my purpose but when i try to make it vertical the shadow fills up the whole parent but the background doesn't.. This is the code im using for the horizontal button: http://jsfiddle.net/ahu8n91o/
HTML:
<a class="button">
<span>TEXT FOR BUTTON</span>
</a>
<a class="button">
<span>BUTTON 2</span>
</a>
<a class="button">
<span>ANOTHER BUTTON</span>
</a>
<a class="button">
<span>LAST BUTTON</span>
</a>
CSS:
.button {
display: inline-block;
margin: 5px;
width: auto;
-webkit-border-radius: 10px;
-webkit-box-shadow:
0px 3px rgba(128,128,128,1), /* gradient effects */
0px 4px rgba(118,118,118,1),
0px 5px rgba(108,108,108,1),
0px 6px rgba(98,98,98,1),
0px 7px rgba(88,88,88,1),
0px 8px rgba(78,78,78,1),
0px 14px 6px -1px rgba(128,128,128,1); /* shadow */
-webkit-transition: -webkit-box-shadow .1s ease-in-out;
}
.button span {
background-color: #E8E8E8;
background-image:
/* gloss gradient */
-webkit-gradient(
linear,
left bottom,
left top,
color-stop(50%,rgba(255,255,255,0)),
color-stop(50%,rgba(255,255,255,0.3)),
color-stop(100%,rgba(255,255,255,0.2))),
/* dark outside gradient */
-webkit-gradient(
linear,
left top,
right top,
color-stop(0%,rgba(210,210,210,0.3)),
color-stop(20%,rgba(210,210,210,0)),
color-stop(80%,rgba(210,210,210,0)),
color-stop(100%,rgba(210,210,210,0.3))),
/* light inner gradient */
-webkit-gradient(
linear,
left top,
right top,
color-stop(0%,rgba(255,255,255,0)),
color-stop(20%,rgba(255,255,255,0.5)),
color-stop(80%,rgba(255,255,255,0.5)),
color-stop(100%,rgba(255,255,255,0)));
-webkit-box-shadow:
0px -1px #fff, /* top highlight */
0px 1px 1px #FFFFFF; /* bottom edge */
-webkit-background-size: 100%, 100%, 100%, 4px 4px;
-webkit-border-radius: 10px;
-webkit-transition: -webkit-transform .1s ease-in-out;
display: inline-block;
padding: 10px 20px;
color: #3A474D;
font-weight: 700;
font-size: 1.2em;
text-shadow: 0px 1px #fff, 0px -1px #262F33;
}
.button span:hover {
color: #AEBF3B;
text-shadow: 0px -1px #97A63A;
cursor: pointer;
}
.button:hover span{
-webkit-transform: translate(0, 1px); /* depth of button press */
}
.button:active {
-webkit-box-shadow:
0px 3px rgba(128,128,128,1),
0px 4px rgba(118,118,118,1),
0px 5px rgba(108,108,108,1),
0px 6px rgba(98,98,98,1),
0px 7px rgba(88,88,88,1),
0px 8px rgba(78,78,78,1),
0px 10px 2px 0px rgba(128,128,128,.6); /* shadow */
}
.button:active span{
-webkit-transform: translate(0, 5px); /* depth of button press */
}
But when i try to make it vertical it mess up like this: http://jsfiddle.net/ahu8n91o/1/
HTML:
<link href="http://fonts.googleapis.com/css?family=Cabin:400,500,600,bold" rel="stylesheet" type="text/css" >
<link href="http://fonts.googleapis.com/css?family=PT+Sans+Narrow:regular,bold" rel="stylesheet" type="text/css" >
<div class="container">
<a class="button">
<span>TEXT FOR BUTTON</span>
</a>
<a class="button">
<span>BUTTON 2</span>
</a>
<a class="button">
<span>ANOTHER BUTTON</span>
</a>
<a class="button">
<span>LAST BUTTON</span>
</a>
</div>
CSS:
.container {
float: left;
height: 100%;
margin-right: 30px;
}
.button {
display: block;
margin: 5px;
width: auto;
-webkit-border-radius: 10px;
-webkit-box-shadow:
0px 3px rgba(128,128,128,1), /* gradient effects */
0px 4px rgba(118,118,118,1),
0px 5px rgba(108,108,108,1),
0px 6px rgba(98,98,98,1),
0px 7px rgba(88,88,88,1),
0px 8px rgba(78,78,78,1),
0px 14px 6px -1px rgba(128,128,128,1); /* shadow */
-webkit-transition: -webkit-box-shadow .1s ease-in-out;
}
.button span {
background-color: #E8E8E8;
background-image:
/* gloss gradient */
-webkit-gradient(
linear,
left bottom,
left top,
color-stop(50%,rgba(255,255,255,0)),
color-stop(50%,rgba(255,255,255,0.3)),
color-stop(100%,rgba(255,255,255,0.2))),
/* dark outside gradient */
-webkit-gradient(
linear,
left top,
right top,
color-stop(0%,rgba(210,210,210,0.3)),
color-stop(20%,rgba(210,210,210,0)),
color-stop(80%,rgba(210,210,210,0)),
color-stop(100%,rgba(210,210,210,0.3))),
/* light inner gradient */
-webkit-gradient(
linear,
left top,
right top,
color-stop(0%,rgba(255,255,255,0)),
color-stop(20%,rgba(255,255,255,0.5)),
color-stop(80%,rgba(255,255,255,0.5)),
color-stop(100%,rgba(255,255,255,0)));
-webkit-box-shadow:
0px -1px #fff, /* top highlight */
0px 1px 1px #FFFFFF; /* bottom edge */
-webkit-background-size: 100%, 100%, 100%, 4px 4px;
-webkit-border-radius: 10px;
-webkit-transition: -webkit-transform .1s ease-in-out;
display: inline-block;
padding: 10px 20px;
color: #3A474D;
font-weight: 700;
font-size: 1.2em;
text-shadow: 0px 1px #fff, 0px -1px #262F33;
}
.button span:hover {
color: #AEBF3B;
text-shadow: 0px -1px #97A63A;
cursor: pointer;
}
.button:hover span{
-webkit-transform: translate(0, 1px); /* depth of button press */
}
.button:active {
-webkit-box-shadow:
0px 3px rgba(128,128,128,1),
0px 4px rgba(118,118,118,1),
0px 5px rgba(108,108,108,1),
0px 6px rgba(98,98,98,1),
0px 7px rgba(88,88,88,1),
0px 8px rgba(78,78,78,1),
0px 10px 2px 0px rgba(128,128,128,.6); /* shadow */
}
.button:active span{
-webkit-transform: translate(0, 5px); /* depth of button press */
}
I can't see what the problem is and or why the to elements dont act the same.. Maybe i'm just to tired to see the obvious but I would really appreciate some help!
You can change the button span from inline-block to:button span {display: block}. Then it will fill up the surface, but all buttons will be equal width. If you want variable width, change the button to button {display: inline-block} and add a div around each button instead.
You might want some more margin-bottom on the buttons as well.
PS: That code is a bit complicated and unsemantic. You wouldn't have this problem if the styling was applied to a single <button></button>.

Place box-shadow behind sibling in CSS

I would like a series of divs with no margin and both top and bottom box shadows such that the box shadows of each div do not overlap any other divs. I've constructed a jsfiddle to show what I'm trying to achieve and what I have now. This seems like something that z-index could be used for, but I'm not sure how.
Put all of your DIVs in one outer wrapper DIV. Apply a box shadow to that, and to the hover state of each internal DIV. Now each can be controlled independentaly.
<div class="outer">
<div class="inner">The box shadow from each div...</div>
<div class="inner">...should go under each other div.</div>
<div class="inner">The whole thing should look...</div>
<div class="inner">...like one big div with a shadow...</div>
<div class="inner">...unless you hover over one.</div>
</div>
div.outer {
background: #fff;
margin: 0px auto;
padding: 0px;
width: 300px;
cursor: pointer;
box-shadow: 0px 0px 3px #999;
transition: padding .1s ease-in-out, width .1s ease-in-out, box-shadow .1s ease-in-out;
}
div.outer:hover {
box-shadow: none;
}
div.inner {
padding: 20px;
transition: padding .1s ease-in-out, width .1s ease-in-out, box-shadow .1s ease-in-out;
}
div.inner:hover {
padding: 20px;
box-shadow: 0px 0px 5px #666;
margin-left: -20px
width: 350px;
}
I've styled this such that the box shadow on the outer DIV disappears when you hover over it, so only the hovered innerDIV shows a shadow. Adjust to taste :)
Fiddle:
https://jsfiddle.net/ehxsdjr8/7/
Are you looking for something like this?
Fiddle
$( 'div' ).hover(
function() {
$(this).addClass( "hey" );
$('div').not(this).addClass( "heyho" );
}, function() {
$(this).removeClass( "hey" );
$('div').not(this).removeClass( "heyho" );
}
);
div {
background: #fff;
margin: 0px auto;
padding: 15px;
width: 300px;
cursor: pointer;
box-shadow: 0px 0px 3px #999;
transition: padding .1s ease-in-out, width .1s ease-in-out, box-shadow .1s ease-in-out;
}
.hey{
padding: 20px;
box-shadow: 0px 0px 5px #666;
margin: 15px auto;
width: 350px;
}
.heyho {
box-shadow: 0px 0px 5px #666;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>The box shadow from each div...</div>
<div>...should go under each other div.</div>
<div>The whole thing should look...</div>
<div>...like one big div with a shadow...</div>
<div>...unless you hover over one.</div>
https://jsfiddle.net/ehxsdjr8/13
The trick here is to add multiple shadows to each div and turn them on/off as needed. In this case, add the top shadow for the first element and the first element after a hover only and modify the existing shadow to not go above the element.
div {
background: #fff;
margin: 0px auto;
padding: 15px;
width: 300px;
cursor: pointer;
box-shadow: 0px 3px 3px #999;
transition:
padding .1s ease-in-out,
width .1s ease-in-out,
box-shadow .1s ease-in-out;
}
div:hover {
padding: 20px;
box-shadow: 0px 0px 5px #666;
margin: 15px auto;
width: 350px;
}
div:hover + div {
box-shadow: 0px 3px 3px #999, 0px -3px 3px #999;
}
div:first-of-type {
box-shadow: 0px 3px 3px #999, 0px -3px 3px #999;
}
div:first-of-type:hover {
box-shadow: 0px 0px 5px #666;
}
It'll take a lot of playing around to get this to look right.

Fancy CSS shadow, possible?

I am currently coding a PSD file in HTML/CSS, and the designer used a somewhat fancy shadow. I can't figure a way to do it in CSS - is it possible? - If so, how?
Here's the shadow:
Based on thgaskell's suggested link, you can use #box:before and #box:after to add 2 slightly smaller boxes with indices lower than 0 and add shadows to them. Use the shadow's color for the background color for these as well.
Here's a codepen that attempts to do this (you can tweak it to suit your purpose):
http://codepen.io/walmik/pen/fyidv
Here's another one tweaked more to the image you ve attached:
http://codepen.io/walmik/pen/eqpGk
HTML:
<div id='box'>Fancy Shadow</div>
CSS:
#box {
position: relative;
width: 600px;
height: 300px;
padding: 20px;
background: #fff;
text-align: center;
font-size: 24px;
color: #333;
font-family: Georgia. serif;
box-shadow: 0px 0px 2px #888;
}
#box:before, #box:after
{
/*this is like appending a div element before the box:*/
z-index: -1;
position: absolute;
content: "";
bottom: 0px;
left: 0px;
width: 45%;
height: 60%;
top: 15px;
max-width:300px;
background: #888;
-webkit-box-shadow: -2px -15px 30px #888;
-moz-box-shadow: -2px -15px 30px #888;
box-shadow: -2px -15px 30px #888;
}
#box:after
{
/*this is like appending a div element after the box:*/
right: 3px;
left: auto;
-webkit-box-shadow: 2px -15px 30px #888;
-moz-box-shadow: 2px -15px 30px #888;
box-shadow: 2px -15px 30px #888;
-webkit-transform: rotate(1deg);
-moz-transform: rotate(1deg);
-o-transform: rotate(1deg);
-ms-transform: rotate(1deg);
transform: rotate(1deg);
}
What you're looking for is the CSS3 attribute box-shadow. The syntax goes something like this:
box-shadow: h-shadow v-shadow blur spread color inset;
The drop shadow you're doing in the image above has a gradient, which is not possible with CSS currently, but a similar shadow would probably be something like this:
box-shadow: -10px -10px 20px #000;
You'll need to play with the numbers to get it to where you like it, but this should help you to start.

How do I make css3 drop shadow 'gradient'?

I want to create a gradient effect on a square div element using css3 drop shadow with only the left and right sides having the shadow. In other words, I am wanting to have the drop shadow start from the top dark and gradually fade lighter towards the bottom, but with roughly the quarter bottom having NO shadow at all to create a 3d, skewed square feel.
This is what I'm working from:
.sub_header {
width:960px;
height:300px;
background:#fff;
position:absolute; top:150px; left:50%;
margin-left:-480px;
-moz-box-shadow:6px 0px 5px -5px #666, -6px 0px 5px -5px #666;
-webkit-box-shadow:6px 0px 5px -5px #666, -6px 0px 5px -5px #666;
box-shadow:6px 0px 5px -5px #666, -6px 0px 5px -5px #666;
}
thanks in advance.
You can't do it like that as CSS3's box-shadow only accept colors. Instead you can emulate that gradient effect by placing an absolute div behind it.have a look at this.
.sub_header:before
{
position: absolute;
z-index: -1;
top: 10%; left: 10%; /*use it as you wish */
width: 100%;
height: 100%;
background: linear-gradient(transparent, #666);
content: '';
}
This should do it.

Resources