0010 CSS font style attributes: font-size, font-family, Unicode fonts, font-weight, font-style, comprehensive set, color, text-align, line-height, text-indent, text-decoration ,,,

CSS font style attributes, debugging tools

aims

  • application
    • Use css style font complete set of fonts
    • Using css attribute the appearance of a page element to add style
    • Use a common syntax emment
    • Developers can use the code debugging tools

1.font font

1.1 font-size: size

  • effect:

    font-size property is used to set the font size

p {  
    font-size:20px; 
}
  • unit:

    • Relative length unit may be used, an absolute length units may also be used.
    • The relative length units commonly used, we recommend the pixel unit px, use less absolute length units.

note:

  • After we text size, use the basic px, and other units rarely used
  • Google browser's default text size is 16px
  • However, different browsers may display the default font size is inconsistent, we try to give a clear value size, do not default size. General to the body designated the entire page text size

1.2 font-family: font

  • effect:

    font-family property for which font set.

p{ font-family:"微软雅黑";}
  • Web page commonly used fonts are Arial, Microsoft elegant black, black body and so on, such as the pages of all paragraphs of text font is set to Microsoft elegant black
  • You can specify multiple fonts at the same time, in the middle separated by commas, said that if the browser does not support the first font, it tries the next one, until you find the right font, if not all, of our computer places the default font shall prevail.
p{font-family: Arial,"Microsoft Yahei", "微软雅黑";}

General Tips:

1. 各种字体之间必须使用英文状态下的逗号隔开。
2. 中文字体需要加英文状态下的引号,英文字体一般不需要加引号。当需要设置英文字体时,英文字体名必须位于中文字体名之前。
3. 如果字体名中包含空格、#、$等符号,则该字体必须加英文状态下的单引号或双引号,例如font-family: "Times New Roman";。
4. 尽量使用系统默认字体,保证在任何用户的浏览器中都能正确显示。

CSS Unicode fonts

  • Why use Unicode fonts

    • Set the font name in the CSS, the direct write Chinese is possible. However, in the encoding file (GB2312, UTF-8, etc.) will produce distortion mismatch errors.
    • xp system does not support similar to Microsoft elegant black Chinese.
  • solve:

    • Option One: You can use English instead. For example font-family:"Microsoft Yahei".

    • Option Two: Use Unicode encoded directly in the CSS to write the name of the font to avoid these errors. Use Unicode font to write Chinese name, the browser can correct resolution.

      font-family: "\5FAE\8F6F\96C5\9ED1";   表示设置字体为“微软雅黑”。
Font Name English name Unicode encoding
Times New Roman SimSun \5B8B\4F53
Times New Roman NSimSun \65B0\5B8B\4F53
黑体 SimHei \9ED1\4F53
微软雅黑 Microsoft YaHei \5FAE\8F6F\96C5\9ED1
楷体_GB2312 KaiTi_GB2312 \6977\4F53_GB2312
隶书 LiSu \96B6\4E66
幼园 YouYuan \5E7C\5706
华文细黑 STXihei \534E\6587\7EC6\9ED1
细明体 MingLiU \7EC6\660E\4F53
新细明体 PMingLiU \65B0\7EC6\660E\4F53

为了照顾不同电脑的字体安装问题,我们尽量只使用宋体和微软雅黑中文字体


1.3 font-weight:字体粗细

  • 在html中如何将字体加粗我们可以用标签来实现
    • 使用 b 和 strong 标签是文本加粗。
  • 可以使用CSS 来实现,但是CSS 是没有语义的。
属性值 描述
normal 默认值(不加粗的)
bold 定义粗体(加粗的)
100~900 400 等同于 normal,而 700 等同于 bold 我们重点记住这句话

提倡:

我们平时更喜欢用数字来表示加粗和不加粗。

1.4 font-style:字体风格

  • 在html中如何将字体倾斜我们可以用标签来实现
    • 字体倾斜除了用 i 和 em 标签,
  • 可以使用CSS 来实现,但是CSS 是没有语义的

font-style属性用于定义字体风格,如设置斜体、倾斜或正常字体,其可用属性值如下:

属性 作用
normal 默认值,浏览器会显示标准的字体样式 font-style: normal;
italic 浏览器会显示斜体的字体样式。

小技巧:

平时我们很少给文字加斜体,反而喜欢给斜体标签(em,i)改为普通模式。

1.5 font:综合设置字体样式 (重点)

