Background of button dont align with shadow in vertical menu - css

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>.

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.

how to use 2 box-shadow on a single button

I want exactly matched button with gradient and Box-shadow.
I tried gradient css3 properties (box-shadow: 2px 3px 3px #333;) but couldn't meet the expected result. Can anyone Suggest me the proper way.
I'm not getting what you want but I'm trying according to your question.
You can use 2 color box-shadow and advance gradient use like this:-
.answer-btn {
color: #fff;
font-family: Arial, sans-serif;
min-width: 267px;
padding: 18px 0 19px;
text-align: center;
border: none;
border-bottom: inset 1px #2894cc;
border-color: -moz-use-text-color -moz-use-text-color rgba(38, 144, 202, 0.11);
background-color: #278abe;
background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PHJhZGlhbEdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgY3g9IjUwJSIgY3k9Ii0yNSUiIHI9IjEwMCUiPjxzdG9wIG9mZnNldD0iMCUiIHN0b3AtY29sb3I9IiM0MWJlZTgiLz48c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiMyNjhhYmQiLz48L3JhZGlhbEdyYWRpZW50PjwvZGVmcz48cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSJ1cmwoI2dyYWQpIiAvPjwvc3ZnPiA=');
background-size: 100%;
background-image: -moz-radial-gradient(50% -25%, ellipse farthest-side, #41bee8, #268abd 100%);
background-image: -webkit-radial-gradient(50% -25%, ellipse farthest-side, #41bee8, #268abd 100%);
background-image: radial-gradient(ellipse farthest-side at 50% -25%, #41bee8, #268abd 100%);
-moz-border-radius: 5px !important;
-webkit-border-radius: 5px;
border-radius: 5px !important;
-moz-box-shadow: 0px 7px 0px 0px #1b6b9e, 0px 0px 10px 1px #b3b3b4;
-webkit-box-shadow: 0px 7px 0px 0px #1b6b9e, 0px 0px 10px 1px #b3b3b4;
box-shadow: 0px 7px 0px 0px #1b6b9e, 0px 0px 10px 1px #b3b3b4;
-moz-transition: all 0.1s;
-o-transition: all 0.1s;
-webkit-transition: all 0.1s;
transition: all 0.1s;
font-size: 25px;
font-size: 1.5625rem;
}
.answer-btn:active {
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none;
-moz-transform: translate(0px, 5px);
-ms-transform: translate(0px, 5px);
-webkit-transform: translate(0px, 5px);
transform: translate(0px, 5px);
}
https://jsfiddle.net/kant707/9zLLpLbg/

How to add background image and gradient background

how do i add a background image to a gradient background in css. here my code
input.button-add {
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
color: #ffffff;
padding: 4px 4px;
background: -moz-linear-gradient(
top,
#ff2819 0%,
#ff0d0d);
background: -webkit-gradient(
linear, left top, left bottom,
from(#ff2819),
to(#ff0d0d));
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
border: 1px solid #ffffff;
-moz-box-shadow:
0px 1px 1px rgba(000,000,000,0.5),
inset 0px 0px 2px rgba(255,255,255,0.7);
-webkit-box-shadow:
0px 1px 1px rgba(000,000,000,0.5),
inset 0px 0px 2px rgba(255,255,255,0.7);
box-shadow:
0px 1px 1px rgba(000,000,000,0.5),
inset 0px 0px 2px rgba(255,255,255,0.7);
is it possible and if its possible how?
Why not? Just add as many background-images as you want (gradients are also images) by separating them with commas. Also, specify background-position and background-repeat for all of them.
Here is your code with one image background and one gradient background:
input.button-add {
color: #ffffff;
padding: 4px 4px;
border: 1px solid #ffffff; border-radius: 5px;
display: inline-block;
width: 120px; height: 64px;
box-shadow: 0px 1px 1px rgba(000, 000, 000, 0.5), inset 0px 0px 2px rgba(255, 255, 255, 0.7);
background-image:
url('http://lorempixel.com/16/16'),
-webkit-gradient(linear, left top, left bottom, from(#ff2819), to(#fff));
background-position: 4px center, center center;
background-repeat: no-repeat, no-repeat;
}
<input id="btn" type="button" value="Click Here" class="button-add" />

Text of link will only show if my mouse hovers over link area, not anywhere in whole button

I don't know if I'll successfully convey what I mean but here goes. I have some CSS and am trying to get the text label of a link in a navigation to button to show if I hover anywhere over that button, not just over where the link should display. What happens is when I hover over most of the button, the button goes all-white. I want it to be white background, but show the text. Make sense?
Just try something as below:
CSS:
.CSSButton {
border: 1px solid #D1D1D1;
background: -webkit-gradient( linear, left top, left bottom, color-stop(0.1, #FFFFFF), color-stop(0.9, #D1D1D1) );
background: -moz-linear-gradient( center top, #FFFFFF 10%, #D1D1D1 90% );
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFF', endColorstr='#D1D1D1');
background-color: #FFFFFF;
-moz-box-shadow: inset 0px 1px 2px 0px #FFFFFF;
-webkit-box-shadow: inset 0px 1px 2px 0px #FFFFFF;
box-shadow: inset 0px 1px 2px 0px #FFFFFF;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
text-shadow: 1px 1px 2px #FFFFFF;
font-weight: bold;
margin: 5px 5px;
padding: 6px 6px;
color: #999999;
letter-spacing: 1px;
font-family: 'Arial', sans-serif;
font-size: 16px;
width: 150px;
text-transform: capitalize;
text-align: center;
text-decoration: none;
cursor: pointer;
display: inline-block;
}
.CSSButton:hover {
background: -webkit-gradient( linear, left top, left bottom, color-stop(0.1, #D1D1D1), color-stop(0.9, #FFFFFF) );
background: -moz-linear-gradient( center top, #D1D1D1 10%, #FFFFFF 90% );
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#D1D1D1', endColorstr='#FFFFFF');
background-color: #D1D1D1;
}
.CSSButton:active {
position: relative;
top: 1px;
left: 0px;
}
HTML:
<span class="CSSButton">Click Me!</span>

How do let CSS change the inset shadow on li hover, instead of resetting it?

I have got a small problem with my list item on hover.
The menu bar has a small inset shadow at the bottom, defined on the li items. On li:hover the small inset at the bottom changes to a inset shadow on all 4 sides.
I`m pretty happy about how the menu reacts, except for the li:lastchild. On hover it first delete the bottom & right inset shadow and then prints the new 4 sided inset shadow. Al the other li items just change the shadow from a single bottom to all 4 sides, without resetting the shadow.
I know the css shadow part is not written very clean. But because the hover has to CHANGE te shadow instead of replace i cant simple commit a statement on multiple selectors. (If you guys know a way to do this please feel free to comment!)
So my question is, how do i get a different inset shadow on the li:lastchild which will change on hover instead of getting replaced?
The code on cedepen
<ul class="hoofd-menu menu">
<li class="menu-item">Menu Item I</li>
<li class="menu-item">Menu Item II</li>
<li class="menu-item">Menu Item III</li>
<li class="menu-item">Menu Item IV</li>
<li class="menu-item">Menu Item V</li>
<li class="menu-item">Menu Item VI</li>
</ul>
<style>
.menu li {
margin: 0 0 0 -4px;
padding: 15px 15px;
}
/* Menu Item Hover effect */
.menu li {
box-shadow: 0 -9px 5px -5px rgba(0,0,0, 1) inset, /* dark shadow */
2px -2px 3px 0px rgba(255,255,255, 0.2), /* white - top */
2px 2px 3px 0px rgba(255,255,255, 0.2); /* white - bottom */
}
li:last-child.menu-item {
box-shadow: -9px 0px 5px -5px rgba(0,0,0, 1) inset, /*dark shadow right */
0px -9px 5px -5px rgba(0,0,0, 1) inset, /*dark shadow */
2px -2px 3px 0px rgba(255,255,255, 0.2), /* white - top */
2px 2px 3px 0px rgba(255,255,255, 0.2); /* white - bottom */
}
li:first-child.menu-item {
box-shadow: 0px -9px 5px -5px rgba(0,0,0, 1) inset, /* dark shadow */
-2px -2px 3px 0px rgba(255,255,255, 0.2), /* white - left */
2px -2px 3px 0px rgba(255,255,255, 0.2), /* white - top */
2px 2px 3px 0px rgba(255,255,255, 0.2); /* white - bottom */
}
.menu li:hover {
cursor: pointer;
box-shadow: -1px -1px 10px 4px rgba(0,0,0, 1) inset, /* dark shadow */
2px -2px 3px 0px rgba(255,255,255, 0.2), /* white - top */
2px 2px 3px 0px rgba(255,255,255, 0.2); /* white - bottom */
}
.menu li:hover>a {
text-shadow: -1px -1px 3px rgba(0,0,0, 0.2); /* text shadow */
}
li:hover:last-child.menu-item {
box-shadow: -1px -1px 10px 4px rgba(0,0,0, 1) inset, /* dark shadow */
2px -2px 3px 0px rgba(255,255,255, 0.2), /* white - top */
2px 2px 3px 0px rgba(255,255,255, 0.2); /* white - bottom */
}
li:hover:first-child.menu-item {
box-shadow: -1px -1px 10px 4px rgba(0,0,0, 1) inset, /* dark shadow */
-2px -2px 3px 0px rgba(255,255,255, 0.2), /* white - top */
2px -2px 3px 0px rgba(255,255,255, 0.2), /* white - top */
2px 2px 3px 0px rgba(255,255,255, 0.2); /* white - bottom */
}
/******************************************************************************************/
/* Round corners */
/******************************************************************************************/
li:first-child.menu-item {
-moz-border-radius-bottomleft: 5px;
border-bottom-left-radius: 5px;
-moz-border-radius-topleft: 5px;
border-top-left-radius: 5px;
}
li:last-child.menu-item {
-moz-border-radius-bottomright: 5px;
border-bottom-right-radius: 5px;
-moz-border-radius-topright: 5px;
border-top-right-radius: 5px;
}
/******************************************************************************************/
/* Color palette */
/******************************************************************************************/
a {color: #0861a5;}
a:hover {color: #d98500;}
.menu li:hover>a,
.menu a {color: #dddddd;}
body {background-color: #b8d3e2;}
.menu li {background-color: #87a0af;}
.menu {font-family: Arial, Helvetica, sans-serif}
a {text-decoration: none;}
a, .menu li>a {
transition: 1.5s ease 0.2s;
-moz-transition: 1.5s ease 0.2s;
-webkit-transition: 1.5s ease 0.2s;
-o-transition: 1.5s ease 0.2s;
}
a:hover, .menu li, .menu li:hover>a {
transition: 0.4s ease 0.6s;
-moz-transition: 0.4s ease 0.6s;
-webkit-transition: 0.4s ease 0.6s;
-o-transition: 0.4s ease 0.6s;
}
ul, li, ol {
margin: 0;
padding: 0;
border: 0;
vertical-align: baseline;
}
ul {
margin: 100px 50px;
}
/* algemeen menu*/
.menu ul {
list-style-type: none;
}
.menu li {
display: inline;
}
</style>
If you want to make transitions with box-shadow, the elements of the box-shadow must make "pairs" and must match the "class" of the shadow.
Pixels and colors can be transitioned, keywords not.
Your base element is
.menu li {
box-shadow: 0 -9px 5px -5px rgba(0,0,0, 1) inset,
2px -2px 3px 0px rgba(255,255,255, 0.2),
2px 2px 3px 0px rgba(255,255,255, 0.2);
}
and you can transition correctly to this:
.menu li:hover {
box-shadow: -1px -1px 10px 4px rgba(0,0,0, 1) inset,
2px -2px 3px 0px rgba(255,255,255, 0.2),
2px 2px 3px 0px rgba(255,255,255, 0.2);
}
Because the first element is inset and both cases, and the other 2 aren't in both cases.
The last child is
li:last-child.menu-item {
box-shadow: -9px 0px 5px -5px rgba(0,0,0, 1) inset,
0px -9px 5px -5px rgba(0,0,0, 1) inset, /* PROBLEM HERE */
2px -2px 3px 0px rgba(255,255,255, 0.2),
2px 2px 3px 0px rgba(255,255,255, 0.2);
}
And the second element is inset and doesn't match the second in the hover that is not inset. THIS is the part that fails.
Once understood where the problems is there are several solutions. May be the easier is to set only 1 inset that has both x and y offsets:
li:last-child.menu-item {
box-shadow: -9px -9px 5px -5px rgba(0,0,0, 1) inset, /* combined shadows */
2px -2px 3px 0px rgba(255,255,255, 0.2),
2px 2px 3px 0px rgba(255,255,255, 0.2);
}
The result maybe isn't exactly the previous one, but that is transitionable

Resources