html - 向现有 HTML 添加行号

标签 html css

我正在尝试将行号添加到行高不等的现有 html - 许多类型的字体大小和图像。 每行看起来像 -

<div id="1"><right><span>line 1</span></right></div>
<div id="2"><right><span>line 2</span></right></div>
<div id="3"><right><span>line 3</span></right></div>

有没有简单的方法来添加垂直对齐的行号? 谢谢

最佳答案

灵感来自 this问题,我已经为你的问题开发了一个解决方案。您可以使用 counter-reset and counter-increment property实现这一点

<html>
    <head>
        <style>
            .container {
              counter-reset: line;
            }
            .container .lineNum {
                display: block;
                line-height: 1.5rem;
            }

            .container .lineNum:before {
                counter-increment: line;
                content: counter(line);
                display: inline-block;
                margin-right: .5em;
            }
        </style>
    </head>
<body>
    <div class="container">
        <div id="1" class="lineNum"><right><span>line 1</span></right></div>
        <div id="2" class="lineNum"><right><span>line 2</span></right></div>
        <div id="3" class="lineNum"><right><span>line 3</span></right></div>
    </div>
</body>

</html>

关于html - 向现有 HTML 添加行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43110136/

相关文章:

php文件中的javascript/css弹出div

javascript - React-router:有没有办法使用历史推送在当前路径之后附加查询字符串?

html - 叠加层上的图像上传按钮...我的 CSS 有问题

css - Angular 2+ 多客户端 多样式表

css - Element UI - VueJS - 在 IOS 上选择输入双击错误

html - bootstrap + django,包装卡

javascript - jQuery 在当前选中的按钮旁边显示元素

javascript - 访问 iframe 之外的元素?

html - 是什么导致了这个盒子?

html - 带页脚和绝对定位的 2 列布局,100% 高度右列