美文网首页
从屌丝到架构师的飞越(CSS篇)-CSS文本

从屌丝到架构师的飞越(CSS篇)-CSS文本

作者: 走着别浪 | 来源:发表于2019-08-11 01:45 被阅读0次

一、介绍

CSS文本属性可定义文本的外观。通过文本属性,您可以改变文本的颜色、字符间距,对齐文本,装饰文本,对文本进行缩进,等等。用CSS给文字设置各种功能会更加方便。本章主要就是介绍如何用CSS设置各种效果等。

二、知识点介绍

1、CSS文本颜色

2、CSS字体

3、CSS书写方向

4、CSS字符间距

5、CSS行高

6、CSS文本对齐方式

7、CSS文本修饰

8、CSS首行缩进

9、CSS文本大小写

10、CSS空白设置

11、CSS字间距

12、CSS文本属性总结

三、上课对应视频的说明文档

1、CSS文本颜色

color :颜色值  文本的颜色

实例:

<html>

<head>

<style type="text/css">

body {color:red}

h1 {color:#00ff00}

p.ex {color:rgb(0,0,255)}

</style>

</head>

<body>

<h1>这是 heading 1</h1>

<p>这是一段普通的段落。请注意,该段落的文本是红色的。在 body 选择器中定义了本页面中的默认文本颜色。</p>

<p class="ex">该段落定义了 class="ex"。该段落中的文本是蓝色的。</p>

</body>

</html>

2、CSS字体

font 属性是声明设置所有字体属性。

字体语法:

font : font-style,font-variant,font-weight,font-size/line-height,font-family

2.1、font-family :字体  规定元素的字体系列

实例:

<html>

<head>

<style type="text/css">

p.serif{font-family:"Times New Roman",Georgia,Serif}

p.sansserif{font-family:Arial,Verdana,Sans-serif}

</style>

</head>

<body>

<h1>CSS font-family</h1>

<p class="serif">This is a paragraph, shown in the Times New Roman font.</p>

<p class="sansserif">This is a paragraph, shown in the Arial font.</p>

</body>

</html>

2.2、font-size :值  设置字体的尺寸

实例:

<html>

<head>

<style type="text/css">

h1 {font-size: 300%}

h2 {font-size: 200%}

p {font-size: 100%}

</style>

</head>

<body>

<h1>This is header 1</h1>

<h2>This is header 2</h2>

<p>This is a paragraph</p>

</body>

</html>

2.3、font-style :值  定义字体的风格

实例:

<html>

<head>

<style type="text/css">

p.normal {font-style:normal}

p.italic {font-style:italic}

p.oblique {font-style:oblique}

</style>

</head>

<body>

<p class="normal">This is a paragraph, normal.</p>

<p class="italic">This is a paragraph, italic.</p>

<p class="oblique">This is a paragraph, oblique.</p>

</body>

</html>

2.4、font-weight :值  设置文本的粗细

实例:

<html>

<head>

<style type="text/css">

p.normal {font-weight: normal}

p.thick {font-weight: bold}

p.thicker {font-weight: 900}

</style>

</head>

<body>

<p class="normal">This is a paragraph</p>

<p class="thick">This is a paragraph</p>

<p class="thicker">This is a paragraph</p>

</body>

</html>

2.5、font-variant:值    设置小型大写字母的字体显示文本,这意味着所有的小写字母均会被转换为大写,但是所有使用小型大写字体的字母与其余文本相比,其字体尺寸更小。

实例:

<html>

<head>

<style type="text/css">

p.normal {font-variant: normal}

p.small {font-variant: small-caps}

</style>

</head>

<body>

<p class="normal">This is a paragraph</p>

<p class="small">This is a paragraph</p>

</body>

</html>

2.6、font样式整合

font:italic bold 12px/20px arial,sans-serif;

实例:

<html>

<head>

<style type="text/css">

p.ex1

{

font:italic arial,sans-serif;

}

p.ex2

{

font:italic bold 12px/30px arial,sans-serif;

}

</style>

</head>

<body>

<p class="ex1">This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph.</p>

<p class="ex2">This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph.</p>

</body>

</html>

3、CSS书写方向

direction :值  文本的方向 / 书写方向。

实例:

<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>

4、CSS字符间距

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、CSS行高

line-height :值  设置行间的距离(行高)

实例:

<html>

<head>

<style type="text/css">

p.small {line-height: 90%}

p.big {line-height: 200%}

</style>

</head>

<body>

<p>

这是拥有标准行高的段落。

在大多数浏览器中默认行高大约是 110% 到 120%。

这是拥有标准行高的段落。

这是拥有标准行高的段落。

这是拥有标准行高的段落。

这是拥有标准行高的段落。

这是拥有标准行高的段落。

</p>

<p class="small">

这个段落拥有更小的行高。

这个段落拥有更小的行高。

这个段落拥有更小的行高。

这个段落拥有更小的行高。

这个段落拥有更小的行高。

这个段落拥有更小的行高。

这个段落拥有更小的行高。

</p>

<p class="big">

这个段落拥有更大的行高。

这个段落拥有更大的行高。

这个段落拥有更大的行高。

这个段落拥有更大的行高。

这个段落拥有更大的行高。

这个段落拥有更大的行高。

这个段落拥有更大的行高。

</p>

</body>

</html

6、CSS文本对齐方式

text-align:值    规定元素中的文本的水平对齐方式

实例:

<html>

<head>

<style type="text/css">

h1 {text-align: center}

h2 {text-align: left}

h3 {text-align: right}

</style>

</head>

<body>

<h1>这是标题 1</h1>

<h2>这是标题 2</h2>

<h3>这是标题 3</h3>

</body>

</html>

7、CSS文本修饰

text-decoration :值  规定添加到文本的修饰

实例:

<html>

<head>

<style type="text/css">

h1 {text-decoration: overline}

h2 {text-decoration: line-through}

h3 {text-decoration: underline}

h4 {text-decoration:blink}

a {text-decoration: none}

</style>

</head>

<body>

<h1>这是标题 1</h1>

<h2>这是标题 2</h2>

<h3>这是标题 3</h3>

<h4>这是标题 4</h4>

<p>

<a href="http://www.w3school.com.cn/index.html">这是一个链接</a>

</p>

</body>

</html>

8、CSS首行缩进

text-indent :值  规定文本块中首行文本的缩进

实例:

<html>

<head>

<style type="text/css">

p {text-indent: 1cm}

</style>

</head>

<body>

<p>

这是段落中的一些文本。

这是段落中的一些文本。

这是段落中的一些文本。

这是段落中的一些文本。

这是段落中的一些文本。

这是段落中的一些文本。

这是段落中的一些文本。

这是段落中的一些文本。

这是段落中的一些文本。

这是段落中的一些文本。

这是段落中的一些文本。

这是段落中的一些文本。

</p>

</body>

</html>

9、CSS文本大小写

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>

10、CSS空白设置

white-space:值  设置如何处理元素内的空白

实例:

<html>

<head>

<style type="text/css">

p

{

white-space: nowrap

}

</style>

</head>

<body>

<p>

这是一些文本。

这是一些文本。

这是一些文本。

这是一些文本。

这是一些文本。

这是一些文本。

这是一些文本。

这是一些文本。

这是一些文本。

这是一些文本。

这是一些文本。

这是一些文本。

</p>

</body>

</html>

11、CSS字间距

word-spacing :值  增加或减少单词间的空白(即字间隔)

实例:

<html>

<head>

<style type="text/css">

p.spread {word-spacing: 30px;}

p.tight {word-spacing: -0.5em;}

</style>

</head>

<body>

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

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

</body>

</html>

12、CSS文本属性总结

相关文章

网友评论

      本文标题:从屌丝到架构师的飞越(CSS篇)-CSS文本

      本文链接:https://www.haomeiwen.com/subject/hwtzdctx.html