CSS属性-文本

text-decoration

  • text-decoration用于设置文字的装饰线

    • decoration是装饰/装饰品的意思;
  • text-decoration有如下常见取值:

    • none:无任何装饰线
      • 可以去除a元素默认的下划线
    • underline:下划线
    • overline:上划线
    • line-through:中划线(删除线)
  • a元素有下划线的本质是被添加了text-decoration属性

<style>
    div {
        text-decoration: underline;
    }
    p {
        text-decoration: overline;
    }
    h1 {
        text-decoration: line-through;
    }
    /* 去除a标签原有的下划线 */
    a {
        text-decoration: none;
    }
</style>

在这里插入图片描述

text-transform

  • text-transform用于设置文字的大小写转换
    • Transform单词是使变形/变换(形变);
  • text-transform有几个常见的值:
    • capitalize:(使首字母大写)将每个单词的首字符变为大写
    • uppercase:(大写字母)将每个单词的所有字符变为大写
    • lowercase:(小写字母)将每个单词的所有字符变为小写
    • none:没有任何影响
  • 实际开发中用JavaScript代码转化的更多.

text-indent

  • text-indent 用于设置第一行内容的缩进
  • text-indent: 2em; 刚好是缩进2个文字

em: 相对值,相对于父元素的值,2em表示相对于父元素的2倍

text-align(重要)

  • text-align: 直接翻译过来设置文本的对齐方式;

  • MDN: 定义行内内容(例如文字)如何相对它的块父元素对齐;

  • 常用的值

    • left:左对齐
    • right:右对齐
    • center:正中间显示
    • justify:两端对齐
  • W3C中的解释:

在这里插入图片描述

text-align官方解释:它用作用于行内级元素

<!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>
    div.text {
      /* 文本居中 */
      text-align: center;
    }
    div.img {
      /* 图片居中 */
      text-align: center;
    }
    div.block {
      /* 给块级元素居中 无效*/
      text-align: center;
    }
    div.content {
      width: 300px;
      height: 300px;
      background-color: skyblue;
      /* 块级元素居中 */
      margin: 0 auto;
    }
      /*justify演示*/
    p {
      width: 300px;
      background-color: orange;
      text-align: justify;
    }

  </style>
</head>
<body>
  <div class="text">我是div元素</div>
  <div class="img">
    <img src="../../images/diqiu.jpg" alt="地球">
  </div>
  <div class="block">
    <div class="content">块级元素</div>
  </div>
  <p>
    This CSS module defines properties for text manipulation and specifies their processing model. It covers line breaking, justification and alignment, white space handling, and text transformation. why
  </p>
</body>
</html>

在这里插入图片描述

word/letter-spacing

letter-spacingword-spacing分别用于设置字母、单词之间的间距

  • 默认是0,可以设置为负数

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值