I am attempting to style some text, with white text and a black stroke. I want it to have a thick stroke while still having the text be visible.
For this, I used the following CSS:
element {
-webkit-text-stroke: 6px black;
color: white;
paint-order: stroke;
}
However, paint-order does not function properly on Chrome browsers. Here is a demonstration, Firefox on the left and Chrome on the right. You can see on the right that Chrome is not honoring the paint-order attribute, despite supposedly being compatible since version 35.
The CodeSandbox I made to demonstrate.
Is there some additional attribute needed for this to work on all browsers? My Chrome version is 80.0.3987.132 and Firefox is 74.0.
Chrome only supports paint-order on SVG text. There is no support for HTML text, although it could be supported in the future since it's supported in Firefox and Safari. In the meantime you can use text-shadow as a fallback for Chrome and older browsers.
Related ticket: https://bugs.chromium.org/p/chromium/issues/detail?id=815111
edit to anyone falling here , text-shadow is still the fallback to use for HTML/CSS and IE11, but FF,Chrome and edge will apply it to your SVG.
-webkit-text-stroke, is non-standard and off standards track, where IE11 also fails .
original answer
Does your browser supports paint-order ?
check it here : https://caniuse.com/#feat=mdn-css_properties_paint-order
you can use many text-shadow to get the blur effect finally looking alike a stroke effect as a possible alternative:
demo of the idea that's worth what it is:
h1, h2 {
color:white;
text-shadow: 0 0 3px black, 0 0 3px black, 0 0 3px black, 0 0 3px black, 0 0 3px black,0 0 3px black, 0 0 3px black, 0 0 3px black, 0 0 3px black, 0 0 3px black,0 0 3px black, 0 0 3px black, 0 0 3px black, 0 0 3px black, 0 0 3px black,0 0 3px black, 0 0 3px black, 0 0 3px black, 0 0 3px black, 0 0 3px black;
letter-spacing:4px;
}
/* dummy demo */
h2 {
text-shadow:
0 0 2px blue,0 0 2px blue,0 0 2px blue,0 0 2px blue,0 0 2px blue,
0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white, 0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white, 0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white, 0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,0 0 4px white,
0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson,0 0 6px crimson;
}
<h1>Hello The World</h1>
<h2>Hello The World</h2>
If you want to implement this average text-shadow stroking only where paint-order is not implemented, #supports could be usefull https://developer.mozilla.org/en-US/docs/Web/CSS/#supports / https://caniuse.com/#feat=css-featurequeries
Related
I tried to make a "text border" with CSS text-shadow. Finally there are 121 shadows:
text-shadow:
-5px -5px 0 var(--grau_dunkel),-4px -5px 0 var(--grau_dunkel),-3px -5px 0 var(--grau_dunkel),-2px -5px 0 var(--grau_dunkel),-1px -5px 0 var(--grau_dunkel),0 -5px 0 var(--grau_dunkel),1px -5px 0 var(--grau_dunkel),2px -5px 0 var(--grau_dunkel),3px -5px 0 var(--grau_dunkel),4px -5px 0 var(--grau_dunkel),5px -5px 0 var(--grau_dunkel),
-5px -4px 0 var(--grau_dunkel),-4px -4px 0 var(--grau_dunkel),-3px -4px 0 var(--grau_dunkel),-2px -4px 0 var(--grau_dunkel),-1px -4px 0 var(--grau_dunkel),0 -4px 0 var(--grau_dunkel),1px -4px 0 var(--grau_dunkel),2px -4px 0 var(--grau_dunkel),3px -4px 0 var(--grau_dunkel),4px -4px 0 var(--grau_dunkel),5px -4px 0 var(--grau_dunkel),
-5px -3px 0 var(--grau_dunkel),-4px -3px 0 var(--grau_dunkel),-3px -3px 0 var(--grau_dunkel),-2px -3px 0 var(--grau_dunkel),-1px -3px 0 var(--grau_dunkel),0 -3px 0 var(--grau_dunkel),1px -3px 0 var(--grau_dunkel),2px -3px 0 var(--grau_dunkel),3px -3px 0 var(--grau_dunkel),4px -3px 0 var(--grau_dunkel),5px -3px 0 var(--grau_dunkel),
-5px -2px 0 var(--grau_dunkel),-4px -2px 0 var(--grau_dunkel),-3px -2px 0 var(--grau_dunkel),-2px -2px 0 var(--grau_dunkel),-1px -2px 0 var(--grau_dunkel),0 -2px 0 var(--grau_dunkel),1px -2px 0 var(--grau_dunkel),2px -2px 0 var(--grau_dunkel),3px -2px 0 var(--grau_dunkel),4px -2px 0 var(--grau_dunkel),5px -2px 0 var(--grau_dunkel),
-5px -1px 0 var(--grau_dunkel),-4px -1px 0 var(--grau_dunkel),-3px -1px 0 var(--grau_dunkel),-2px -1px 0 var(--grau_dunkel),-1px -1px 0 var(--grau_dunkel),0 -1px 0 var(--grau_dunkel),1px -1px 0 var(--grau_dunkel),2px -1px 0 var(--grau_dunkel),3px -1px 0 var(--grau_dunkel),4px -1px 0 var(--grau_dunkel),5px -1px 0 var(--grau_dunkel),
-5px 0 0 var(--grau_dunkel),-4px 0 0 var(--grau_dunkel),-3px 0 0 var(--grau_dunkel),-2px 0 0 var(--grau_dunkel),-1px 0 0 var(--grau_dunkel),1px 0 0 var(--grau_dunkel),2px 0 0 var(--grau_dunkel),3px 0 0 var(--grau_dunkel),4px 0 0 var(--grau_dunkel),5px 0 0 var(--grau_dunkel),
-5px 1px 0 var(--grau_dunkel),-4px 1px 0 var(--grau_dunkel),-3px 1px 0 var(--grau_dunkel),-2px 1px 0 var(--grau_dunkel),-1px 1px 0 var(--grau_dunkel),0 1px 0 var(--grau_dunkel),1px 1px 0 var(--grau_dunkel),2px 1px 0 var(--grau_dunkel),3px 1px 0 var(--grau_dunkel),4px 1px 0 var(--grau_dunkel),5px 1px 0 var(--grau_dunkel),
-5px 2px 0 var(--grau_dunkel),-4px 2px 0 var(--grau_dunkel),-3px 2px 0 var(--grau_dunkel),-2px 2px 0 var(--grau_dunkel),-1px 2px 0 var(--grau_dunkel),0 2px 0 var(--grau_dunkel),1px 2px 0 var(--grau_dunkel),2px 2px 0 var(--grau_dunkel),3px 2px 0 var(--grau_dunkel),4px 2px 0 var(--grau_dunkel),5px 2px 0 var(--grau_dunkel),
-5px 3px 0 var(--grau_dunkel),-4px 3px 0 var(--grau_dunkel),-3px 3px 0 var(--grau_dunkel),-2px 3px 0 var(--grau_dunkel),-1px 3px 0 var(--grau_dunkel),0 3px 0 var(--grau_dunkel),1px 3px 0 var(--grau_dunkel),2px 3px 0 var(--grau_dunkel),3px 3px 0 var(--grau_dunkel),4px 3px 0 var(--grau_dunkel),5px 3px 0 var(--grau_dunkel),
-5px 4px 0 var(--grau_dunkel),-4px 4px 0 var(--grau_dunkel),-3px 4px 0 var(--grau_dunkel),-2px 4px 0 var(--grau_dunkel),-1px 4px 0 var(--grau_dunkel),0 4px 0 var(--grau_dunkel),1px 4px 0 var(--grau_dunkel),2px 4px 0 var(--grau_dunkel),3px 4px 0 var(--grau_dunkel),4px 4px 0 var(--grau_dunkel),5px 4px 0 var(--grau_dunkel),
-5px 5px 0 var(--grau_dunkel),-4px 5px 0 var(--grau_dunkel),-3px 5px 0 var(--grau_dunkel),-2px 5px 0 var(--grau_dunkel),-1px 5px 0 var(--grau_dunkel),0 5px 0 var(--grau_dunkel),1px 5px 0 var(--grau_dunkel),2px 5px 0 var(--grau_dunkel),3px 5px 0 var(--grau_dunkel),4px 5px 0 var(--grau_dunkel),5px 5px 0 var(--grau_dunkel);
Is this generally bad, are there too many shadows or does it work anyways?
This is not forbidden by the specification, some people would tell you that this code is unreadable, so you should consider generating such construction automatically using tools like LESS or SASS if you want code looking good.
What about performance issues, I'd avoid that if animations are involved (even those achieved by combining scrolling with things like vh dimensions or poisition:fixed) but it should be perfectly fine if the text does not need to be re-rendered while the page is opened.
It may need checking in practice thou if it impacts the site in your case or not as it is hard to tell in a general case. Test especially how it behaves in Firefox as Chrome seems to optimize such things better, so FF may be the bottleneck.
#-webkit-keyframes neon {
from {
-webkit-box-shadow: 0 0 1px #fff, 0 0 2px #fff, 0 0 4px #fff, 0 0 5px #FF1177, 0 0 6px #FF1177, 0 0 9px #FF1177, 0 0 11px #FF1177, 0 0 14px #FF1177;
}
to {
-webkit-box-shadow: 0 0 1px #fff, 0 0 2px #fff, 0 0 4px #fff, 0 0 5px #FF9900, 0 0 6px #FF9900, 0 0 9px #FF9900, 0 0 11px #FF9900, 0 0 14px #FF9900 inset;
}
}
#-moz-keyframes neon {
from {
-webkit-box-shadow: 0 0 1px #fff, 0 0 2px #fff, 0 0 4px #fff, 0 0 5px #FF1177, 0 0 6px #FF1177, 0 0 9px #FF1177, 0 0 11px #FF1177, 0 0 14px #FF1177;
}
to {
-webkit-box-shadow: 0 0 1px #fff, 0 0 2px #fff, 0 0 4px #fff, 0 0 5px #FF9900, 0 0 6px #FF9900, 0 0 9px #FF9900, 0 0 11px #FF9900, 0 0 14px #FF9900 inset;
}
}
#-o-keyframes neon {
from {
-webkit-box-shadow: 0 0 1px #fff, 0 0 2px #fff, 0 0 4px #fff, 0 0 5px #FF1177, 0 0 6px #FF1177, 0 0 9px #FF1177, 0 0 11px #FF1177, 0 0 14px #FF1177;
}
to {
-webkit-box-shadow: 0 0 1px #fff, 0 0 2px #fff, 0 0 4px #fff, 0 0 5px #FF9900, 0 0 6px #FF9900, 0 0 9px #FF9900, 0 0 11px #FF9900, 0 0 14px #FF9900 inset;
}
}
#keyframes neon {
from {
-webkit-box-shadow: 0 0 1px #fff, 0 0 2px #fff, 0 0 4px #fff, 0 0 5px #FF1177, 0 0 6px #FF1177, 0 0 9px #FF1177, 0 0 11px #FF1177, 0 0 14px #FF1177;
}
to {
-webkit-box-shadow: 0 0 1px #fff, 0 0 2px #fff, 0 0 4px #fff, 0 0 5px #FF9900, 0 0 6px #FF9900, 0 0 9px #FF9900, 0 0 11px #FF9900, 0 0 14px #FF9900 inset;
}
}
.deallinkactive {
display: inline;
float: right;
width: 508px;
padding: 5px;
font-size: 14px;
margin: 10px 10px 8px 8px;
border: 1.5px solid rgba(173, 38, 38, 0.541176);
-webkit-border-radius: 3px;
border-radius: 3px;
color: rgba(0, 0, 0, 1);
background: #ecf0f1;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease;
-webkit-animation: neon2 .2s ease-in-out infinite alternate;
-moz-animation: neon2 .2s ease-in-out infinite alternate;
animation: neon2 .2s ease-in-out infinite alternate;
}
The Box shadow animation is perfectly working on Chrome and Mobiles but not on IE and Firefox. I have tried -webkit-box-shadow , box-shadow , moz-box-shadow and all the things I found on internet. If I replace text-shadow in box-shadow, text-shadow works. Help!!
First of all, your class .deallinkactive is pointing to a wrong keyframe, it says neon2, change that to neon. then remove -webkit- from all -webkit-box-shadow. Finally, #keyframes not supported in an inline or scoped stylesheet in Firefox bug 830056.
But you have an alternate:
#keyframes neon {
0% {
-webkit-box-shadow: 0px 0px 12px 0px rgba(255,17,120,1);
-moz-box-shadow: 0px 0px 12px 0px rgba(255,17,120,1);
box-shadow: 0px 0px 12px 0px rgba(255,17,120,1);
}
100% {
-webkit-box-shadow: 0px 0px 12px 0px rgba(255,153,0,1);
-moz-box-shadow: 0px 0px 12px 0px rgba(255,153,0,1);
box-shadow: 0px 0px 12px 0px rgba(255,153,0,1);
}
}
.deallinkactive {
display: block;
float: right;
width: 508px;
padding: 5px;
font-size: 14px;
margin: 10px 10px 8px 8px;
border: 1.5px solid rgba(173, 38, 38, 0.541176);
-webkit-border-radius: 3px;
border-radius: 3px;
color: rgba(0, 0, 0, 1);
background: #ecf0f1;
transition: all 0.5s ease;
animation: neon .2s ease-in-out infinite alternate;
}
Fiddle example
It works on modern browsers (chrome, firefox, safari, IE10+). Hope it helps.
Tip: try generating box-shadow using cssmatic.com/box-shadow
You have to use moz for firefox
-webkit-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
Try box shadow generator in css3
http://www.cssmatic.com/box-shadow
I would like to add a white background to my letters.
I have an image as example, but I would like to build this image with CSS.
To see the difference, edit html with editor and add black as body background.
I have tried this with text-shadow, but it didn't work great.
My question is how can I build this with css?
Kind regards,
Itouch
I believe that text-shadow is the only way to go.
something like :
text-shadow: -1px 0 #fff, 0 1px #fff, 1px 0 #fff, 0 -1px #fff
Demo : http://codepen.io/mbrillaud/pen/zGxdMQ
I have a solution which is not really answering your question but still it might help (i hope).
You can make use of SVG and stroke-linejoin.
<svg height="100" width="250">
<text
x="0"
y="50"
fill="red"
stroke="#ffffff"
stroke-width="3px"
font-size="50px"
letter-spacing="-4"
stroke-linejoin="round"
stroke-linecap="round"
font-weight="600">I love SVG!</text>
</svg>
JSBIN: http://jsbin.com/zemeya/2/edit?html,css,output
Edit: I changed the font to be more funky adding this line between head tags.
<link href='http://fonts.googleapis.com/css?family=Indie+Flower' rel='stylesheet' type='text/css'>
It's a combination of text-shadow and letter-spacing.
First of all you need to get a solid "border" around your text.
For that use this:
text-shadow:-1px 0 #fff, 0 1px #fff, 1px 0 #fff, 0 -1px #fff,
-2px 0 #fff, 0 2px #fff, 2px 0 #fff, 0 -2px #fff
But that's not all. As there is another shadow which is kinda blurry you have to add another text-shadow:
text-shadow:-1px 0 #fff, 0 1px #fff, 1px 0 #fff, 0 -1px #fff,
-2px 0 #fff, 0 2px #fff, 2px 0 #fff, 0 -2px #fff,
2px 2px 3px #000;
Now you may remove some letter-spacing. You can do this by use a nagative value for it:
letter-spacing: -6px;
#import url(http://fonts.googleapis.com/css?family=Chewy);
span {
font-family: 'Chewy', cursive;
letter-spacing: -6px;
font-size:50px;
color:#555;
text-shadow:-1px 0 #fff,
0 1px #fff,
1px 0 #fff,
0 -1px #fff,
-2px 0 #fff,
0 2px #fff,
2px 0 #fff,
0 -2px #fff,
2px 2px 3px #000;
}
<span>home</span>
Demo
You can play with text-shadow property, but than you would have to stack values to achieve thicker stroke this way:
body {
background-color: #ddd;
}
p {
font-size: 52px;
color: #666666;
text-shadow: 0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,0 0 3px #fff,
4px 4px 6px #000, 4px 4px 6px #000;
}
<p>home</p>
Also on codepen.
You can do a colored outline on text by using the text-shadow in CSS. The trick is you have to do multiple shadows:
.white_background {
text-shadow: 0px 0px 1px #fff,
0px 0px 1px #fff,
0px 0px 1px #fff,
0px 0px 1px #fff;
}
CSS supports multiple listings of text-shadow. Each listing stacks with the others. If you stack up enough, they give the appearance of a solid outline.
at the rounded corner, it has crisp edge, is this normal?
-moz-box-shadow: inset 0 0 0px 2px #FFF;
-webkit-box-shadow: inset 0 0 0px 2px #FFF;
box-shadow: inset 0 0 0px 2px #FFF;
I tried border method, doesn't seem to be improved..
I want to have both and outer shadow and an inner (inset) shadow on the same element, is this possible? Right now I have this:
box-shadow: 0 4px 2px -2px #888;
box-shadow: inset 0 0 30px #EEE;
with this the inset shadow overrides the normal box-shadow, any suggestions?
Yes. Separate them with a comma:
box-shadow: inset 0 0 30px #EEE, 0 4px 2px -2px #888;
You can have up to six I believe.
here is an example of what you want fiddle
box-shadow:0 0 30px #222 inset, 0 4px 2px -2px #888;