为半个字符应用CSS样式可能吗?

What I am looking for:

A way to apply styling to one HALF of a character.
(In this case, half the letter being transparent)

我正在寻找:

一种方法为半个字符应用样式。(在这种情况下,一半的字母是透明的)

What I have currently searched for and tried (With no
luck):

  • Methods for styling half of a character/letter

  • Styling part of a character with CSS or JavaScript

  • Apply CSS to 50% of a character

Below is an example of what I am trying to obtain.

我目前已经搜索并尝试的(不走运):

  • 渲染一半字符/字母的方法

  • 用CSS或JavaScript渲染字符的一部分

  • 对一个字符的50%应用CSS

以下是我尝试实现的一个例子:

Does a CSS or JavaScript solution exists for this or am I going to have to
resort to images? I would prefer not to go the image route as this text will end
up being generated dynamically.

这个是否有一个CSS或者JavaScript的解决方法存在,还是我必须采用图片的方法?我不愿意采用图片的方法,因为文本将最终是动态生成的。

回答:

Now on GitHub as a
Plugin!


现在在GitHub上是一个插件!

 Feel
free to fork and improve.

Demo | Download
Zip
 | Half-Style.com (Redirects to
GitHub)


演示 | 下载
Zip
 | Half-Style.com (重定向到GitHub)



  • Pure CSS for a Single Character

  • JavaScript used for automation accross text or multiple characters

  • Preserves Text Accessibility for screen readers for the blind or visually
    impaired

  • 单个字符的纯css

  • JavaScript用来自动穿过文本或多字符

  • 保护文本的可读性,使其可以被盲人或视障人士使用的屏幕阅读器识别

Part1: Basic Solution


第一部分: 基本解决方案


演示: http://jsfiddle.net/pd9yB/817/


This works on any dynamic text, or a single character, and is all automated.
All you need to do is add a class on the target text and the rest is taken care
of.

这种方法适用于任何动态文本或单个字符,并且都是自动适用的。所有你需要做的就是在目标文本上添加一个class,剩下的就解决了。

Also, the accessibility of the original text is preserved for screen readers
for the blind or visually impaired.

同时,保留了原文的可访问性,可以被盲人或视障人士使用的屏幕阅读器识别。

Explanation for a single character:

Pure CSS. All you need to do is to
apply .halfStyle class to each element that contains the
character you want to be half-styled.

For each span element containing the character, you can create a data
attribute, for example here data-content="X", and on the
pseudo element use content: attr(data-content); so
the .halfStyle:before class will be dynamic and you won‘t
need to hard code it for every instance.

单个字符的说明:

纯CSS。所有你需要做的就是把.halfStyle class用在每个你想要渲染一半样式字符的元素上。

对于每个包含字符的span元素,你可以添加一个data属性,比如data-content="X",并且在伪元素上使用content:attr(data-content);这样,.halfStyle:before class将会是动态的,你不需要为每个实例进行硬编码

Explanation for any text:

Simply add textToHalfStyle class to the element
containing the text.

任意文本说明:

只需添加textToHalfStyle class到包含文本的元素上。


CSS:

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

.halfStyle {

    position:relative;

    display:inline-block;

    font-size:80px; /* or any font size will work */

    color: black; /* or transparent, any color */

    overflow:hidden;

    white-space: pre; /* to preserve the spaces from collapsing */

}

.halfStyle:before {

    display:block;

    z-index:1;

    position:absolute;

    top:0;

    left:0;

    width: 50%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    overflow:hidden;

    color: #f00;

}

HTML

?





1

2

3

4

5

6

7

8

9

10

<p>Single Characters:</p>

<span class="halfStyle"
data-content="X">X</span>

<span class="halfStyle"
data-content="Y">Y</span>

<span class="halfStyle"
data-content="Z">Z</span>

<span class="halfStyle"
data-content="A">A</span>

<hr/>

<p>Automated:</p>

<span class="textToHalfStyle">Half-style, please.</span>


To make it automated, simply add textToHalfStyle class
to the element containing the text.

让它自动生效,只要添加 textToHalfStyle class到包含文本的元素上。

jQuery for automated mode:

jQuery 自动模式:

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

jQuery(function($) {

    var
text, chars, $el, i, output;

    // Iterate over all class occurences

    $(‘.textToHalfStyle‘).each(function(idx, el) {

        $el = $(el);

        text = $el.text();

        chars = text.split(‘‘);

        // Set the screen-reader text

        $el.html(‘&lt;span style="position: absolute !important;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);"&gt;‘
+ text + ‘&lt;/span&gt;‘);

        // Reset output for appending

        output = ‘‘;

        // Iterate over all chars in the text

        for
(i = 0; i &lt; chars.length; i++) {

            // Create a styled element for each character and append to container

            output += ‘&lt;span aria-hidden="true" data-content="‘
+ chars[i] + ‘"&gt;‘
+ chars[i] + ‘&lt;/span&gt;‘;

        }

        // Write to DOM only once

        $el.append(output);

    });

});

