前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CSS + HTML <文字排列效果>

CSS + HTML <文字排列效果>

作者头像
网罗开发
发布2021-04-07 15:31:36
1.2K0
发布2021-04-07 15:31:36
举报
文章被收录于专栏:网罗开发网罗开发

svg 的使用:

具体详解,请看代码注释

代码语言:javascript
复制
<!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>
        body {
            margin: 0;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .text1 {
            width: 200px;
            height: 200px;
            border-radius: 50%;
            position: relative;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 40px;
            color: white;
            font-weight: bold;
            background-color: #9211e9;
            animation: zhuan 10s linear infinite;
            animation-play-state: paused;
        }

        .text1:hover {
            animation-play-state: running
        }

        @keyframes zhuan {
            0% {
                transform: rotate(0);
            }

            100% {
                transform: rotate(360deg);
            }
        }


        .text2 {
            width: 200px;
            height: 50px;
            background: rgb(16, 206, 212);
            margin: 30px;
            color: white;
            border-radius: 5px;
        }

        .text3 {
            width: 50px;
            height: 200px;
            margin: 30px;
            border-radius: 5px;
            background: rgb(9, 180, 38);
        }

        #text {
            /* 设置字体由上往下排列,当然直接文本设置也可以,但是文字的朝向却没办法通过rotate控制 */
            writing-mode: vertical-rl;
            font-size: 20px;
            letter-spacing: 0.4em;
        }
</style>
</head>

<body>
    <!-- 实现文字垂直排列 -->
    <div class="text3">
        <svg viewBox='0 0 50 380' width="50" height="200">
            <text style="fill: white;" id="text" x="25" y="30" rotate='-90'>writing vertical text</text>
        </svg>
    </div>
    
    <!-- 实现文字跟随路径排列 -->
    <div class="text1">
        <!-- view='x,y,width,height' -->
        <!-- x,y  相当于 svg 左上角的横坐标和纵坐标 -->
        <svg viewBox='-50 -50 300 300' width="200" height="200">
            <!-- 实现文字跟随路径排列 -->
            <defs>
                <!--  M x y 起始位置坐标 M100 0 圆所开始的坐标点  a100 100 圆的半径 -->
                <path id="circle" d="M100 0 a100 100 0 1 1 -1 0"></path>
            </defs>
            <text>
                <textPath xlink:href="#circle" style="fill: white;">
                    Text following a circle.............
                </textPath>
            </text>
        </svg>
    </div>

    <!-- 旋转文字方向 -->
    <div class="text2">
        <svg width="200" height="50">
            <!-- x y 坐标位置 -->
            <text x="7" y="30" style="fill: white;">
                It’s
                <!-- dx dy 定义文字所在坐标的位置  此处有6个字符,所以有6个坐标值 -->
                <!-- rotate 为每个字符的旋转度数 -->
                <tspan style="fill: yellow;" dx="0 4 -3 5 -4 6" dy="0 -3 7 3 -2 -8" rotate="5 10 -5 -20 0 15">shaken
                </tspan>, not stirred.
            </text>
        </svg>
    </div>
</body>
</html>
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2021-04-03,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 网罗开发 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档