CSS3 horizontal fading shadow with certain stops?

So, I'm trying to use pure CSS to have a little dropshadow that lies above the tab. I want it to go out at the ends by 20% and 80%. I have been trying to achieve this for some time, but have not yet been satisfied with the results.

Here is an image of what I want to have:

Shadow tab

HTML:

<button type="button" class="btn">
    <span>Button Text</span>
    <span class="buttonshadow"></span>
</button>

CSS

.btn {
    -webkit-border-radius: 0px;
    -webkit-border-bottom-right-radius: 5px;
    -webkit-border-bottom-left-radius: 5px;
    -moz-border-radius: 0px;
    -moz-border-radius-bottomright: 5px;
    -moz-border-radius-bottomleft: 5px;
    border-radius: 0px;
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
    font-size: 24px;
    padding: 6px 16px 7px;
    line-height: 1;
    position: relative;
    color: #ffffff;
    background-color: #5CBCEC;
    border-color: #5CBCEC;
    display: inline-block;
    margin-bottom: 0;
    background-image: none;
    border: 1px solid transparent;
    white-space: nowrap;
    overflow: visible;
}
.buttonshadow {
    width: 120%;
    height: 100%;
    position: absolute;
    top: 0;
    left: -10%;
}
.buttonshadow:before {
    content: "";
    position: absolute;
    z-index: 1;
    top: -1px;
    left: 0;
    width: 100%;
    height: 5px;
    background: -webkit-radial-gradient(50% -3%, ellipse cover, rgba(00, 00, 00, 0.2), rgba(97, 97, 97, 0.0) 40%);
    background: radial-gradient(ellipse at 50% 0%, rgba(0, 0, 0, 0.4), rgba(97, 97, 97, 0) 70%);
}

Here is my current fiddle: JSFiddle

Clearly, this does not look the same. Any help is much appreciated!

+4
source share
3 answers

If I understand the problem correctly, you want the gradient to be outside the borders of the button.

the problem is .buttonshadowand.buttonshadow:before

I changed it to

.buttonshadow {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: -25px;
}
.buttonshadow:before {
    content: "";
    position: absolute;
    z-index: 1;
    top: -1px;
    left: 0;
    width: 130%;
    height: 5px;
    background: -webkit-radial-gradient(50% -3%, ellipse cover, rgba(00, 00, 00, 0.2), rgba(97, 97, 97, 0.0) 40%);
    background: radial-gradient(ellipse at 50% 0%, rgba(55, 55, 55, 1), rgba(97, 97, 97, 0) 80%);
}

Check script

http://jsfiddle.net/rLsbC/1/

, , . , !

. , .buttonshadow:before .buttonshadow

+3

, .

-

, , . .btn .

CSS

.btn:after {
    content: '';
    display: block;
    position: absolute;
    width: 120%;
    height: 5px;
    top: -2px;
    left: -10%;
    background: -webkit-radial-gradient(center, ellipse cover, rgba(0,0,0,0.45) 0%,rgba(0,0,0,0) 85%); 
}
+2

[me, ] Id , :before/:after ...

, - http://jsfiddle.net/rLsbC/3/

, Firefox , , . ( , .)

span ,

background: linear-gradient(to bottom, rgba(0, 0, 0, 0.4) 0%,
  rgba(97, 97, 97, 0) 100%);

:before/:after , . ,

background: -moz-radial-gradient(top right, ellipse cover, rgba(0, 0, 0, 0.4),
  rgba(97, 97, 97, 0) 50%);

span , , , , .

( , / ), , .

+1
source

Source: https://habr.com/ru/post/1529902/


All Articles