演示: http://jsfiddle.net/pd9yB/819/


Part2: Advanced solution - Independent left and right parts


第二部分: 先进的解决方案 - 独立的左边和右边部分


With this solution you can style left and right parts,
individually and independently
.

使用这种方法你可以分别单独的渲染左边和右边部分。

Everything is the same, only more advanced CSS does the magic.

一切都是相同的,只是更高级的CSS在发挥作用。

演示: http://jsfiddle.net/pd9yB/819/

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

.halfStyle {

    position:relative;

    display:inline-block;

    font-size:80px; /* or any font size will work */

    color: transparent; /* hide the base character */

    overflow:hidden;

    white-space: pre; /* to preserve the spaces from collapsing */

}

.halfStyle:before { /* creates the left part */

    display:block;

    z-index:1;

    position:absolute;

    top:0;

    width: 50%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    overflow:hidden;

    pointer-events: none; /* so the base char is selectable by mouse */

    color: #f00; /* for demo purposes */

    text-shadow: 2px -2px 0px #af0; /* for demo purposes */

}

.halfStyle:after { /* creates the right part */

    display:block;

    direction: rtl; /* very important, will make the width to start from right */

    position:absolute;

    z-index:2;

    top:0;

    left:50%;

    width: 50%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    overflow:hidden;

    pointer-events: none; /* so the base char is selectable by mouse */

    color: #000; /* for demo purposes */

    text-shadow: 2px 2px 0px #0af; /* for demo purposes */

}



Part3: Mix-Match and Improve


第三部分: 混合-匹配和改进


Now that we know what is possible, let‘s create some variations.

现在我们知道什么是可能的,让我们来添加一些花样。


-Horizontal Half Parts


-水平一半


Demo

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

.halfStyle {

    position:relative;

    display:inline-block;

    font-size:80px; /* or any font size will work */

    color: transparent; /* hide the base character */

    overflow:hidden;

    white-space: pre; /* to preserve the spaces from collapsing */

}

.halfStyle:before { /* creates the top part */

    display:block;

    z-index:2;

    position:absolute;

    top:0;

    height: 50%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    overflow:hidden;

    pointer-events: none; /* so the base char is selectable by mouse */

    color: #f00; /* for demo purposes */

    text-shadow: 2px -2px 0px #af0; /* for demo purposes */

}

.halfStyle:after { /* creates the bottom part */

    display:block;

    position:absolute;

    z-index:1;

    top:0;

    height: 100%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    overflow:hidden;

    pointer-events: none; /* so the base char is selectable by mouse */

    color: #000; /* for demo purposes */

    text-shadow: 2px 2px 0px #0af; /* for demo purposes */

}



-Vertical 1/3 Parts


-垂直1/3


Demo

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

.halfStyle { /* base char and also the right 1/3 */

    position:relative;

    display:inline-block;

    font-size:80px; /* or any font size will work */

    color: transparent; /* hide the base character */

    overflow:hidden;

    white-space: pre; /* to preserve the spaces from collapsing */

    color: #f0f; /* for demo purposes */

    text-shadow: 2px 2px 0px #0af; /* for demo purposes */

}

.halfStyle:before { /* creates the left 1/3 */

    display:block;

    z-index:2;

    position:absolute;

    top:0;

    width: 33.33%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    overflow:hidden;

    pointer-events: none; /* so the base char is selectable by mouse */

    color: #f00; /* for demo purposes */

    text-shadow: 2px -2px 0px #af0; /* for demo purposes */

}

.halfStyle:after { /* creates the middle 1/3 */

    display:block;

    z-index:1;

    position:absolute;

    top:0;

    width: 66.66%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    overflow:hidden;

    pointer-events: none; /* so the base char is selectable by mouse */

    color: #000; /* for demo purposes */

    text-shadow: 2px 2px 0px #af0; /* for demo purposes */

}



-Horizontal 1/3 Parts


-水平 1/3


Demo

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

.halfStyle { /* base char and also the bottom 1/3 */

    position:relative;

    display:inline-block;

    font-size:80px; /* or any font size will work */

    color: transparent;

    overflow:hidden;

    white-space: pre; /* to preserve the spaces from collapsing */

    color: #f0f;

    text-shadow: 2px 2px 0px #0af; /* for demo purposes */

}

