Place box-shadow behind sibling in CSS - 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.

Related

A glow around a circular image with CSS on hover

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.

Why the animation is showing only on hover and not when leaves?

this is fast, I have a menu that I am trying to animate with the :hover event, the menu is on a navbar and what I am trying to accomplish is the same behavior as Twitter navbar, once you hover the links, a border bottom appears, in my case is a box-shadow but it doesn't matter. As you see in the example, there is an animation once the user hover the links and I want the same animation when the user leaves
See here my codepen
and here my css
.capilleira-navbar{
background: white;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
a {
color: getColor(night);
}
a:hover, a:focus {
background: getColor(snow) !important;
color: red;
box-shadow: inset 0px -4px 0px 0px red;
margin: 0px;
transition: all 0.4s ease-in-out;
}
img {
max-width:100px;
margin-top: -7px;
}
.navbar-nav {
margin-left: 30px;
}
.navbar-nav > li > a {
padding-left: 30px;
padding-right: 30px;
}
}
.one {
transition: all 0.4s ease-in-out;
}
.one:hover {
box-shadow: inset 0px -4px 0px 0px red;
transition: all 0.4s ease-in-out;
}
<div class="one">
Hover
</div>
This is because you have the transition in the 'a:hover' declaration and not the 'a' declaration. The 'a:hover' is only in effect whilst you are hovering over the element, once you move the mouse off, it doesn't apply anymore, hence why the transition doesn't have any effect then. If you move the transition to the 'a', it will work correctly as shown in this codepen
a {
color: getColor(night);
transition: all 0.4s ease-in-out;
}
a:hover, a:focus {
background: getColor(snow) !important;
color: red;
box-shadow: inset 0px -4px 0px 0px red;
margin: 0px;
}
Remove the transition in a:hover, a:focus and add this
a
{
transition: all 0.4s ease-in-out;
}

CSS Gallery not responding

My CSS Gallery specifications are not corresponding to my HTML5. The images are not following the hover tag and they are displaying on top of everything else. It will not stay fixed however when I change the positioning to fixed it disappear all together. CSS checker states validates all fine. I can not position it where I want on the page either. Any help would be appreciated. Thanks in advance
CSS CODE
#gallery {
bottom: -20px;
padding-right: 50px;
display: inline;
top: 200px;
z-index: 99999999;
}
#gallery ul {
list-style-type: none;
padding: 20px;
text-align: center;
position: fixed;
}
#gallery li {
display: inline;
padding-right: 20px;
}
#gallery img {
padding: 5px 5px 40px 5px;
background: white;
box-shadow: 4px 4px 8px -4px #000000;
-webkit-box-shadow: 4px 4px 8px -4px #000000;
-mox-box-shadow:4px 4px 8px -4px #000000;
}
#gallery:hover {
-webkit-transform:scale(5%);
-o-transform:scale(5%);
-moz-transform:scale(5%);
-ms-transform: scale(5%);
transform: scale(5%);
transition: 0.5s ease-in-out;
-webkit-transition:0.5s ease-in-out;
-o-transition:0.5s ease-in-out;
-mox-transition:0.5s ease-in-out;
-ms-transition: 0.5s ease-in-out;
}

input type text not going in the same position?

Here is my jsfiddle http://jsfiddle.net/7LUV4/
As you can see,
.text {
width: auto;
height: 20px;
outline: none;
-webkit-box-shadow: 7px 7px 0px rgba(50, 50, 50, 0);
-moz-box-shadow: 7px 7px 0px rgba(50, 50, 50, 0);
box-shadow: 7px 7px 0px rgba(50, 50, 50, 0);
transition: box-shadow 0.2s ease;
-moz-transition: box-shadow 0.2s ease;
-webkit-transition: box-shadow 0.1s ease;
-ms-transition: box-shadow 0.2s ease;
-o-transition: box-shadow 0.2s ease;
border: 1px solid #CFCACC;
border-radius: 9px 9px 9px 9px;
-moz-border-radius: 9px 9px 9px 9px;
-webkit-border-radius: 9px 9px 9px 9px;
margin: 5px 20px;
word-wrap: break-word;
}
That is the code i'm using, It uses :focus for it's transition but the thing is, it's not staying at the same position. it's just floating from right to left, How do I fix this?
If possible, please?
You can give the proper styles to label:
label {
display: inline-block;
width: 120px;
text-align: right;
}
Here you make label display as a inline block element, give it exact width, and make text align to right. Hence, you get the inputs nicely aligned under each other.
Btw, it's not good to style all labels like this. You'd better give some id to the form and use #myForm label as the selector.
See in fiddle
Add this to your css
input.text, label.alt{
display: inline-block;
*display: inline;
zoom: 1;
vertical-align: baseline;
width: 150px;
}
label.alt{
text-align: left;
}
FIDDLE

CSS3 Colour Transition on Button

I can't seem to get my button to change colour with CSS3 transitions. I've been successful using the roundabout same code on and tags, but no such luck with the button.
Here's the code:
.button {
position:absolute;
width: 135px;
height: 46px;
background-color: #ef6529;
text-decoration: none;
border-radius: 4px;
-moz-border-radius: 4px;
border: 1px solid #c33b00;
box-shadow: 0px 4px 0px #af5a5a;
-moz-box-shadow: 0px 4px 0px #af5a5a;
-webkit-box-shadow: 0px 4px 0px #af5a5a;
-webkit-transition:color 1s ease-in;
-moz-transition:color 1s ease-in;
-o-transition:color 1s ease-in;
transition:color 1s ease-in;
}
.button:hover {
width: 135px;
height: 46px;
background-color: #ff6726;
border-radius: 4px;
-moz-border-radius: 4px;
border: 1px solid #c33b00;
text-decoration: none;
}
and the HTML:
<a href="#" class="button">
<!--<h2>PUSH ME!</h2>-->
</a>
Cheers!
You haven't specified colors for the button. I presume you want to transition the background color insted. Just change transition:color 1s ease-in; to transition: background-color 1s ease-in;.

Resources