Latest web development tutorials

CSS3 Text Effects

CSS3 Text Effects

CSS3 text contains several new features.

In this chapter you will learn the following text attributes:

  • text-shadow
  • box-shadow
  • text-overflow
  • word-wrap
  • word-break

Browser Support

属性
text-shadow 4.0 10.0 3.5 4.0 9.5
box-shadow 10.0
4.0 -webkit-
9.0 4.0
3.5 -moz-
5.1
3.1 -webkit-
10.5
text-overflow 4.0 6.0 7.0 3.1 11.0
9.0 -o-
word-wrap 23.0 5.5 3.5 6.1 12.1
word-break 4.0 5.5 15.0 3.1 15.0

The text shadow CSS3

In CSS3, text-shadow property applies to text shadows.

Text shadow effect!

You specify the horizontal shadow, the vertical shadow, color, distance blur and shadows:

OperaSafariChromeFirefoxInternet Explorer

Examples

Add a shadow to the title:

h1
{
text-shadow: 5px 5px 5px #FF0000;
}

try it"


CSS3 box-shadow property

In CSS3 CSS3 box-shadow property applies to shadow box

Examples

div {
box-shadow: 10px 10px;
}

try it"


Next, add color to the shadow

Examples

div {
box-shadow: 10px 10px grey;
}

try it"


Next, add a shadow to a blur effect

Examples

div {
box-shadow: 10px 10px 5px grey;
}

try it"


You can also add a shadow effect in two :: befor and :: after pseudo-elements

Examples

# Boxshadow {
position: relative;
b ox-shadow: 1px 2px 4px rgba (0, 0, 0, .5);
pa dding: 10px;
bac kground: white;
}
#boxshadow img {
width: 100%;
border: 1px solid # 8a4419;
border-style: inset;
}
#b oxshadow :: after {
content: '';
position: absolute;
z-index: -1; / * hide shadow behind image * /
box-shadow: 0 15px 20px rgba (0, 0, 0, 0.3);
width: 70%;
left: 15%; / * one half of the remaining 30% * /
height: 100px;
bottom: 0;
}

try it"


A special case is the use of shadow card effect

Examples

div.card {
width: 250px;
box-shadow: 0 4px 8px 0 rgba (0, 0, 0, 0.2), 0 6px 20px 0 rgba (0, 0, 0, 0.19);
text-align: center;
}
}

Text Cards >> Picture Card >>


CSS3 Text Overflow property

CSS3 text overflow attribute specifies how users should display overflow content

Examples

p.test1 {
white-space: nowrap;
width: 200px;
border: 1px solid # 000000;
overflow: hidden;
text-overflow: clip;
}

p.test2 {
white-space: nowrap;
width: 200px;
border: 1px solid # 000000;
overflow: hidden;
text-overflow: ellipsis;
}

try it"


CSS3 newline

If a word is too long to fit in an area that extends to the outside:

CSS3, the property allows you to wrap text wrapping mandatory - even if it means splitting it in the middle of a word:

CSS code is as follows:

OperaSafariChromeFirefoxInternet Explorer

Examples

Allows long text wrapping:

p {word-wrap:break-word;}

try it"


CSS3 Word Breaking

CSS3 Word Breaking attribute to specify line breaking rules:

CSS code is as follows:

Examples

p.test1 {
word-break: keep-all;
}

p.test2 {
word-break: break-all;
}

try it"


The new text attributes

Attributes description CSS
hanging-punctuation Provisions punctuation character is located outside the frame. 3
punctuation-trim Whether the provisions of the punctuation characters pruning. 3
text-align-last Setting how to align the last line or immediately before the line to force a line break. 3
text-emphasis Key elements of the application to a text tag and key tag foreground. 3
text-justify When a predetermined alignment method when text-align is set to "justify" use. 3
text-outline Specification of the contour of the text. 3
text-overflow Provisions when things happen when text overflows the containing element. 3
text-shadow Add a shadow to the text. 3
text-wrap Provisions of rule wrap text. 3
word-break CJK text of the provisions of the non-line-breaking rules. 3
word-wrap It allows long divided and indivisible word wrap to the next line. 3