字体、图标字体、iconfont,行高、字体框、字体简写,水平垂直对齐、下划线省略号

本文介绍了网页中字体的使用,包括通过`@font-face`自定义字体,字体样式如`font-size`、`font-family`的设置,以及图标字体的运用,如Font Awesome的引入和使用。此外,还展示了如何通过伪元素和实体来实现图标展示,以及阿里字体库的使用。同时,讲解了行高、字体框的概念和设置,以及文本对齐方式和图片基线对齐的调整。文章最后讨论了下划线的添加和文本溢出的处理方式。
摘要由CSDN通过智能技术生成
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>

        /* 
        font-face可以将服务器中的字体直接提供给用户去使用 
            问题:
                1.加载速度
                2.版权
                3.字体格式
        
        */
        @font-face {
                /* 指定字体的名字 */
            font-family:'myfont' ;
            /* 服务器中字体的路径 */
            src: url('./font/ZCOOLKuaiLe-Regular.ttf') format("truetype");
        }

        p{
            /* 
            字体相关的样式 
                color 用来设置字体颜色
                font-size 字体的大小
                    和font-size相关的单位
                    em 相当于当前元素的一个font-size
                    rem 相对于根元素的一个font-size
                font-family 字体族(字体的格式)
                    可选值:
                        serif  衬线字体
                        sans-serif 非衬线字体
                        monospace 等宽字体
                            - 指定字体的类别,浏览器会自动使用该类别下的字体

                    - font-family 可以同时指定多个字体,多个字体间使用,隔开
                        字体生效时优先使用第一个,第一个无法使用则使用第二个 以此类推

                        Microsoft YaHei,Heiti SC,tahoma,arial,Hiragino Sans GB,"\5B8B\4F53",sans-serif


            */
            color: skyblue;
            font-size: 40px;

            /* font-family: 'Courier New', Courier, monospace; */
            font-family: myfont;
        }
    </style>
</head>
<body>
    <p style="width: 20em; height: 2em;background-color: pink; line-height: 2em;">
        今天天气真不错,Hello Hello How are you!
    </p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./fa/css/all.css">
</head>
<body>
    <!-- 
        图标字体(iconfont)
            - 在网页中经常需要使用一些图标,可以通过图片来引入图标
                但是图片大小本身比较大,并且非常的不灵活
            - 所以在使用图标时,我们还可以将图标直接设置为字体,
                然后通过font-face的形式来对字体进行引入
            - 这样我们就可以通过使用字体的形式来使用图标

        fontawesome 使用步骤
            1.下载 https://fontawesome.com/
            2.解压
            3.将css和webfonts移动到项目中
            4.将all.css引入到网页中
            5.使用图标字体
                - 直接通过类名来使用图标字体
                    class="fas fa-bell"
                    class="fab fa-accessible-icon"

     -->
    
    <i class="fas fa-bell" style="font-size:80px; color:red;"></i>
    <i class="fas fa-bell-slash"></i>
    <i class="fab fa-accessible-icon"></i>
    <i class="fas fa-otter" style="font-size: 160px; color:skyblue;"></i>
    <i class="fas fa-ad"></i>
    <i>jweofjweiof</i>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./fa/css/all.css">
    <style>
        li{
            list-style: none;
        }

        li::before{
            /* 
                通过伪元素来设置图标字体
                    1.找到要设置图标的元素通过before或after选中
                    2.在content中设置字体的编码
                    3.设置字体的样式
                        fab
                        font-family: 'Font Awesome 5 Brands';

                        fas
                        font-family: 'Font Awesome 5 Free';
                        font-weight: 900; 

            */
            content: '\f1b0';
            /* font-family: 'Font Awesome 5 Brands'; */
            font-family: 'Font Awesome 5 Free';
            font-weight: 900; 
            color: sandybrown;
            margin-right: 10px;
        }
    </style>
</head>
<body>

    <!-- <i class="fas fa-cat"></i> -->

    <ul>
        <li>锄禾日当午</li>
        <li>汗滴禾下土</li>
        <li>谁知盘中餐</li>
        <li>粒粒皆辛苦</li>
    </ul>

    <!-- 

        通过实体来使用图标字体:
            &#x图标的编码;
     -->
    <span class="fas">&#xf0f3;</span>
    <span class="fas">&#xf1b0;</span>
</body>
</html>

阿里字体库

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./iconfont/iconfont.css">
    <style>
        i.iconfont{
            font-size: 100px;
        }

        p::before{
            content: '\e625';
            font-family: 'iconfont';
            font-size: 100px;
        }
    </style>