.halfStyle:before { /* creates the top 1/3 */

    display:block;

    z-index:2;

    position:absolute;

    top:0;

    height: 33.33%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    overflow:hidden;

    pointer-events: none; /* so the base char is selectable by mouse */

    color: #f00; /* for demo purposes */

    text-shadow: 2px -2px 0px #fa0; /* for demo purposes */

}

.halfStyle:after { /* creates the middle 1/3 */

    display:block;

    position:absolute;

    z-index:1;

    top:0;

    height: 66.66%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    overflow:hidden;

    pointer-events: none; /* so the base char is selectable by mouse */

    color: #000; /* for demo purposes */

    text-shadow: 2px 2px 0px #af0; /* for demo purposes */

}



-HalfStyle Improvement By @KevinGranger


-HalfStyle改进 @KevinGranger


DEMO

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

body{

    background-color: black;

}

.textToHalfStyle{

    display:block;

    margin: 200px 0
0 0;

    text-align:center;

}

.halfStyle {

    font-family: ‘Libre Baskerville‘, serif;

    position:relative;

    display:inline-block;

    width:1;

    font-size:70px;

    color: black;

    overflow:hidden;

    white-space: pre;

    text-shadow: 1px 2px 0
white;

}

.halfStyle:before {

    display:block;

    z-index:1;

    position:absolute;

    top:0;

    width: 50%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    overflow:hidden;

    color: white;

}



-PeelingStyle 改进的 HalfStyle @SamTremaine


Demo and on samtremaine.co.uk


演示 和 samtremaine.co.uk

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

.halfStyle {

    position: relative;

    display: inline-block;

    font-size: 68px;

    color: rgba(0, 0, 0, 0.8);

    overflow: hidden;

    white-space: pre;

    transform: rotate(4deg);

    text-shadow: 2px 1px 3px rgba(0, 0, 0, 0.3);

}

.halfStyle:before { /* creates the left part */

    display: block;

    z-index: 1;

    position: absolute;

    top: -0.5px;

    left: -3px;

    width: 100%;

    content: attr(data-content);

    overflow: hidden;

    pointer-events: none;

    color: #FFF;

    transform: rotate(-4deg);

    text-shadow: 0px 0px 1px #000;

}



Part4: Ready for Production


第四部分: 准备生产


Customized different Half-Style style-sets can be used on desired elements on
the same page. You can define multiple style-sets and tell the plugin which one
to use.

定制不同的Half-Style样式集可以用在同一个页面的所需元素上。你可以定义多个样式集并告诉插件要用哪一个。

The plugin uses data
attribute data-halfstyle="[-CustomClassName-]" on the
target .textToHalfStyle elements and makes all the
necessary changes automatically.

插件在目标.textToHalfStyle元素上使用data属性data-halfstyle="[-CustomClassName-]",所有都会自动改变。

So, simply on the element containing the text
add textToHalfStyle class and data
attribute data-halfstyle="[-CustomClassName-]". The plugin
will do the rest of the job.

所以,只要含有文本的元素添加了textToHalfStyle class和data属性 data-halfstyle="[-CustomClassName-]",插件将完成剩下的工作。

Demo of Multiple
Half-Styles on the same page.


相同页面中多个Half-Styles的 演示

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

jQuery(function($) {

    var
halfstyle_text, halfstyle_chars, $halfstyle_el, halfstyle_i, halfstyle_output, halfstyle_style;

    // Iterate over all class occurrences

    $(‘.textToHalfStyle‘).each(function(idx, halfstyle_el) {

        $halfstyle_el = $(halfstyle_el);

        halfstyle_style = $halfstyle_el.data(‘halfstyle‘);

        halfstyle_text = $halfstyle_el.text();

        halfstyle_chars = halfstyle_text.split(‘‘);

        // Set the screen-reader text

        $halfstyle_el.html(‘&lt;span style="position: absolute !important;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);"&gt;‘
+ halfstyle_text + ‘&lt;/span&gt;‘);

        // Reset output for appending

        halfstyle_output = ‘‘;

        // Iterate over all chars in the text

        for
(halfstyle_i = 0; halfstyle_i &lt; halfstyle_chars.length; halfstyle_i++) {

            // Create a styled element for each character and append to container

            halfstyle_output += ‘&lt;span aria-hidden="true" data-content="‘
+ halfstyle_chars[halfstyle_i] + ‘"&gt;‘
+ halfstyle_chars[halfstyle_i] + ‘&lt;/span&gt;‘;

        }

        // Write to DOM only once

        $halfstyle_el.append(halfstyle_output);

    });

});

