05.文本

2022-09-04  本文已影响0人  一直流浪

1. 缩进文本(text-indent 属性)

提示:如果想把一个行内元素的第一行“缩进”,可以用左内边距或外边距创造这种效果。

p {text-indent: -5em; padding-left: 5em;}
div {width: 500px;}
p {text-indent: 20%;}

<div>
<p>this is a paragragh</p>
</div>
div#outer {width: 500px;}
div#inner {text-indent: 10%;}
p {width: 200px;}

<div id="outer">
<div id="inner">some text. some text. some text.
<p>this is a paragragh.</p>
</div>
</div>

以上标记中的段落也会缩进 50 像素,这是因为这个段落继承了 id 为 inner 的 div 元素的缩进值。

2. 水平对齐(text-align属性)

提示:将块级元素或表元素居中,要通过在这些元素上适当地设置左、右外边距来实现。

text-align:center 与 <CENTER>的区别?

您可能会认为 text-align:center 与 <CENTER> 元素的作用一样,但实际上二者大不相同。<CENTER> 不仅影响文本,还会把整个元素居中。text-align 不会控制元素的对齐,而只影响内部内容。元素本身不会从一段移到另一端,只是其中的文本受影响。

3. 字间隔(word-spacing 属性)

<html>
<head>
<style type="text/css">
p.spread {word-spacing: 50px;}
p.tight {word-spacing: -0.5em;}
</style>
</head>

<body>
<p class="spread">This is some text.</p>
<p class="tight">This is some text. This is some text.</p>
</body>
</html>

4. 字母间隔(letter-spacing 属性)

<html>

<head>
<style type="text/css">
h1 {letter-spacing: -0.5em}
h4 {letter-spacing: 20px}
</style>
</head>

<body>
<h1>This is header 1</h1>
<h4>This is header 4</h4>
</body>

</html>

5. 字符转换(text-transform 属性)

默认值 none 对文本不做任何改动,将使用源文档中的原有大小写。顾名思义,uppercase 和 lowercase 将文本转换为全大写和全小写字符。最后,capitalize 只对每个单词的首字母大写。

作为一个属性,text-transform 可能无关紧要,不过如果您突然决定把所有 h1 元素变为大写,这个属性就很有用。不必单独地修改所有 h1 元素的内容,只需使用 text-transform 为你完成这个修改:

<html>

<head>
<style type="text/css">
  h1 {text-transform: uppercase}
  p.uppercase {text-transform: uppercase}
  p.lowercase {text-transform: lowercase}
  p.capitalize {text-transform: capitalize}
</style>
</head>

<body>
<h1>This Is An H1 Element</h1>
<p class="uppercase">This is some text in a paragraph.</p>
<p class="lowercase">This is some text in a paragraph.</p>
<p class="capitalize">This is some text in a paragraph.</p>
</body>

</html>

6. 文本修饰(text-decoration 属性)

7. 处理空白符(white-space 属性)

8. 文本方向(direction 属性)

取值

rtl——靠屏幕右边对齐

ltr——靠屏幕左边对齐

<html>
<head>
<style type="text/css">
div.one
{
direction: rtl
}
div.two
{
direction: ltr
}
</style>
</head>
<body>

<div class="one">Some text. Right-to-left direction.</div>
<div class="two">Some text. Left-to-right direction.</div>

</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读