CSS属性-字体

目录

一、font-size(重要)​

二、font-family (重要, 不过一般仅设置一次)​

三、font-weight(重要)​

四、font-style(一般)​

五、font-variant(了解)​

六、line-height(常用)​

七、font​


一、font-size(重要)

二、font-family (重要, 不过一般仅设置一次)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="./css/base.css">
  <style>
    
  </style>
</head>
<body>
  
</body>
</html>

base.css

body {
  font-family: "Microsoft YaHei", "Heiti SC", tahoma, arial, "Hiragino Sans GB", "\5B8B\4F53", sans-serif;
}

三、font-weight(重要)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      /* font-weight: bold; */
      font-weight: 700;
    }
  </style>
</head>
<body>
  
  <div class="box">我是div元素</div>
  <div>我是div元素</div>

</body>
</html>

四、font-style(一般)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      /* 斜体: 字体本身支持斜体时, 显示的斜体 */
      /* font-style: italic; */
      /* 倾斜: 让文本进行倾斜 */
      font-style: oblique;
    }
  </style>
</head>
<body>
  
  <div class="box">我是div元素</div>
  <div>我是div元素</div>

</body>
</html>

五、font-variant(了解)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      font-variant: small-caps;
    }
  </style>
</head>
<body>
  
  <div class="box">My Name Is Coderwhy</div>

</body>
</html>

六、line-height(常用)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      background-color: #f00;
      color: white;
      width: 200px;

      line-height: 2;
    }
  </style>
</head>
<body>
  
  <div class="box">
    我是div元素我是div元素我是div元素我是div元素我是div元素我是div元素我是div元素我是div元素我是div元素我是div元素我是div元素我是div元素我是div元素我是div元素
  </div>

</body>
</html>

 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      height: 100px;
      background-color: #f00;
      color: #fff;

      line-height: 100px;
    }
  </style>
</head>
<body>
  
  <div class="box">我是div元素</div>

</body>
</html>

七、font

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      /* 关于字体的属性 */
      font-size: 30px;
      font-weight: 700;
      font-variant: small-caps;
      font-style: italic;
      font-family: serif;
      line-height: 30px;

      /* 缩写属性 */
      /* 1.5的行高是相对于font-size的 */
      font: italic small-caps 700 30px/1.5 serif;
    }
  </style>
</head>
<body>
  
  <div class="box">我是div元素</div>

</body>
</html>

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值