How do I combine CSS "text-shadow" and "background-image: -webkit-gradient" - html

I am trying to achieve a gradient + text shadow effect in Chrome/Safari using CSS text-shadow and a combination of text-shadow and background-image: -webkit-gradient, see example blw. I can only make one of the effects apply(if I add the shadow the gradient disappears. What am I doing wrong?
h1 {
font-size: 100px;
background-image: -webkit-gradient(linear, left top, left bottom, from(white), to(black));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
text-shadow: 0 1px 1px #fff;
}

The gradient "disappears" because the text-shadow is on a level above the background.
The text (which is transparent)
The shadow
The background.
We can work around this by copying the text and put it below the original layer, then apply the shadow there, for example:
h1 {
position: relative;
font-size: 100px;
text-align: center;
}
h1 div {
background-image: linear-gradient(white, black);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
position: absolute;
width: 100%;
}
h1:after {
text-shadow: 10px 10px 11px #fff;
color: transparent;
}
#hello:after {
content: 'Hello World';
}
<h1 id="hello"><div>Hello World</div></h1>

With no extra HTML markup or pseudo elements you can achieve this effect using the filter property and drop-shadow function. This method also works with a background image vs gradient.
h1 {
font:54px 'Open Sans', 'Helvetica', Arial, sans-serif;
background-image: linear-gradient(#787878, #484848);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
-webkit-filter: drop-shadow(2px 2px #333);
filter: drop-shadow(2px 2px #333);
}
Fiddle: https://jsfiddle.net/eywda89g/

This answer is similar to the answer by #KennyTM above, except his answer has the shadow hard-coded into the CSS, which is not suitable for dynamic text such as in a CMS. Also, his method requires a separate ID for each instance, which would be very tedious if you plan to use this effect a lot. The example below uses a class instead, and allows dynamic text.
Try this:
h1 {
position: relative;
font-size: 100px;
text-align: center;
}
h1 div {
background-image: linear-gradient(teal, black);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
position: absolute;
width: 100%;
}
h1:after {
text-shadow: 2px 2px 2px #000000;
color: transparent;
}
.gradient-shadow:after {
content: attr(title); /* Pulls the text from the 'title' attribute to make the shadow */
}
And then in your HTML:
<h1 class="gradient-shadow" title="Hello World"><div>Hello World</div></h1>
Just make sure that the text in the <div> matches the text in the title attribute.
Here is a Codepen example of this method:
https://codepen.io/mprewitt/pen/gexypd

These answers helped me a lot in getting to my final result. Thank you.
So I figured I would share it. Seeing the colour of my text is light, I needed a darker "border" at the top to make it pop.
Also while 'ems' are harder to work with (as opposed to px), I found that the transition of colours for the text-shadow looks a lot smoother as I wanted to make it a gradient as well :)
Works on Edge, Chrome, Vivaldi and FireFox, a little blurry though.
<h1 class="text3d">Privacy Policy</h1>
.text-3d{
background-image:linear-gradient(to bottom,#f7eb3b 30%,#f5d839 40%,#eead34 50%, #eb9531 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
filter:
drop-shadow(-0.015em -0.015em 0 #ffff00)
drop-shadow(-0.015em -0.015em 0 #bf290c)
drop-shadow(0 -0.005em 0 #bf290c)
drop-shadow(0.010em 0.025em 0 #bf290c)
drop-shadow(0.015em 0.030em 0 #b6240b)
drop-shadow(0.020em 0.035em 0 #a91d0b)
drop-shadow(0.025em 0.040em 0 #8d0d09)
drop-shadow(0.030em 0.045em 0 #830708)
drop-shadow(0.035em 0.050em 0 #680a07)
drop-shadow(0.01em 0.08em 0.01em rgba(0,0,0,0.10))
}

Related

Make Text transparent with border

I'm trying to display text (a number), which is displayed on a background image.
What I currently got is the following:
body {
background-image: url("https://i.picsum.photos/id/10/800/800.jpg");
background-repeat: no-repeat;
background-position: center;
width: 400px;
height: 400px;
}
#age {
/* 1 pixel black shadow to left, top, right and bottom */
text-shadow: 2px 0 0 #fff, -2px 0 0 #fff, 0 2px 0 #fff, 0 -2px 0 #fff, 1px 1px #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff;
font-family: sans;
color: transparent;
font-size: 40vw;
}
<h1 id="age">27</h1>
Basically, it works more or less as I want. However, the number itself is always filled with white color. What I would like though, is to have that number displayed huge there, have it filled with no color (transparent) and only use it with a border around the number itself. Later on, I want to upgrade to a counter, that visibly counts to the defined number first. However, the first step for me would be to display the number without the white fill.
Do you know any possible way to do this and only display a white border and have the background shine through for the rest?
There is an experimental -webkit-text-stroke CSS property, that does what you need (see this answer):
#age-container {
background-image: url("https://images.pexels.com/photos/68568/primula-catchfly-blossom-bloom-pink-68568.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
width: 400px;
height: 400px;
display: flex;
}
#age {
margin: auto;
-webkit-text-stroke: 10px white;
font-family: sans-serif;
color: transparent;
font-size: 250px;
}
<div id="age-container">
<h1 id="age">27</h1>
</div>
Another option would be to use a font that already looks the way you need it to (like these).
The issue in 2020 with:
text-stroke
text-stroke-width
text-stroke-color
text-fill-color
is that - despite having been around for over half a decade - these are still experimental properties and have never yet been added to any offical spec (either W3C or WHAT-WG).
That's why, even though text-stroke now has wide support from browsers, all browsers (including Firefox) only support text-stroke with the -webkit prefix:
-webkit-text-stroke
See: https://caniuse.com/#feat=text-stroke
Using the -webkit- browser vendor prefix may not be an issue for you.
But if it is, there is another way to visually display a text-stroke-outlined transparent number within:
<h1 id="age">27</h1>
and that's to apply an SVG image background to the <h1> element.
Working Example:
body {
display: flex;
justify-content: center;
align-items: flex-start;
}
#age {
position: relative;
font-family: sans-serif;
color: rgba(0, 0, 0, 0);
background-image: url("https://images.pexels.com/photos/1749/fire-orange-emergency-burning.jpg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
}
#age[data-age="27"]::after {
content: '';
position: absolute;
top: 0;
left: 0;
background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 400 400'><text x='204' y='320' text-anchor='middle' stroke='rgb(255, 255, 255)' stroke-width='6' fill='rgba(0, 0, 0, 0)' style='font: 320px sans-serif; font-weight: 700;'>27</text></svg>");
}
#age,
#age[data-age="27"]::after {
width: 400px;
height: 400px;
background-repeat: no-repeat;
background-position: center;
}
<h1 id="age" data-age="27">27</h1>

HTML Input Gradient Text

Been looking for a solution but no prevail, so I thought I'd ask here.
I am trying to apply a linear gradient to the input field as I have for the buttons as seen in this picture.
I have played around with different CSS options but have not been able to succeed.
The best version is where the placeholder is styled, but the input value is not. If I try to style the input value then things go wrong.
And advice would be greatly appreciated.
button{
background-color: dodgerblue;
height: 60px;
width: 60px;
border-radius: 50%;
font-size: 32px
}
button i{
background: -webkit-linear-gradient(#ffffff70, #ffffff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
input{
background-color: dodgerblue;
height: 60px;
width: 360px;
font-size: 32px
}
input::placeholder{
background: -webkit-linear-gradient(#ffffff70, #ffffff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
/*
input:focus {
background: -webkit-linear-gradient(#ffffff70, #ffffff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
*/
<button><i>X</i></button>
<hr />
<input placeholder="SEARCH"/>
You will need two background layer. One for the text and one for the background-color.
Unfortunately this won't work on Firefox due to known bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1571244
input {
background-color: dodgerblue;
color:transparent;
height: 60px;
width: 360px;
font-size: 32px
}
input::placeholder {
background: linear-gradient(#ffffff70, #ffffff);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
}
input:not(:placeholder-shown) {
background:
linear-gradient(#ffffff70, #ffffff),
dodgerblue;
-webkit-background-clip: text, padding-box;
background-clip: text, padding-box;
-webkit-text-fill-color: transparent;
}
<input placeholder="SEARCH">
For firefox you can consider an extra div for the background:
input {
color:transparent;
height: 60px;
width: 360px;
font-size: 32px;
background: linear-gradient(#ffffff70, #ffffff);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
}
.input {
display:inline-block;
background-color: dodgerblue;
}
<div class="input"><input placeholder="SEARCH"></div>
if your trying to set a gradient on the placeholder text,
your best option is to omit or remove the placeholder completely and set another div over the top of the input with your chosen font, and the text gradient.
<div id="InpCont">
<input type="text" id="UsrInp">
<div id="InpOverlay">
<p id="PsudoPlcHlder" class="OverlayTxt" contenteditable="true" onchange="PsudoPlcHlder.value=UsrInp.value" max-length="44">Search</p>
</div>
</div>
#InpCont{
// Position Where you want this element
}
#UsrInp{
position:absolute;
top:8px; left:50%;
transform:translateX(-50%);
width:64%; height:calc(28px + 1.87vh);
background:linear-gradient(-33deg,#ffffff70, #ffffff);
z-index:20;
}
#PsudoPlcHlder{
position:relative;
top:-40px; left:calc(20px + 25%);
width:240px; height:29px; padding:2px;
background:linear-gradient(23deg,red,green,blue);
overflow-x:hidden;
background-clip:text;
color:transparent;
z-index:25;
}
(document.addEventListener('DOMContentLoaded', function(){
const UsrInp = document.getElementById('UsrInp');
const PsudoPlcHlder = document.getElementById('PsudoPlcHlder');
PsudoPlcHlder.addEventListener('click', (function(){
PsudoPlcHlder.innerText = '';
}))
})
Just tried this on my own app and it seems to be working, but i'm not sure about the form submission part as I haven't got it hooked up to a db at the moment, might have to play around with the positioning a bit as I only tested this at the very bottom of my app, but might be a good starting point for you to mess around with.
in testing this, the gradient seems to stretch to fit, however many characters there are even if there like 120, which is a bit weird. will play around with this more and edit later on if I find any better methods..

Text goes behind gradient

Im still making a reponsive menu, with scroll controls. I added a gradient on my menu, but I want to, that gradient goes in front of my links and hide them behind it. There's is JSFiddle, you can test it.
There you can see my gradient CSS on my menu
#page .page-nav {
background: white -webkit-linear-gradient(left, transparent 50px, red);
background-size: 40% 100%;
background-repeat: no-repeat;
background-position: right;
}
Any solutions, how to do that?
As far as I know,
You can do it with vendor prefixes and it's not supported in IE (even IE 11)
Unless someone here knows a better way to implement it, I would advise against this.
body {
background: #111;
width: 50%;
margin: 0 auto;
font-size: 50px
}
.page-nav {
background: linear-gradient(to right, #900, #999);
-webkit-background-clip: text;
-moz-background-clip: text;
-webkit-text-fill-color: transparent;
-moz-text-fill-color: transparent;
}
<body>
<p class="page-nav">Sample Sample</p>
</body>

CSS with a 2 gradient button?

Below is an image of a button we use on our site, it's a .png.
We'd like to see if we can get really close to it with CSS on a standard button.
The gradient goes top: #E14C5B to middle: #D33742 to bottom: #B61C27 with a couple pixel radial of round corners.
Is that even possible in CSS?
I'll get ya started...
HTML
<button>Submit</button>
CSS with some background gradients
#import url(http://fonts.googleapis.com/css?family=Pathway+Gothic+One);
button {
font-family: 'Pathway Gothic One', sans-serif;
font-size: 1.5em;
text-shadow: 1px 1px rgba(0, 0, 0, 0.5);
border: 1px solid transparent;
border-radius: 3px;
height: 50px;
width: 100px;
color: white;
background-repeat: repeat-x;
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#E14C5B), color-stop(0.5, #D33742), to(#B61C27));
box-shadow: 1px 1px 1px 1px rgba(0, 0, 0, 0.25);
cursor: pointer;
}
DEMO
Screenshot:
If you want some kind of clicky feedback type look on click, you could also add:
button:active {
-webkit-transform: translate(1px, 1px);
box-shadow: none;
}
DEMO w/ :active
This is only prefixed for -webkit browsers. You'll need to provide the proper vendor prefixes for whatever you are supporting.
Here is the cross-browser version using css gradient.
I specified 4 colors for the gradient.
The first gradient from 0 to 50% and the second gradient from 51% to 100%.
Ex.
background: linear-gradient(to bottom, #f64757 0%,#f83b49 50%,#eb2735 51%,#ce0011 100%);
jsfiddle demo here
Please note that the red i took are brighter than in tour example.
Just play with the css to adjust colors that fit your needs.

Text Pattern Overlay

I would like to overlay a text with pattern.
current text:
desired result:
Here is what I tried:
<p style="background: url(http://i.imgur.com/kODqYvS.jpg);>International experiance</p>
Direct link to pattern picture:
http://i.imgur.com/kODqYvS.jpg
Here you go, exactly how you wanted it: DEMO
<p class="bnd">International experiance</p>
.bnd
{
font-size: 48px;
font-weight: bold;
background: url(http://i.imgur.com/kODqYvS.jpg);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
Fiddle
h1{color: white; /* Fallback: assume this color ON TOP of image */
background: url(http://i.imgur.com/kODqYvS.jpg) ;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;}