</head>
<body>

    <i class="iconfont">&#xe61c;</i>
    <i class="iconfont">&#xe622;</i>
    <i class="iconfont">&#xe623;</i>

    <i class="iconfont icon-qitalaji"></i>

    <p>Hello</p>
</body>
</html>

行高、字体框

        div{
            font-size: 50px;

            /* 可以将行高设置为和高度一样的值,使单行文字在一个元素中垂直居中 */
            line-height: 200px;

            /* 
                行高(line height)
                    - 行高指的是文字占有的实际高度
                    - 可以通过line-height来设置行高
                        行高可以直接指定一个大小(px em)
                        也可以直接为行高设置一个整数
                            如果是一个整数的话,行高将会是字体的指定的倍数
                    - 行高经常还用来设置文字的行间距
                        行间距 = 行高 - 字体大小

                字体框
                    - 字体框就是字体存在的格子,设置font-size实际上就是在设置字体框的高度

                行高会在字体框的上下平均分配

            */

            border: 1px red solid;

            /* line-height: 1.33; */
            /* line-height: 1; */
            /* line-height: 10 */
        }

字体简写

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div{
            border: 1px red solid;


            /* 
                font 可以设置字体相关的所有属性
                    语法:
                        font: 字体大小/行高 字体族
                        行高 可以省略不写 如果不写使用默认值
            
            */

            /* font-size: 50px;
            font-family: 'Times New Roman', Times, serif; */
            font-weight: bold;
            /* font: 50px/2  微软雅黑, 'Times New Roman', Times, serif; */
            /* font: normal normal 50px/2  微软雅黑, 'Times New Roman', Times, serif; */
            font: bold italic 50px/2  微软雅黑, 'Times New Roman', Times, serif;
            font: 30px/4 微软雅黑,'Times New Roman',Times,serif;
            /* font:50px 'Times New Roman', Times, serif;
            line-height: 2; */

            /* font-size: 50px; */

            /* font-weight 字重 字体的加粗 
                可选值:
                    normal 默认值 不加粗
                    bold 加粗
                    100-900 九个级别(没什么用)

                font-style 字体的风格
                    normal 正常的
                    italic 斜体
            */
            /* font-weight: bold; */
            /* font-weight: 500;
            font-style: italic; */



        }
    </style>
</head>
<body>
    
    <div>今天天气真不错 Hello hello</div>
    
</body>
</html>

水平垂直对齐,修改图片的基线对齐

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div{
            width: 800px;
            border: 1px red solid;

            /* 
                text-align 文本的水平对齐
                    可选值:
                        left 左侧对齐
                        right 右对齐
                        center 居中对齐
                        justify 两端对齐
            */
            /* text-align: center; */
            text-align: justify;

            font-size: 50px;
        }

        span{
            font-size: 20px;
            border: 1px blue solid;

                /*
                vertical-align 设置元素垂直对齐的方式
                    可选值:
                        baseline 默认值 基线对齐
                        top 顶部对齐
                        bottom 底部对齐
                        middle 居中对齐
                */
            vertical-align:middle; 
        }

        p{
            border: 1px red solid;

        }

        img{
            vertical-align: bottom;
        }
    </style>
</head>
<body>
    
<div>
    今天天气 Hello HelloHelloHelloHello <span>真不错 Hello</span></div>

    <div>
        Lorem ipsum dolor, sit amet consectetur adipisicing elit. Illo nihil iure at ab atque nostrum molestiae totam porro, dolorem maiores repudiandae molestias veritatis, eligendi laudantium incidunt dolores corporis? Quibusdam, consequatur.
    </div>


    <p>
       <img src="./img/an.jpg" alt=""> 
    </p>

</body>
</html>

下划线

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box1{
            font-size: 50px;
            font-family: 微软雅黑;


            /* 
                text-decoration 设置文本修饰
                    可选值:
                        none 什么都没有
                        underline 下划线
                        line-through 删除线
                        overline 上划线
            */

            text-decoration: overline;

            /* text-decoration: underline red dotted; */
        }

        .box2{
            width: 200px;
            /* 
                white-space 设置网页如何处理空白
                    可选值:
                        normal 正常
                        nowrap 不换行
                        pre 保留空白

            */
            white-space: nowrap;
            overflow: hidden;
            /*省略号*/
            text-overflow:ellipsis;
        }
    </style>
</head>
<body>

    <div class="box2">
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur, minus fugit in perspiciatis reprehenderit consequuntur aspernatur repellat cumque quidem asperiores quaerat placeat, tenetur vel veritatis deserunt numquam. Dolores, cupiditate enim.
    </div>

    <div class="box1">
        今天天气真不错
    </div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值