How to apply CSS styles to text only - html

I am trying to apply a style to a like of HTML text. What I want is basically:
What I get is basically:
As you can see, the first line is indented, but not any other line. So far, I have the text inside of a <span>, which is nested inside of a <div>.
.slide-text .text {
background-color: rgba(0, 0, 0, .6);
color: #FFF;
padding: 8px 17px;
}
.slide-text .slide-title {
font-family: "Titillium Web", Arial, Helvetica, sans-serif;
font-weight: 700;
}
.slide-text .slide-content {
font-family: "Open Sans", Arial, Helvetica, sans-serif;
font-weight: 500;
}
My HTML code is:
<div class="slide-text">
<div class="slide-title"><span class="text">[TITLE]</span>
</div>
<div class="slide-content"><span class="text">[TEXT]</span>
</div>
</div>
They work great, as long as neither the title or the content are more than one line. As soon as they go over two or more lines, the span loses its inner padding. Changing the inner span to display: inline-block; gives it a block display as soon as it goes into two lines. Is there a way to get the effect I am looking for?

The CSS guru Chris Coyier has an article on CSS-Tricks listing several methods to solve this. One method is the one with box-shadow. It is already mentioned as an answer, but it needs some more love to work in modern Firefox :).
.multi-line-padded {
background: black;
color: white;
/* For the top and bottom padding */
padding: 0.5em 0;
/* Text height (1.0) + compensate for padding (0.5 * 2) */
line-height: 2;
/* For the left and right padding */
/* Vendor prefixes FIRST */
-webkit-box-shadow: 1em 0 0 black, -1em 0 0 black;
-moz-box-shadow: 1em 0 0 black, -1em 0 0 black;
box-shadow: 1em 0 0 black, -1em 0 0 black;
/* Firefox defaults to `box-decoration-break: split`, we need `clone` */
box-decoration-break: clone;
}
<p><span class="multi-line-padded">You think water moves fast? You should see ice. It moves like it has a mind. Like it knows it killed the world once and got a taste for murder.</span></p>
<p style="text-align: right;"><span class="multi-line-padded">Samuel L. Ipsum</span></p>

