小白教程
所有教程
关于
Search
172.70.126.111
172.70.126.111
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“CSS3 文本效果”的源代码
本页内容
上一节:
CSS3_背景
下一节:
CSS3_字体
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:CSS3 文本效果}}[[Category:CSS 教程|47]] = CSS3 文本效果 = == CSS3 文本效果 == CSS3中包含几个新的文本特征。 在本章中您将了解以下文本属性: * text-shadow * box-shadow * text-overflow * word-wrap * word-break == 浏览器支持 == {| class="table table-striped table-hover" ! 属性 ! Chrome ! Internet Explorer / Edge ! Firefox ! Safari ! Opera |- | text-shadow | 4.0 | 10.0 | 3.5 | 4.0 | 9.5 |- | box-shadow | 10.04.0 -webkit- | 9.0 | 4.03.5 -moz- | 5.13.1 -webkit- | 10.5 |- | text-overflow | 4.0 | 6.0 | 7.0 | 3.1 | 11.09.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 |} == CSS3 的文本阴影 == CSS3 中,text-shadow属性适用于文本阴影。 您指定了水平阴影,垂直阴影,模糊的距离,以及阴影的颜色: 给标题添加阴影: <sample title="" desc="" lang="html" hererun="1"> h1 { text-shadow: 5px 5px 5px #FF0000; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> h1 { text-shadow: 5px 5px 5px #FF0000; } </style> </head> <body> <h1>Text-shadow effect!</h1> <p><b>注意:</b> Internet Explorer 9 以及更早版本的浏览器不支持 text-shadow属性.</p> </body> </html> </run> == CSS3 box-shadow属性 == CSS3 中 CSS3 box-shadow 属性适用于盒子阴影 <sample title="" desc="" lang="html" hererun="1"> div { box-shadow: 10px 10px 5px #888888; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> div { width:300px; height:100px; background-color:yellow; box-shadow: 10px 10px 5px #888888; } </style> </head> <body> <div></div> </body> </html> </run> == 接下来给阴影添加颜色 == <sample title="" desc="" lang="html" hererun="1"> div { box-shadow: 10px 10px grey; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> div { width: 300px; height: 100px; padding: 15px; background-color: yellow; box-shadow: 10px 10px grey; } </style> </head> <body> <div>This is a div element with a box-shadow</div> </body> </html> </run> == 接下来给阴影添加一个模糊效果 == <sample title="" desc="" lang="html" hererun="1"> div { box-shadow: 10px 10px 5px grey; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> div { width: 300px; height: 100px; padding: 15px; background-color: yellow; box-shadow: 10px 10px 5px grey; } </style> </head> <body> <div>This is a div element with a box-shadow</div> </body> </html> </run> == 你也可以在 ::before 和 ::after 两个伪元素中添加阴影效果 == <sample title="" desc="" lang="html" hererun="1"> #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; } #boxshadow::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; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> #boxshadow { position: relative; -moz-box-shadow: 1px 2px 4px rgba(0, 0, 0,0.5); -webkit-box-shadow: 1px 2px 4px rgba(0, 0, 0, .5); box-shadow: 1px 2px 4px rgba(0, 0, 0, .5); padding: 10px; background: white; } /* Make the image fit the box */ #boxshadow img { width: 100%; border: 1px solid #8a4419; border-style: inset; } #boxshadow::after { content: ''; position: absolute; z-index: -1; /* hide shadow behind image */ -webkit-box-shadow: 0 15px 20px rgba(0, 0, 0, 0.3); -moz-box-shadow: 0 15px 20px rgba(0, 0, 0, 0.3); 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; } </style> </head> <body> <div id="boxshadow"> <img src="rock600x400.jpg" alt="Norway" width="600" height="400"> </div> </body> </html> </run> == 阴影的一个使用特例是卡片效果 == <sample title="" desc="" lang="html" hererun="1"> 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; } </sample> [[try.php?filename=trycss3_box shadow4|文字卡片 »]] [[try.php?filename=trycss3_box shadow5|图片卡片 »]] == CSS3 Text Overflow属性 == CSS3文本溢出属性指定应向用户如何显示溢出内容 <sample title="" desc="" lang="html" hererun="1"> 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; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> div.test { white-space:nowrap; width:12em; overflow:hidden; border:1px solid #000000; } </style> </head> <body> <p>以下 div 容器内的文本无法完全显示,可以看到它被裁剪了。</p> <p>div 使用 "text-overflow:ellipsis":</p> <div class="test" style="text-overflow:ellipsis;">This is some long text that will not fit in the box</div> <p>div 使用 "text-overflow:clip":</p> <div class="test" style="text-overflow:clip;">This is some long text that will not fit in the box</div> <p>div 使用自定义字符串 "text-overflow: >>"(只在 Firefox 浏览器下有效):</p> <div class="test" style="text-overflow:'>>';">This is some long text that will not fit in the box</div> </body> </html> </run> == CSS3的换行 == 如果某个单词太长,不适合在一个区域内,它扩展到外面: CSS3中,自动换行属性允许您强制文本换行 - 即使这意味着分裂它中间的一个字: CSS代码如下: 允许长文本换行: <sample title="" desc="" lang="html" hererun="1"> p {word-wrap:break-word;} </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> p.test { width:11em; border:1px solid #000000; word-wrap:break-word; } </style> </head> <body> <p class="test"> This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.</p> </body> </html> </run> == CSS3 单词拆分换行 == CSS3 单词拆分换行属性指定换行规则: CSS代码如下: <sample title="" desc="" lang="html" hererun="1"> p.test1 { word-break: keep-all; } p.test2 { word-break: break-all; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> p.test1 { width:9em; border:1px solid #000000; word-break:keep-all; } p.test2 { width:9em; border:1px solid #000000; word-break:break-all; } </style> </head> <body> <p class="test1"> This paragraph contains some text. This line will-break-at-hyphenates.</p> <p class="test2"> This paragraph contains some text: The lines will break at any character.</p> <p><b>注意:</b> word-break 属性不兼容 Opera.</p> </body> </html> </run> == 新文本属性 == {| class="table table-striped table-hover" ! 属性 ! 描述 ! CSS |- | [[css3 pr hanging punctuation|hanging-punctuation]] | 规定标点字符是否位于线框之外。 | 3 |- | [[css3 pr punctuation trim|punctuation-trim]] | 规定是否对标点字符进行修剪。 | 3 |- | [[css3 pr text align last|text-align-last]] | 设置如何对齐最后一行或紧挨着强制换行符之前的行。 | 3 |- | [[css3 pr text emphasis|text-emphasis]] | 向元素的文本应用重点标记以及重点标记的前景色。 | 3 |- | [[css3 pr text justify|text-justify]] | 规定当 text-align 设置为 "justify" 时所使用的对齐方法。 | 3 |- | [[css3 pr text outline|text-outline]] | 规定文本的轮廓。 | 3 |- | [[css3 pr text overflow|text-overflow]] | 规定当文本溢出包含元素时发生的事情。 | 3 |- | [[css3 pr text shadow|text-shadow]] | 向文本添加阴影。 | 3 |- | [[css3 pr text wrap|text-wrap]] | 规定文本的换行规则。 | 3 |- | [[css3 pr word break|word-break]] | 规定非中日韩文本的换行规则。 | 3 |- | [[css3 pr word wrap|word-wrap]] | 允许对长的不可分割的单词进行分割并换行到下一行。 | 3 |}
返回至“
CSS3 文本效果
”。
上一节:
CSS3_背景
下一节:
CSS3_字体