Is there a possibilty to combine text gradient with box shadow?
See example-image to understand what exactly I want to achive.Example-Image
I've achived the Gradient, but the box shadow I added after, appears in foreground.
How can I solve that?
h2 {
display: inline-block;
background-image:linear-gradient(90deg,#c93718 0%,#035b34 30%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
box-shadow: inset 0px 30px white;
}
Would love to get some help!
Thank's!
(I'm sorry for my english)
You can try multiple background:
h2 {
display: inline-block;
font-size:50px;
color:transparent;
background-image:
linear-gradient(90deg,#c93718 0%,#035b34 30%),
linear-gradient(#ccc,#ccc);
-webkit-background-clip:
text,
padding-box;
background-clip:
text,
padding-box;
-webkit-text-fill-color: transparent;
}
<h2>A title here</h2>
This won't work on Firefox due to a know bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1571244
As an alternative for Firefox, consider pseudo element:
h2 {
display: inline-block;
font-size: 50px;
color: transparent;
background-image: linear-gradient(90deg, #c93718 0%, #035b34 30%);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
position: relative;
}
h2::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: -1;
background: #ccc;
}
<h2>A title here</h2>
Try adding a div and then you can play around with position will solve your issues.
h2 {
display: inline-block;
background-image:linear-gradient(90deg,#c93718 0%,#035b34 30%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
z-index: 999999;
position: absolute;
}
div{
background-color: gray;
height: 30px;
width: 140px;
position: absolute;
top: 22px;
}
<h2>This is Demo</h2>
<div></div>
Related
I am trying to achieve the below design! I have managed to achieve the border radius with gradient border but if i try to use -webkit-background-clip & -webkit-text-fill-color for gradient text then the border radius doesn't work and the whole button gets the gradient color.
I am using this as reference for gradient text and attaching the code for gradient border
.btn {
background-image: linear-gradient(to right, #006175 0%, #00a950 100%);
border-radius: 40px;
box-sizing: border-box;
color: #00a84f;
display: block;
font: 1.125rem 'Oswald', Arial, sans-serif;
/*18*/
height: 80px;
letter-spacing: 1px;
margin: 0 auto;
padding: 4px;
position: relative;
text-decoration: none;
text-transform: uppercase;
width: 264px;
z-index: 2;
}
.btn:hover {
color: #fff;
}
.btn span {
align-items: center;
background: #e7e8e9;
border-radius: 40px;
display: flex;
justify-content: center;
height: 100%;
transition: background .5s ease;
width: 100%;
}
.btn:hover span {
background: transparent;
}
<a class="btn" href="#">
<span>Click Here!</span>
</a>
Any kind of help would be greatly appreciated! Please feel free to give some suggestions. TIA
I will consider this previous answer to build the rounded gradient using pseudo element so that you can use background-clip:text on the main element. I have used the mask version by you can also consider the SVG one:
.btn {
--r:40px; /* radius */
--b:5px; /* border width */
background: linear-gradient(to right, #006175 0%, #00a950 100%);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
color: transparent;
border-radius: var(--r);
display: flex;
align-items: center;
justify-content: center;
font: 1.5rem 'Oswald', Arial, sans-serif;
height: 80px;
margin: 0 auto;
position: relative;
z-index:0;
text-decoration: none;
width: 264px;
}
/* check lined question for the detail of the below code */
.btn::before {
content:"";
position:absolute;
z-index:-1;
inset: 0;
border: var(--b) solid transparent;
border-radius: var(--r);
background: inherit;
background-origin: border-box;
background-clip: border-box;
-webkit-mask:
linear-gradient(#fff 0 0) padding-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
-webkit-mask-repeat: no-repeat;
}
/**/
.btn:hover {
color: #fff;
-webkit-text-fill-color: #fff;
-webkit-background-clip: border-box;
background-clip: border-box;
}
.btn:hover::before {
-webkit-mask:none;
}
body {
background:pink;
}
<a class="btn" href="#">
Click Here!
</a>
I got this answer from another post and it worked out for me:
border-bottom: 6px solid transparent;
border-image: linear-gradient(to right, red , yellow);
border-image-slice: 1;
and from my experience, I would use &:after to insert &:hover options to the desired hover effects.
Here is a shadow:
So I need this to be a shadow which appears on button hover. I know its css but I didn't manage to make any blur:
background-image: linear-gradient(-90deg, #CF77F3 0%, #009BFF 47%, #2AC9DB 100%);
border-radius: 100px;
filter: blur(5px);
So, two basic questions:
Is it possible to make this blurred thing with CSS?
If yes, is it possible to make it a button shadow? Or how else can I solve this? One thought was to just make a png with absolute positioning, which is hacky a bit
update
So the final result I want achieve looks something like this:
The shadow repeats button gradient which is
linear-gradient(-90deg, #CF77F3 0%, #009BFF 47%, #2AC9DB 100%);
New answer
I have made an online generator that helps you get a gradient shadow easily: https://css-generators.com/gradient-shadows/
All you have to do is to adjust a few values and get the code:
button {
margin: 50px;
border-radius: 999px;
padding: 10px 30px;
font-size: 25px;
color: #fff;
text-align: center;
line-height: 50px;
border: none;
background: linear-gradient(-90deg, #CF77F3 0%, #009BFF 47%, #2AC9DB 100%);
position: relative;
transform-style: preserve-3d;
}
button::before {
content: "";
position: absolute;
inset: -10px;
background: inherit;
filter: blur(20px);
transform: translate3d(15px,15px,-1px);
border-radius: inherit;
pointer-events: none;
}
<button >
this a button
</button>
More detail: https://css-tricks.com/different-ways-to-get-css-gradient-shadows/
Old answer
What about multiple box-shadow:
.box {
margin:50px;
width:100px;
height:50px;
border-radius:20px;
color:#fff;
text-align:center;
line-height:50px;
box-shadow:
20px 5px 40px #CF77F3,
0px 5px 40px #009BFF,
-20px 5px 40px #2AC9DB;
background-image: linear-gradient(-90deg, #CF77F3 0%, #009BFF 47%, #2AC9DB 100%);
}
<div class="box">
this a button
</div>
You can get this effect in modern browsers using a pseudo element with the same background, and a filter blur applied on it.
To get compatibility with IE, you can set also a pseudo, and to get the blurred borders use an inset shadow. At least in Chrome, there is a small left over of the border that still can be seen.
.test {
margin: 20px;
background-image: linear-gradient(-90deg, #CF77F3 0%, #009BFF 47%, #2AC9DB 100%);;
border-radius: 50px;
display: inline-block;
height: 100px;
width: 200px;
position: relative;
border: solid 4px black;
}
#test1:after {
content: "";
position: absolute;
background-image: inherit;
border-radius: inherit;
width: inherit;
height: inherit;
transform: translate(0px, 20px) scale(1.1);
z-index: -1;
filter: blur(14px);
}
#test2:after {
content: "";
position: absolute;
border-radius: 90px;
width: 250px;
height: 150px;
z-index: -1;
top: 1px;
left: -25px;
background-image: linear-gradient(-90deg, #CF77F3 0%, #009BFF 47%, #2AC9DB 100%);
box-shadow: inset 0px 0px 25px 18px white;
}
<div class="test" id="test1">
</div>
<div class="test" id="test2">
</div>
I add a ":after" element to all links (simulate a "border-bottom") so on ":hover" i can animate this pseudo element ("height: 100%"). This works fine, but when the link is split with a line-break the pseudo element is broken after the line break.
a {
color: red;
position: relative;
text-decoration: none;
&:after {
transition: height .1s;
background-color: red;
bottom: -3px;
content: '';
display: inline;
height: 3px;
left: 0;
right: 0;
position: absolute;
width: 100%;
z-index: -1;
}
&:hover:after {
height: calc(100% + 4px);
}
&:hover {
color: white;
}
}
Here is a pen:
http://codepen.io/herrfischer/pen/YWKmQJ
Any idea what I am doing wrong?
For an inline element, background will be more efficient: http://codepen.io/gc-nomade/pen/pbzMYP
a {
color: red;
position: relative;
text-decoration: none;
background:linear-gradient(red,red) bottom repeat-x;
background-size:3px 3px;
transition:1s;
&:hover {
background-size:100% 100%;
color: white;
}
}
Stolen from another site - it works with animated background gradient :)
a {
background-image: linear-gradient(red 0%, red 100%);
background-position: bottom;
background-repeat: repeat-x;
background-size: 0 0;
border-bottom: 3px solid red;
color: red;
position: relative;
text-decoration: none;
transition: 150ms ease;
&:hover {
color: white;
background-size: 1em 1.5em;
}
}
Updated the pen.
I need to do a triangular onfocus on button, like on this image
I looked at different examples like this, but the focus zone is rectangular.
Is it possible make triangular onfocus?
You could use clip-path to give a triangular shape to the button and apply the same shape to button::before pseudoelement slightly enlarged to mimic an outline, e.g.
Codepen Demo
Note: working only on browser supporting clip-path
Markup
<button><span>button</span></button>
CSS
button {
position: relative;
border: 0;
padding: 0;
cursor: pointer;
-webkit-clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 50% 100% 0);
clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 50% 100% 0);
}
button span {
position: relative;
z-index: 1;
display: block;
background: linear-gradient(#f4f4f4, #d4d4d4);
padding: 10px 20px;
}
button:focus {
outline: none;
-webkit-clip-path: polygon(0 0, 0 100%, 90% 100%, 100% 50%, 90% 0);
clip-path: polygon(0 0, 0 100%, 90% 100%, 100% 50%, 90% 0);
}
button::before,
button span {
-webkit-clip-path: inherit;
clip-path: inherit;
}
button:focus::before {
content: "";
position: absolute;
height: calc(100% + 4px);
width: calc(100% + 4px);
left: -2px;
top: -2px;
background: rgba(81,153,219, .7);
}
Maybe like this?
Adding an element after the button to provide the triangular shape...
Now it is 45° rotation, you could play by skewing to get another angle.
CodePen Sample
button:hover { border-color: blue; }
button:hover:after { border-color: blue;}
button {
font-size: 14px;
background: none;
border: 1px solid red;
border-right: 0;
position: relative;
height: 44px;
z-index: 1;
background-color: #FFF;
}
button::after {
content: "";
display: block;
position: absolute;
width: 30px; height: 30px;
background: #FFF;
right: -15px;
top: 5px;
transform: rotate(-45deg);
z-index:-1;
border-right: 1px solid Red;
border-bottom: 1px solid Red;
}
You could use the map tag : http://www.w3schools.com/tags/tag_map.asp
But in that case your button must be a picture.
little late,
but you can do for almost every browser with transform and a pseudo.
Eventually add background gradient and shadow : http://codepen.io/gc-nomade/pen/yOjOby
* {
box-sizing: border-box;
}
a {
display: inline-block;
padding: 0.5em 1em;
margin: 0 1.5em 0 0;
text-decoration: none;
color: #177EE5;
border: solid 3px;
border-radius: 5px;
border-right: none;
position: relative;
background: linear-gradient(to right, lightgray, white, lightgray);
box-shadow: 0 0 5px black;
}
a:after {
content: '';
position: absolute;
top: 3px;
bottom: 3px;
right: -.8em;
width: 1.75em;
border-radius: inherit;
border-top: solid;
border-right: solid;
border-color: inherit;
transform: rotate(45deg);
background: linear-gradient(45deg, transparent 45%, lightgray 60%);
box-shadow: 0px -5px 5px -5px black, 5px 0px 5px -5px black
}
arrow
longer arrow
#
you can use this site and make triangular, polygon: The Shapes of CSS - CSS-Tricks
https://css-tricks.com/examples/ShapesOfCSS
make a css class. add that class on focus.
http://www.w3schools.com/jquery/html_addclass.asp
Is it possible to create two arrows like the photo below with css or I have to use a png or svg?
So far
HTML
a {
position: relative;
display: block;
padding-left: 30px;
line-height: 45px;
height: 45px;
}
a:after,
a:before {
right: 100%;
top: 26px;
border-left: 1px solid black;
content: " ";
height: 30px;
width: 25px;
position: absolute;
pointer-events: none;
left: 7px;
}
a:after {
-webkit-transform: rotate(135deg);
left: -11px;
}
a:before {
-webkit-transform: rotate(45deg);
top: 5px;
}
Next
jsfiddle
I can't figure how to put another pair of borders.
Thanks in advance
With a bit of tinkering of your example, it's possible, but you'd probably be better off using another method to draw it or using an icon or icon font.
Here's the fiddle
Achieved with
transform: skew();
rather than rotate.
It's possible, but I would just use a SVG in this case:
http://jsfiddle.net/6v7Np/
HTML
<div class="arrow_box"></div>
<div class="arrow_box alt"></div>
CSS
.arrow_box {
position: relative;
background: #fff;
top:50px;
left:60px;
}
.arrow_box.alt {
left:80px;
}
.arrow_box:after, .arrow_box:before {
right: 100%;
top: 50%;
border: solid transparent;
content:" ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.arrow_box:after {
border-color: rgba(255, 255, 255, 0);
border-right-color: #fff;
border-width: 30px;
margin-top: -30px;
}
.arrow_box:before {
border-color: rgba(0, 0, 0, 0);
border-right-color: #000;
border-width: 31px;
margin-top: -31px;
}
With gradients:
a{
position: relative;
padding-left: 40px;
}
a::before{
content: '';
position: absolute;
width: 40px;
height: 40px;
left: 0;
top: 0;
background-image:
linear-gradient(135deg, transparent 0px, transparent 19px, black 20px, transparent 21px),
linear-gradient(45deg, transparent 0px, transparent 19px, black 20px, transparent 21px),
linear-gradient(135deg, transparent 0px, transparent 19px, black 20px, transparent 21px),
linear-gradient(45deg, transparent 0px, transparent 19px, black 20px, transparent 21px);
background-repeat: no-repeat;
background-size: 50% 50%;
background-position: 0% top, 0% bottom, 50% top, 50% bottom;
/* distance ^ ^ */
}
http://jsfiddle.net/E8sRw/