CSS属性-文本

前言


🦧上篇文章我们学习了CSS的相关概念,这篇文章我们将开始学习CSS中一些属性,本文章是入门级别的内容,同时也是个人学习笔记性质的内容,前端老鸟请绕路。

一.text-decoration


🐻‍❄️text-decoration用来设置文字的装饰线,text-decoration一般有如下的取值,我们一一来进行演示

  1. none:无任何装饰线,可以去除a标签的下划线。
  2. underline:下划线。
  3. overline:上划线。
  4. line-through:中划线(删除线)
html 复制代码
<style>
    .text-style1 {
      text-decoration: none;
      margin-bottom: 20px;
    }

    .text-style2 {
      text-decoration: underline;
      margin-bottom: 20px;
    }

    .text-style3 {
      text-decoration: line-through;
      margin-bottom: 20px;
    }

    .text-style4 {
      text-decoration: overline;
      margin-bottom: 20px;
    }
</style>

<body>
  <div class="text-style1">你好世界111!</div>
  <div class="text-style2">你好世界222!</div>
  <div class="text-style3">你好世界333!</div>
  <div class="text-style4">你好世界444!</div>
</body>

二.text-transform


🙈text-transform用于设置文字的大小写转换,transform单词的意思是使形变的意思。

  1. capitalize:(使...首字母大写, 资本化的意思)将每个单词的首字符变为大写。
  2. uppercase:(大写字母)将每个单词的所有字符变为大写。
  3. lowercase:(小写字母)将每个单词的所有字符变为小写。
  4. none:没有任何影响。
html 复制代码
<style>
    .text-style1 {
      text-transform: none;
      margin-bottom: 20px;
    }

    .text-style2 {
      text-transform: capitalize;
      margin-bottom: 20px;
    }

    .text-style3 {
      text-transform: uppercase;
      margin-bottom: 20px;
    }

    .text-style4 {
      text-transform: lowercase;
      margin-bottom: 20px;
    }
</style>
<body>
  <div class="text-style1">abcdefg</div>
  <div class="text-style2">abcdefg</div>
  <div class="text-style3">ABCDEFG</div>
  <div class="text-style4">ABCDEFG</div>
</body>

三.text-indent


🐸text-indent用于设置首行文本的缩进,text-indent: 2em刚好缩进两个空格。

html 复制代码
<style>
    .text-style1 {
      text-transform: none;
      width: 200px;
      background-color: antiquewhite;
      margin-bottom: 20px;
      padding: 16px;
      text-indent: 2em;
    }
</style>

<body>
  <div class="text-style1">风到这里就是黏,黏住过客的思念,雨到了这里缠成线,缠住我们留恋人世间,你在身边就是缘</div>
</body>

四.text-align


😳text-align直接翻译过来的意思使对齐方式,它有如下这些常用值。

  1. left左对齐
  2. right右对齐
  3. center中间对齐
  4. justify两端对齐
html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .text-style1 {
      width: 200px;
      background-color: antiquewhite;
      margin-bottom: 20px;
      padding: 16px;
      text-align: center;
    }

    .text-style2 {
      width: 200px;
      background-color: antiquewhite;
      margin-bottom: 20px;
      padding: 16px;
      text-align: left;
    }

    .text-style3 {
      width: 200px;
      background-color: antiquewhite;
      margin-bottom: 20px;
      padding: 16px;
      text-align: right;
    }

    .text-style4 {
      width: 200px;
      background-color: antiquewhite;
      margin-bottom: 20px;
      padding: 16px;
      text-align: justify;
    }
  </style>
</head>

<body>
  <div class="text-style1">风到这里就是黏</div>
  <div class="text-style2">风到这里就是黏</div>
  <div class="text-style3">风到这里就是黏</div>
  <div class="text-style4">风到这里就是黏</div>
</body>

</html>

五.letter-spacing、word-spacing


🙈这两个属性主要用来设置字母单词之间的间距内容单位是像素,默认值为0,可以设置负值。

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .text-style1 {
      width: 200px;
      background-color: antiquewhite;
      margin-bottom: 20px;
      padding: 16px;
      letter-spacing: 2px;
    }

    .text-style2 {
      width: 200px;
      background-color: antiquewhite;
      margin-bottom: 20px;
      padding: 16px;
      word-spacing: 4px;
    }
  </style>
</head>

<body>
  <div class="text-style1">classclassclassclass</div>
  <div class="text-style2">HelloWorld</div>
</body>

</html>

六.总结


😬这篇文章我们学习了文本相关的几个CSS属性,CSS相关的属性有非常多的内容,但是在日常开发中基本就是写的这几个属性,所以把这几个写好就基本满足了开发的要求了。

相关推荐
爱宇阳4 分钟前
npm 常用标签与使用技巧新手教程
前端·npm·node.js
@大迁世界9 分钟前
2025 年该选谁?npm vs yarn vs pnpm
前端·npm·node.js
crary,记忆10 分钟前
简介NPM 和 NPX
前端·学习·npm·node.js
JianZhen✓27 分钟前
现在在本地开发了一些代码A,又有了新需求要紧急开发代码B需要只上线代码B的代码,如何更好的处理这种情况
前端
郝学胜-神的一滴1 小时前
Cesium绘制线:从基础到高级技巧
前端·javascript·程序人生·线性代数·算法·矩阵·图形渲染
蒙奇D索大1 小时前
【计算机网络】408计算机网络高分指南:物理层编码与调制技术精讲
java·前端·学习·计算机网络
无盐海1 小时前
CSRF漏洞攻击(跨站请求伪造攻击)
前端·csrf
慧一居士2 小时前
CSS3 全部功能点介绍,使用场景,对应功能点完整使用示例
前端
烛阴2 小时前
深入Lua包(Package)与依赖管理
前端·lua
IT_陈寒2 小时前
5个Vue3性能优化技巧,让你的应用提速50% 🚀(附实测对比)
前端·人工智能·后端