font属性用于对字体样式进行综合设置

  • 基本语法格式如下:
选择器 { font: font-style  font-weight  font-size/line-height  font-family;}
  • 注意:
    • 使用font属性时,必须按上面语法格式中的顺序书写,不能更换顺序,各个属性以空格隔开。
    • 其中不需要设置的属性可以省略(取默认值),但必须保留font-size和font-family属性,否则font属性将不起作用。
    • 如果font采用综合写法,在综合写法中,没有指定line-height,而前面没有指定,则会覆盖前面的line-height。
        p {
            width: 120px;
            height: 30px;
            /* line-height: 30px; */  /* 不生效,会被下面的font: 900 16px "arial" 覆盖掉, */
            text-align: center;
            background-color: lightskyblue;
            /* 要么写成 font: 900 16px/30px "arial",要么在下面加一行 line-height: 30px; */
            font: 900 16px "arial"; 
            line-height: 30px;
            border-radius: 15px;
            color: white;
        }

在这里插入图片描述

1.6 font总结

属性 表示 注意点
font-size 字号 我们通常用的单位是px 像素,一定要跟上单位
font-family 字体 实际工作中按照团队约定来写字体
font-weight 字体粗细 记住加粗是 700 或者 bold 不加粗 是 normal 或者 400 记住数字不要跟单位
font-style 字体样式 记住倾斜是 italic 不倾斜 是 normal 工作中我们最常用 normal
font 字体连写 1. 字体连写是有顺序的 不能随意换位置 2. 其中字号 和 字体 必须同时出现

2. CSS外观属性

2.1 color:文本颜色

  • 作用:

    color属性用于定义文本的颜色,

  • 其取值方式有如下3种:

表示表示 属性值
预定义的颜色值 red,green,blue,还有我们的御用色 pink
十六进制 #FF0000,#FF6600,#29D794
RGB代码 rgb(255,0,0)或rgb(100%,0%,0%)
  • 注意

    我们实际工作中, 用 16进制的写法是最多的,而且我们更喜欢简写方式比如 #f00 代表红色

2.2 text-align:文本水平对齐方式

  • 作用:

    text-align属性用于设置文本内容的水平对齐,相当于html中的align对齐属性。
    【1、盒子内的文字水平居中是 text-align: center, 而且还可以让 行内元素和行内块居中对齐。 2、块级盒子水平居中 左右margin 改为 auto 。

  • 其可用属性值如下:

属性 解释
left 左对齐(默认值)
right 右对齐
center 居中对齐
  • 注意:

    是让盒子里面的内容水平居中, 而不是让盒子居中对齐。


2.3 line-height:行间距

  • 作用:

    line-height属性用于设置行间距,就是行与行之间的距离,即字符的垂直间距,一般称为行高。

  • 单位:

    • line-height常用的属性值单位有三种,分别为像素px,相对值em和百分比%,实际工作中使用最多的是像素px
  • 技巧:

一般情况下,行距比字号大7.8像素左右就可以了。
line-height: 24px;

2.4 text-indent:首行缩进

  • 作用:

    text-indent属性用于设置首行文本的缩进,

  • 属性值

    • 其属性值可为不同单位的数值、em字符宽度的倍数、或相对于浏览器窗口宽度的百分比%,允许使用负值,
    • 建议使用em作为设置单位。

1em 就是一个字的宽度 如果是汉字的段落, 1em 就是一个汉字的宽度

p {
      /*行间距*/
      line-height: 25px;
      /*首行缩进2个字  em  1个em 就是1个字的大小*/
      text-indent: 2em;  
 }

2.5 text-decoration 文本的装饰

text-decoration 通常我们用于给链接修改装饰效果

描述
none 默认。定义标准的文本。 取消下划线(最常用)
underline 定义文本下的一条线。下划线 也是我们链接自带的(常用)
overline 定义文本上的一条线。(不用)
line-through 定义穿过文本下的一条线。(不常用)

2.6 CSS外观属性总结

属性 表示 注意点
color 颜色 我们通常用 十六进制 比如 而且是简写形式 #fff
line-height 行高 控制行与行之间的距离
text-align 水平对齐 可以设定文字水平的对齐方式
text-indent 首行缩进 通常我们用于段落首行缩进2个字的距离 text-indent: 2em;
text-decoration 文本修饰 记住 添加 下划线 underline 取消下划线 none

Guess you like

Origin www.cnblogs.com/jianjie/p/12125642.html