Also the CSS style-sets‘ class definitions match
the [-CustomClassName-] part mentioned above and is
chained to .halfStyle, so we will
have .halfStyle.[-CustomClassName-]

此外,CSS样式集class的定义匹配上述的 [-CustomClassName-] 部分,并且链到.halfStyle,因此我们将有.halfStyle.[-CustomClassName-]

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

/* start half-style hs-base */

 .halfStyle.hs-base {

    position:relative;

    display:inline-block;

    font-size:80px; /* or any font size will work */

    overflow:hidden;

    white-space: pre; /* to preserve the spaces from collapsing */

    color: #000; /* for demo purposes */

}

.halfStyle.hs-base:before {

    display:block;

    z-index:1;

    position:absolute;

    top:0;

    width: 50%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    pointer-events: none; /* so the base char is selectable by mouse */

    overflow:hidden;

    color: #f00; /* for demo purposes */

}

 /* end half-style hs-base */

/* start half-style hs-horizontal-third */

.halfStyle.hs-horizontal-third { /* base char and also the bottom 1/3 */

    position:relative;

    display:inline-block;

    font-size:80px; /* or any font size will work */

    color: transparent;

    overflow:hidden;

    white-space: pre; /* to preserve the spaces from collapsing */

    color: #f0f;

    text-shadow: 2px 2px 0px #0af; /* for demo purposes */

}

.halfStyle.hs-horizontal-third:before { /* creates the top 1/3 */

    display:block;

    z-index:2;

    position:absolute;

    top:0;

    height: 33.33%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    overflow:hidden;

    pointer-events: none; /* so the base char is selectable by mouse */

    color: #f00; /* for demo purposes */

    text-shadow: 2px -2px 0px #fa0; /* for demo purposes */

}

.halfStyle.hs-horizontal-third:after { /* creates the middle 1/3 */

    display:block;

    position:absolute;

    z-index:1;

    top:0;

    height: 66.66%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    overflow:hidden;

    pointer-events: none; /* so the base char is selectable by mouse */

    color: #000; /* for demo purposes */

    text-shadow: 2px 2px 0px #af0; /* for demo purposes */

}

/* end half-style hs-horizontal-third */

/* start half-style hs-PeelingStyle, by user SamTremaine on Stackoverflow.com */

.halfStyle.hs-PeelingStyle {

    position: relative;

    display: inline-block;

    font-size: 68px;

    color: rgba(0, 0, 0, 0.8);

    overflow: hidden;

    white-space: pre;

    transform: rotate(4deg);

    text-shadow: 2px 1px 3px rgba(0, 0, 0, 0.3);

}

.halfStyle.hs-PeelingStyle:before { /* creates the left part */

    display: block;

    z-index: 1;

    position: absolute;

    top: -0.5px;

    left: -3px;

    width: 100%;

    content: attr(data-content);

    overflow: hidden;

    pointer-events: none;

    color: #FFF;

    transform: rotate(-4deg);

    text-shadow: 0px 0px 1px #000;

}

/* end half-style hs-PeelingStyle */

/* start half-style hs-KevinGranger, by user KevinGranger on StackOverflow.com*/

.textToHalfStyle.hs-KevinGranger {

    display:block;

    margin: 200px 0
0 0;

    text-align:center;

}

.halfStyle.hs-KevinGranger {

    font-family: ‘Libre Baskerville‘, serif;

    position:relative;

    display:inline-block;

    width:1;

    font-size:70px;

    color: black;

    overflow:hidden;

    white-space: pre;

    text-shadow: 1px 2px 0
white;

}

.halfStyle.hs-KevinGranger:before {

    display:block;

    z-index:1;

    position:absolute;

    top:0;

    width: 50%;

    content: attr(data-content); /* dynamic content for the pseudo element */

    overflow:hidden;

    color: white;

}