Try following the example in the best answer to this similar question. It essentially suggests using a box-shadow to create padding.
span {
background:#ff0;color:#000;
box-shadow:0.2em 0 0 #ff0,-0.2em 0 0 #ff0;
-moz-box-shadow:0.2em 0 0 #ff0,-0.2em 0 0 #ff0;
-webkit-box-shadow:0.2em 0 0 #ff0,-0.2em 0 0 #ff0;
}
will indent all of your text equally and add yellow padding (change the #ff0 to any HTML color value you need). However, you will have to reformat the existing code, since it will indent further than the shadow.

You can try to use
style='width: fit-content;'
For more info: https://developer.mozilla.org/en-US/docs/Web/CSS/fit-content

Related

How can I position 3 elements into 3 sections of a circle

I tried this: https://jsbin.com/qidesiqada/edit?html,output
also pasted here:
<html>
<head>
<style>
p.two {
float: right;
color: white;
font-family: Century Gothic, sans-serif;
font-size:20px;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
p.one {
float: left;
font-family: Century Gothic, sans-serif;
color: white;
font-size:27px;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
p.three {
text-align: center;
margin-top: 12px;
font-family: Century Gothic, sans-serif;
color: white;
font-size:20px;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
#container {
width:45px;
}
p { margin: 0; }
</style>
</head>
<body>
<div id="container">
<p class="one">1</p><p class="two">20</p><br>
<p class="three">3</p></div>
</body>
</html>
however, when 1 element is large than the other, it shoves the other ones out of the way. Note how the big 1 shoves the little 3 slightly to the right. This is what I want to avoid
I want each element to be exactly in the same place no matter the size of the font or the size of the others. So it would seem that position-absolute would do this, right? But no, When I use position-absolute on that bottom element, it doesn't center in the div. When I use tricks like transform: translate(-50%, -50%); it move it half way across the screen as though its ignoring the fact that it exists inside of the container div.
Any help on this? Thanks!
this is where the numbers are supposed to fit. You'll notice that even here they are slightly off, but you can get the general idea. The "pie chart" on the back is not part of the desired affect. I simply wish to show that each number should be positioned in one of the quadrants.
There's a few things going on in your question so I'll answer what I think will be the most help to you (also not entirely sure what you're doing).
The reason #3 is centering to the body instead of the div is because absolute position is relative to the first dom it finds up the tree with absolute or relative positioning. Since the parent dom element has the default static positioning it is positioned relative to the body.
css-
#container { position: relative; }
jsbin-
https://jsbin.com/hamepicage/1/edit?html,output
Edit:
Closer what what you're trying to achieve. Use absolute position on all elements so their bounding boxes don't collide. Instead of float: left; use:
left: 0;
Instead of float: right; use:
right: 0;
And for the centering you can calculate the center if you know the width.
calc(50% - 12px);
Or make it width: 100%; and center align the text.
text-align: center;
width: 100%;
Also, don't forget to give your container div a height.
https://jsbin.com/tovopiseqe/1/edit?html,output

adapt blockquote to the image height and add stylized quote

I want to modify my html/css to obtain something like these modification in red, adding two stylized quote, and adapt image to the size of my <blockquote></blockquote> element.
My html is
<img src="presentation-images/bernardlee.jpg" style="width:300px";
class = "author"/>
<blockquote> [...] <mark>The project started with the philosophy that
much academic information should be freely available to anyone.</mark>
It aims to allow information sharing within internationally dispersed
teams, and the dissemination of information by support groups. -- Tim
Berners-Lee (1991)</blockquote>
My css :
mark {
background-color: #EBEBE4;
color: black;
}
.author
{
float:left;
clear:both;
margin:8px 8px 8px 8px;
}
blockquote {
display: block;
margin: 1.5em 0 1.5em -1.5em;
padding: .75em .5em .75em 1em;
background: #fff;
font-family: 'Crimson Text';
border-left: 0.5em solid green;
font-size: 0.8em;
font-style: italic;
line-height: 1.5;
-webkit-box-shadow: 0 0 5px rgba(20,20,20,0.5);
-moz-box-shadow: 0 0 5px rgba(20,20,20,0.5);
box-shadow: 0 0 5px rgba(20,20,20,0.5);
}
You can see fiddle here : http://jsfiddle.net/h6m80gqb/
As you tagged this HTML5 and even awarded a bounty on it I decided to have a play with this myself, despite my solution ending up with the same weakness as Clint Brown's answer has, but at least I am not using tables in my css and my quotes are a bit more stylized :P .
The DOM structure
<div class="quote">
<blockquote> [...] <mark>The project started with the philosophy that
much academic information should be freely available to anyone.</mark>
It aims to allow information sharing within internationally dispersed
teams, and the dissemination of information by support groups. -- Tim
Berners-Lee (1991)</blockquote>
</div>
Is what I ended up with, if you need to include the image url in the generated HTML (as you likely will), you will need to put a separate tag for that as well.
Getting the image to adapt to the size of the box
Although flexible box model is a bit overkill here, it works splendidly none the less. A simple display:flex; on the container and flex: 0 0 20%; on the image element will cause it to get the height of the container and as the height of the container is defined by the amount of text in the <blockquote> this means the image element is adapting to the <blockquote>. Next all you need is setting the image as a background and either background-size:cover; or background-size:contain; for the image (if you choose contain you would want to add background-repeat:no-repeat; background-position:right; as well).
.quote{
display:flex;
box-shadow: 0 0 5px rgba(20,20,20,0.5);
border-left: 0.5em solid green;
margin:10px;
}
div:before{
content:'';
display:block;
flex: 0 0 30%;
padding-left:0.5em;
background:url('http://www.enlactualidad.com/wp-content/uploads/2013/03/Tim-Berners-Lee.jpg');
background-size:cover;
background-position:center;
}
The quotes
As you were talking about stylized quotes I believe you wanted more than just inserting the relevant character, so instead you can float the first quote with a big font size and inline the second to give the following final look
Playing around with fonts and stuff could still greatly enhance the look of everything, but this does bring the point across.
blockquote:before,blockquote:after{
display:block;
font-size:60px;
height:0.5em;
overflow:hidden;
position:relative;
top:-0.15em;
color:red;
margin-bottom:-0.15em;
}
blockquote:before{
float:left;
padding-right:10px;
content:'“';
}
blockquote:after{
content:'”';
display:inline-block;
padding-left:10px;
vertical-align:top;
}
The 'flaw' in this answer
Just like Brown's answer the height adapts to the text as required, however the width is fixed which is somehow 'solved' by the image being partially covered. A solution that would adapt both the width and the height would quite definitely require Javascript as it is sort of circular dependency (by changing the width, the height of the blockquote changes, thus the width of the height of the image changes, thus the width changes, which can be resolved, but not in HTML/CSS).
Trickier than I first thought using only CSS. This is the approach I tried but it's not quite there yet -
blockquote {
display: table;
margin: 1.5em 0 1.5em -1.5em;
padding: .75em .5em;
font-family: 'Crimson Text';
border-left: 0.5em solid green;
font-size: 0.8em;
font-style: italic;
line-height: 1.5;
-webkit-box-shadow: 0 0 5px rgba(20,20,20,0.5);
-moz-box-shadow: 0 0 5px rgba(20,20,20,0.5);
box-shadow: 0 0 5px rgba(20,20,20,0.5);
}
blockquote .image {
display: table-cell;
width: 20%;
}
blockquote .quote {
margin-left: 10px;
}
blockquote .quote:before,
blockquote .quote:after {
content: '"';
color: red;
font-size: 1.6em;
line-height: 0;
vertical-align: middle;
}
blockquote .quote:after {
display: inline;
}
mark {
background-color: #EBEBE4;
color: black;
}
<blockquote>
<div class="image" style="background: url('http://www.enlactualidad.com/wp-content/uploads/2013/03/Tim-Berners-Lee.jpg') no-repeat center right; background-size: auto 100%;"></div>
<div class="quote">[...] <mark>The project started with the philosophy that
much academic information should be freely available to anyone.</mark>
It aims to allow information sharing within internationally dispersed
teams, and the dissemination of information by support groups. -- Tim Berners-Lee (1991)</div>
</blockquote>
I would move the <img> tag into the <blockquote> tag and remove the style='' attribute.
I modified the CSS like this:
mark {
background-color: #EBEBE4;
color: black;
}
.author {
float:left;
clear:both;
margin:8px 8px 8px 8px;
}
blockquote {
position:absolute;
display: block;
margin: 1.5em 0 1.5em -1.5em;
padding: .75em .5em .75em 1em;
background: #fff;
font-family:'Crimson Text';
border-left: 0.5em solid green;
font-size: 0.8em;
font-style: italic;
line-height: 1.5;
-webkit-box-shadow: 0 0 5px rgba(20, 20, 20, 0.5);
-moz-box-shadow: 0 0 5px rgba(20, 20, 20, 0.5);
box-shadow: 0 0 5px rgba(20, 20, 20, 0.5);
width:100%;
height:100px;
padding-bottom:15px;
}
blockquote img {
height:100%;
width:auto;
}
To get special " marks, you could have the quotes in a <span> tag and style them appropriately.

Add stroke around text - on the outside - with css?

I have the following HTML and CSS:
body { background-color: gray; }
h1 {
color: white;
font-size: 2.5em;
}
<h1>WHAT CARRER SHOULD YOU HAVE ?</h1>
Which renders like this:
I want to add a stroke around it, that means a black border around these text.
I Googled and found -webkit-text-stroke, and came up with:
body { background-color: gray; }
h1 {
color: white;
font-size: 2.5em;
-webkit-text-stroke: 2px black;
}
<h1>WHAT CARRER SHOULD YOU HAVE ?</h1>
However, the effect is not what I want:
As you can see, it seems that the stroke is added inside the text, which make the text looks too thin for me.
How can I make the stroke outside the text?
Fiddle: http://jsfiddle.net/jpjbk1z7/
PS: only webkit support is needed
For a smooth outside stroke emulated by text shadow, use the following 8-axis shadow:
text-shadow:
-1px -1px 0 #000,
0 -1px 0 #000,
1px -1px 0 #000,
1px 0 0 #000,
1px 1px 0 #000,
0 1px 0 #000,
-1px 1px 0 #000,
-1px 0 0 #000;
For customisation, you can use this SASS mixin instead (although changing the size does have side effects on rendering):
#mixin stroke($color: #000, $size: 1px) {
text-shadow:
-#{$size} -#{$size} 0 $color,
0 -#{$size} 0 $color,
#{$size} -#{$size} 0 $color,
#{$size} 0 0 $color,
#{$size} #{$size} 0 $color,
0 #{$size} 0 $color,
-#{$size} #{$size} 0 $color,
-#{$size} 0 0 $color;
}
This gives a very smooth stroke, without missing parts, like on the 4 axis solution.
Firefox and Safari now support a new CSS property called paint-order which can be used to simulate an outside stroke:
h1 {
color: #00ff01;
font-size: 3em;
-webkit-text-stroke: 5px black;
}
.fix-stroke {
paint-order: stroke fill;
}
<h1>the default often is ugly</h1>
<h1 class="fix-stroke">paint-order: stroke fill 😀</h1>
Screenshot:
One option is to use text-shadow to simulate a stroke. Example:
text-shadow:
-1px -1px 0 #000,
1px -1px 0 #000,
-1px 1px 0 #000,
1px 1px 0 #000;
The -webkit-text-stroke doesn't support placing the stroke on the outside of the text
as this CSS-Tricks article explains:
The stroke drawn by text-stroke is aligned to the center of the text
shape (as is the default in Adobe Illustrator), and there is currently
no option to set the alignment to the inside or outside of the shape.
Unfortunately this makes it much less usable, as no matter what now
the stroke interferes with the shape of the letter destroying the
original type designers intent. A setting would be ideal, but if we
had to pick one, outside stroke would have been much more useful.
What about SVG?
Well it seems that it also places the stroke on the inside -
FIDDLE
However,
you might be able to simulate this effect (depending on what you need) by:
Change your font to a sans serif like verdana and
Increase the font-size of the text you are adding a stroke to.
body {
background: grey;
font-family: verdana;
}
.stroke,
.no-stroke {
color: white;
font-size: 2.5em;
}
.stroke {
-webkit-text-stroke: 2px black;
font-size: 2.7em;
}
<h1 class="stroke">WHAT CAREER SHOULD YOU HAVE?</h1>
<h1 class="no-stroke">WHAT CAREER SHOULD YOU HAVE?</h1>
Further elaborating on the other text-shadow solutions, for pixel-perfect thick round outlines the number of shadows should increase with the radius of the stroke. For example, a 10px thick outline requires 2⋅10⋅π ≈ 63 shadows distributed in all directions. To generate this in javascript, one could something like:
const color = "#FFF" /* white outline */
const r = 10 /* width of outline in pixels */
const n = Math.ceil(2*Math.PI*r) /* number of shadows */
var str = ''
for(var i = 0;i<n;i++) /* append shadows in n evenly distributed directions */
{
const theta = 2*Math.PI*i/n
str += (r*Math.cos(theta))+"px "+(r*Math.sin(theta))+"px 0 "+color+(i==n-1?"":",")
}
document.querySelector("#myoutlinedtext").style.textShadow = str
If the thickness is static, then just run this once to generate the string and paste it into your CSS.
One way I found was to stack two elements on each other having the element that stays behind get the double stroke width. The element behind leaks the stroke to the outside of the visible element making it a true stroke outside.
Also, another option is to use :after to create this second element. The downside is that you can't programmatically change the stroke
This might not work properly on big stroke values.
body { background-color: gray; }
h1 {
color: white;
font-size: 2.5em;
font-family: verdana;
}
.stroke { -webkit-text-stroke: 2px black; }
.stack .stroke { -webkit-text-stroke: 4px black; }
h1.stroke-fs { font-size: 2.7em; }
.stack { position: relative; }
.stack > h1:not(:first-child) {
left: 0;
margin: 0;
position: absolute;
top: 0;
}
.stroke-after:after {
-webkit-text-stroke: 4px black;
content: attr(value);
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
Stack
<div class="stack">
<h1 class="stroke">WHAT CARRER SHOULD YOU HAVE ?</h1>
<h1>WHAT CARRER SHOULD YOU HAVE ?</h1>
</div>
<hr />
After
<div style="position: relative">
<h1 class="stroke-after" value="WHAT CARRER SHOULD YOU HAVE ?">WHAT CARRER SHOULD YOU HAVE ?</h1>
</div>
<hr />
Native
<h1 class="stroke">WHAT CARRER SHOULD YOU HAVE ?</h1>
<hr />
Font size
<h1 class="stroke stroke-fs">WHAT CARRER SHOULD YOU HAVE ?</h1>
I have also tried text-shadow and -webkit-text-stroke, but unsuccessful in all ways.
I could only get the result by making two divs(background and foreground) i.e,
background div with -webkit-text-stroke and foreground div without -webkit-text-stroke.
<div style="position:absolute;width:1280px;height:720px;left:0px;top:0px" >
<div style="color:#CDCDCD;
font-family:sans-serif;
font-size:57px;
-webkit-text-stroke-color:black;
-webkit-text-stroke-width:0.04em;" >
<p>
Text with outine stroke outwards.
</p>
</div>
</div>
<div style="position:absolute;width:1280px;height:720px;left:0px;top:0px" >
<div style="color:#CDCDCD;
font-family:sans-serif;
font-size:57px;" >
<p>
Text with outine stroke outwards.
</p>
</div>
</div>
Bt the only problem with the html generated through is twice the size(size in memory) as the div is repeated twice.
Does anyone has some better solution?
I know this is an old question but have a look at this:
https://jsfiddle.net/1dbta9cq/
you can simply place another text on top of the stroked text with absolute positioning, it's not so tidy but it solves the problem
<div class="container">
<h1 class="stroke">Stroke</h1>
<h1 class="no-stroke">Stroke</h1>
</div>
.container{
width:300px;
}
.stroke{
position:absolute;
-webkit-text-stroke: 10px black;
}
.no-stroke{
color:white;
position:absolute
}
Here’s a SCSS mixin for simulating text outlines with multiple shadows:
#use "sass:math";
#use 'sass:list';
#mixin text-outline($offset, $color, $num-steps: 16) {
$shadows: ();
#for $i from 0 to $num-steps {
$angle: $i * 360deg / $num-steps;
$x: calc(#{math.cos($angle)} * #{$offset});
$y: calc(#{math.sin($angle)} * #{$offset});
$shadows: list.append($shadows, #{$x} #{$y} 0 #{$color}, $separator: comma);
}
text-shadow: $shadows;
}
For larger offsets, a greater number of shadows (“steps”) is required for good results. Note that in general, however, more shadows will be more expensive for the browser to render.
Example:
span {
color: #FF004D;
#include utils.type-outline(
$offset: calc(0.05rem + 0.05em),
$color: #FFFFFF,
$num-steps: 32
);
}
Result:
I'm obviously late to the party but I find the easiest is probably the best way forward to a solution.
For me, I did the outside stroke effect by just making the weight of the font larger.
body { background-color: gray; }
h1 {
color: white;
font-size: 2.5em;
font-weight: bold;
-webkit-text-stroke: 2px black;
}
Is it the most correct ?
Depending on the situation then the answer is yes Or no.
Does it work in your use case ? ...for me , yes perfefctly.
Text shadow might be used to achieve this result
http://css3generator.com
Here's a SASS mixin I created to make it easy to create a text outline using the prefixed properties (-webkit, -moz) when supported, but falling back to just a color with text shadow. Note that the fallback doesn't work well with opaque fill colors, but other than that I think it's a pretty good solution, until we can get a standard method that has better browser support.
Fiddle
Mixin
#mixin text-stroke($fill-color, $stroke-color, $stroke-width) {
color: $fill-color;
text-shadow: -$stroke-width -$stroke-width 0 $stroke-color,
$stroke-width -$stroke-width 0 $stroke-color,
-$stroke-width $stroke-width 0 $stroke-color,
$stroke-width $stroke-width 0 $stroke-color;
#supports ((-webkit-text-stroke-color: $stroke-color) and (-webkit-text-fill-color: white))
or ((-moz-text-stroke-color: $stroke-color) and (-moz-text-fill-color: white)) {
color: unset;
text-shadow: unset;
-moz-text-fill-color: $fill-color;
-webkit-text-fill-color: $fill-color;
-moz-text-stroke-color: $stroke-color;
-webkit-text-stroke-color: $stroke-color;
-moz-text-stroke-width: $stroke-width;
-webkit-text-stroke-width: $stroke-width;
}
}
Example Usage
(Makes text semi-transparent black with a white outline)
.heading-outline {
#include text-stroke(rgba(#000,.5), #fff, 1px);
}

How to draw a text outline in css with outwards stroke? [duplicate]

I have the following HTML and CSS:
body { background-color: gray; }
h1 {
color: white;
font-size: 2.5em;
}
<h1>WHAT CARRER SHOULD YOU HAVE ?</h1>
Which renders like this:
I want to add a stroke around it, that means a black border around these text.
I Googled and found -webkit-text-stroke, and came up with:
body { background-color: gray; }
h1 {
color: white;
font-size: 2.5em;
-webkit-text-stroke: 2px black;
}
<h1>WHAT CARRER SHOULD YOU HAVE ?</h1>
However, the effect is not what I want:
As you can see, it seems that the stroke is added inside the text, which make the text looks too thin for me.
How can I make the stroke outside the text?
Fiddle: http://jsfiddle.net/jpjbk1z7/
PS: only webkit support is needed
For a smooth outside stroke emulated by text shadow, use the following 8-axis shadow:
text-shadow:
-1px -1px 0 #000,
0 -1px 0 #000,
1px -1px 0 #000,
1px 0 0 #000,
1px 1px 0 #000,
0 1px 0 #000,
-1px 1px 0 #000,
-1px 0 0 #000;
For customisation, you can use this SASS mixin instead (although changing the size does have side effects on rendering):
#mixin stroke($color: #000, $size: 1px) {
text-shadow:
-#{$size} -#{$size} 0 $color,
0 -#{$size} 0 $color,
#{$size} -#{$size} 0 $color,
#{$size} 0 0 $color,
#{$size} #{$size} 0 $color,
0 #{$size} 0 $color,
-#{$size} #{$size} 0 $color,
-#{$size} 0 0 $color;
}
This gives a very smooth stroke, without missing parts, like on the 4 axis solution.
Firefox and Safari now support a new CSS property called paint-order which can be used to simulate an outside stroke:
h1 {
color: #00ff01;
font-size: 3em;
-webkit-text-stroke: 5px black;
}
.fix-stroke {
paint-order: stroke fill;
}
<h1>the default often is ugly</h1>
<h1 class="fix-stroke">paint-order: stroke fill 😀</h1>
Screenshot:
One option is to use text-shadow to simulate a stroke. Example:
text-shadow:
-1px -1px 0 #000,
1px -1px 0 #000,
-1px 1px 0 #000,
1px 1px 0 #000;
The -webkit-text-stroke doesn't support placing the stroke on the outside of the text
as this CSS-Tricks article explains:
The stroke drawn by text-stroke is aligned to the center of the text
shape (as is the default in Adobe Illustrator), and there is currently
no option to set the alignment to the inside or outside of the shape.
Unfortunately this makes it much less usable, as no matter what now
the stroke interferes with the shape of the letter destroying the
original type designers intent. A setting would be ideal, but if we
had to pick one, outside stroke would have been much more useful.
What about SVG?
Well it seems that it also places the stroke on the inside -
FIDDLE
However,
you might be able to simulate this effect (depending on what you need) by:
Change your font to a sans serif like verdana and
Increase the font-size of the text you are adding a stroke to.
body {
background: grey;
font-family: verdana;
}
.stroke,
.no-stroke {
color: white;
font-size: 2.5em;
}
.stroke {
-webkit-text-stroke: 2px black;
font-size: 2.7em;
}
<h1 class="stroke">WHAT CAREER SHOULD YOU HAVE?</h1>
<h1 class="no-stroke">WHAT CAREER SHOULD YOU HAVE?</h1>
Further elaborating on the other text-shadow solutions, for pixel-perfect thick round outlines the number of shadows should increase with the radius of the stroke. For example, a 10px thick outline requires 2⋅10⋅π ≈ 63 shadows distributed in all directions. To generate this in javascript, one could something like:
const color = "#FFF" /* white outline */
const r = 10 /* width of outline in pixels */
const n = Math.ceil(2*Math.PI*r) /* number of shadows */
var str = ''
for(var i = 0;i<n;i++) /* append shadows in n evenly distributed directions */
{
const theta = 2*Math.PI*i/n
str += (r*Math.cos(theta))+"px "+(r*Math.sin(theta))+"px 0 "+color+(i==n-1?"":",")
}
document.querySelector("#myoutlinedtext").style.textShadow = str
If the thickness is static, then just run this once to generate the string and paste it into your CSS.
One way I found was to stack two elements on each other having the element that stays behind get the double stroke width. The element behind leaks the stroke to the outside of the visible element making it a true stroke outside.
Also, another option is to use :after to create this second element. The downside is that you can't programmatically change the stroke
This might not work properly on big stroke values.
body { background-color: gray; }
h1 {
color: white;
font-size: 2.5em;
font-family: verdana;
}
.stroke { -webkit-text-stroke: 2px black; }
.stack .stroke { -webkit-text-stroke: 4px black; }
h1.stroke-fs { font-size: 2.7em; }
.stack { position: relative; }
.stack > h1:not(:first-child) {
left: 0;
margin: 0;
position: absolute;
top: 0;
}
.stroke-after:after {
-webkit-text-stroke: 4px black;
content: attr(value);
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
Stack
<div class="stack">
<h1 class="stroke">WHAT CARRER SHOULD YOU HAVE ?</h1>
<h1>WHAT CARRER SHOULD YOU HAVE ?</h1>
</div>
<hr />
After
<div style="position: relative">
<h1 class="stroke-after" value="WHAT CARRER SHOULD YOU HAVE ?">WHAT CARRER SHOULD YOU HAVE ?</h1>
</div>
<hr />
Native
<h1 class="stroke">WHAT CARRER SHOULD YOU HAVE ?</h1>
<hr />
Font size
<h1 class="stroke stroke-fs">WHAT CARRER SHOULD YOU HAVE ?</h1>
I have also tried text-shadow and -webkit-text-stroke, but unsuccessful in all ways.
I could only get the result by making two divs(background and foreground) i.e,
background div with -webkit-text-stroke and foreground div without -webkit-text-stroke.
<div style="position:absolute;width:1280px;height:720px;left:0px;top:0px" >
<div style="color:#CDCDCD;
font-family:sans-serif;
font-size:57px;
-webkit-text-stroke-color:black;
-webkit-text-stroke-width:0.04em;" >
<p>
Text with outine stroke outwards.
</p>
</div>
</div>
<div style="position:absolute;width:1280px;height:720px;left:0px;top:0px" >
<div style="color:#CDCDCD;
font-family:sans-serif;
font-size:57px;" >
<p>
Text with outine stroke outwards.
</p>
</div>
</div>
Bt the only problem with the html generated through is twice the size(size in memory) as the div is repeated twice.
Does anyone has some better solution?
I know this is an old question but have a look at this:
https://jsfiddle.net/1dbta9cq/
you can simply place another text on top of the stroked text with absolute positioning, it's not so tidy but it solves the problem
<div class="container">
<h1 class="stroke">Stroke</h1>
<h1 class="no-stroke">Stroke</h1>
</div>
.container{
width:300px;
}
.stroke{
position:absolute;
-webkit-text-stroke: 10px black;
}
.no-stroke{
color:white;
position:absolute
}
Here’s a SCSS mixin for simulating text outlines with multiple shadows:
#use "sass:math";
#use 'sass:list';
#mixin text-outline($offset, $color, $num-steps: 16) {
$shadows: ();
#for $i from 0 to $num-steps {
$angle: $i * 360deg / $num-steps;
$x: calc(#{math.cos($angle)} * #{$offset});
$y: calc(#{math.sin($angle)} * #{$offset});
$shadows: list.append($shadows, #{$x} #{$y} 0 #{$color}, $separator: comma);
}
text-shadow: $shadows;
}
For larger offsets, a greater number of shadows (“steps”) is required for good results. Note that in general, however, more shadows will be more expensive for the browser to render.
Example:
span {
color: #FF004D;
#include utils.type-outline(
$offset: calc(0.05rem + 0.05em),
$color: #FFFFFF,
$num-steps: 32
);
}
Result:
I'm obviously late to the party but I find the easiest is probably the best way forward to a solution.
For me, I did the outside stroke effect by just making the weight of the font larger.
body { background-color: gray; }
h1 {
color: white;
font-size: 2.5em;
font-weight: bold;
-webkit-text-stroke: 2px black;
}
Is it the most correct ?
Depending on the situation then the answer is yes Or no.
Does it work in your use case ? ...for me , yes perfefctly.
Text shadow might be used to achieve this result
http://css3generator.com
Here's a SASS mixin I created to make it easy to create a text outline using the prefixed properties (-webkit, -moz) when supported, but falling back to just a color with text shadow. Note that the fallback doesn't work well with opaque fill colors, but other than that I think it's a pretty good solution, until we can get a standard method that has better browser support.
Fiddle
Mixin
#mixin text-stroke($fill-color, $stroke-color, $stroke-width) {
color: $fill-color;
text-shadow: -$stroke-width -$stroke-width 0 $stroke-color,
$stroke-width -$stroke-width 0 $stroke-color,
-$stroke-width $stroke-width 0 $stroke-color,
$stroke-width $stroke-width 0 $stroke-color;
#supports ((-webkit-text-stroke-color: $stroke-color) and (-webkit-text-fill-color: white))
or ((-moz-text-stroke-color: $stroke-color) and (-moz-text-fill-color: white)) {
color: unset;
text-shadow: unset;
-moz-text-fill-color: $fill-color;
-webkit-text-fill-color: $fill-color;
-moz-text-stroke-color: $stroke-color;
-webkit-text-stroke-color: $stroke-color;
-moz-text-stroke-width: $stroke-width;
-webkit-text-stroke-width: $stroke-width;
}
}
Example Usage
(Makes text semi-transparent black with a white outline)
.heading-outline {
#include text-stroke(rgba(#000,.5), #fff, 1px);
}

CSS3 Heading Issue

I am scratching my head to resolve this issue but without success.
It is very simple: a div with rounded corners with a h3 on the top (I am trying to simulate a panel with title), very simple.
For some reason, the h3 always has a space, feels like it has a margin or something.
.example-wrapper {
border: 1px solid #555;
border-radius: 10px 10px 0 0;}
.example-wrapper h3 {
background: #555;
color: #fff;
border-radius: 10px 10px 0 0;
padding: 10px;
font-size: 16px;}
<DIV class="example-wrapper">
<H3>Herry Potter</H3>
</DIV>
Any comments would be appreciated.
You can find the issue here.
Yes, H# has margins by default. Set H3{ margin: 0; } to solve it. You can always use developer tools to inspect elements and see any style applied to them.