/* end half-style hs-KevinGranger

HTML:

?





1

2

3

4

5

6

7

8

9

10

11

12

<p>

    <span class="textToHalfStyle"
data-halfstyle="hs-base">Half-style, please.</span>

</p>

<p>

    <span class="textToHalfStyle"
data-halfstyle="hs-horizontal-third">Half-style, please.</span>

</p>

<p>

    <span class="textToHalfStyle"
data-halfstyle="hs-PeelingStyle">Half-style, please.</span>

</p>

<p style="background-color:#000;">

    <span class="textToHalfStyle"
data-halfstyle="hs-KevinGranger">Half-style, please.</span>

</p>

相同页面中多个Half-Styles的 演示


为半个字符应用CSS样式可能吗?,布布扣,bubuko.com

时间: 2024-10-25 21:28:33

为半个字符应用CSS样式可能吗?的相关文章

CSS 样式书写规范

CSS书写顺序 1.位置属性(position, top, right, z-index, display, float等)2.大小(width, height, padding, margin)3.文字系列(font, line-height, letter-spacing, color- text-align等)4.背景(background, border等)5.其他(animation, transitio CSS书写规范 使用CSS缩写属性 CSS有些属性是可以缩写的,比如paddin

CSS基础学习十二:CSS样式

CSS样式包括:CSS背景,CSS文本,CSS字体,CSS列表,CSS表格,CSS轮廓等样式.我们就目前用到的 CSS样式简单地介绍一下. 下面只是总结性的一些东西,具体的可以参考:CSS样式教程 (1)背景色 background-color 设置背景颜色 可能的值: 颜色名称:如red,yellow,blue 十六进制颜色值:如#ffffff rgb颜色值:如rgb(255,255,255(十六进制为ff)) transparent:默认的,背景颜色透明 inherit:继承父元素的背景色

css样式表中四种属性选择器

css样式表中四种属性选择器1> 简易属性 tag[class]{ font-weight:bold } It will affect all tag with any class. e.g. <h2 class="old" > or <h2 class="new"> 2>精确属性值 a[href="http://www.cnblogs.cn"][title="textTitle"]{fon

HTML标记语言和CSS样式的简单运用(Nineteenth Day)

曾经励志下去要坚持把每天所学的知识记录下来,可是坚持了几天后,就觉得自己坚持不下去了....这几天自己好好的想了想,觉得不能坚持也得要坚持,因为要对自己负责,所以得学会逼着自己去做,只有这样才能把一件事做到底......今天就总结一下所学到的知识. 理论: HTML(Hyper Text Markup Language) 超文本标记语言 ?HTML文档 = 网页 ?HTML标签(不区分大小写)(有些大写是自动生成的) 页面包括“格式标签”和“页面内容” ?网页文件格式:.html或.htm HT

[WinXP] Chrome使用CSS样式强制使用微软雅黑字体出现口口的解决办法

XP下使用chrome(也包括FF.opera.IE等支持css定义样式的浏览器),为美观希望将页面字体强制显示为微软雅黑,但是在某些网站,会有部分字符无法显示,比如:www.taobao.com,https://www.zybuluo.com/mdeditor,究其原因,是由于这些网站使用了"图标字体",而微软雅黑不能够显示.这个问题估计不少人都遇到过.那么,能否"鱼和熊掌兼得"呢?答案是肯定的,将自定义样式改为以下代码即可: *:not([class*=&quo

HTML表单 CSS样式

1.HTML表单 <body rightmargin="50" leftmargin="50" background="未标题-1.jpg"> <from> <table border="0" cellspacing="3" align="center"> <tr> <td>邮箱:</td> <td>&l

网页设计—CSS样式基础

1.CSS样式表 (1)行内式 行内式也称为内联样式,是通过标记的style属性来设置元素的样式. 语法格式:<标记名 style="属性1:属性值;属性2:属性值;属性3:属性值;">内容</标记名> 语法中style是标记的属性,实际上任何HTML标记都拥有style属性,用来设置行内式. (2)内嵌式 内嵌式是将CSS代码集中写在HTML文档的<head>头部标记中,并且用<style>标记定义. 语法格式:<head>

利用css样式画各种图形--初步、进阶、高级(一)

转文请注明:穆乙 http://www.cnblogs.com/pigtail/archive/2013/02/17/2914119.html 利用css画图形,是个有利有弊的写法,好处是不用画图,且节省了一些流量,坏处是要写长串的css样式,而且有可能流量并没有减少,用与否视情况而定,个人选择. 下面是我做测试的一些图形,也是参考了一些网站,简单的注解一下和归纳了一下,其中并没涉及到复杂的css画图形. 其中用了css3.0的一些属性,所以这里声明:请用支持css3.0的浏览器看此文章! 正方

css部分样式整理-特殊字体格式、导航栏固定、块级元素与行内元素、html 元素的margin与padding默认值、css样式优先级概括等

1.一些特殊字体样式: 首行缩进2字符:{text-indent:2em;} 水平居中:{text-align:center;} 两端对齐:{text-align:justify;} 垂直居中:{vertical-align: middle;} 字间距2字符:{letter-spacing:2em;} 行间距2倍:{line-height:2;}     2.导航栏固定在页面某处(相对于<body>):     {position:fixed;left:  px;top:  px;}  3.块