html - html中带虚线下划线的目录

标签 html css tableofcontents

我正在尝试以 html 的形式创建目录

Introduction.................................1
Heading 1....................................1
Heading 2....................................2

现在我想要...从标题中的最后一个字符到右边的数字。

我可以在一个带有单个 tr 和两个 tds(一个用于标题,一个用于页码)的表格中获得这种工作方式,第一个 td 上有一个底部边框,但是 .. 贯穿整个边框而不仅仅是最后一个字符。

有没有更好的方法可以用 html 表示它?

至于为什么我在 HTML 中执行此操作,我们将其导出到 HTML-> PDF 转换器,因此它必须是 HTML。

这是我目前的情况

<h1>Contents</h1>

<ul>
    <li>
        <table style="width:100%">
            <tr style="">
                <td>System Overview Manual..adn the dog went to the zoo and had a really good time and it was really really good.</td>
                <td style="text-align: right; "> <span id='contents1'>2</span>

                </td>
            </tr>
        </table>
    </li>
</ul>

fiddle :http://jsfiddle.net/EBhAX/

最佳答案

您可以为点使用生成的内容...(我从 this post 中学到了这一点)

We create the dot leaders with a ‘:before’ pseudo-element attached to the LI elements. The pseudo-element fills the whole width of the list item with dots and the SPANs are put on top. A white background on the SPANs hides the dots behind them and an ‘overflow: hidden’ on the UL ensures the dots do not extend outside the list: (from this w3.org article)

编辑:更新代码以允许嵌套列表

FIDDLE

标记

<ul class="outer">
    <li><a href="#">Introduction</a><span>1</span></li>
    <li class="nested">
        <ul class="inner">
            <li><a href="#">Header 1</a><span>2</span>
            </li>
            <li><a href="#">Header 2</a><span>2</span>
            </li>
        </ul>
    </li>
    <li><a href="#">Header 2</a><span>3</span></li>
</ul>

CSS

ul
{
    list-style: none;
    padding: 0;
    overflow-x: hidden;
}
.outer {
    width: 70%;  
}
.inner
{
    padding-left: 20px;
}
li:not(.nested):before {
    float: left;
    width: 0;
    white-space: nowrap;
    content:". . . . . . . . . . . . . . . . . . . . "". . . . . . . . . . . . . . . . . . . . "". . . . . . . . . . . . . . . . . . . . "". . . . . . . . . . . . . . . . . . . . "
}
li a:first-child {
    padding-right: 0.33em;
    background: white
}
a + span {
    float: right;
    padding-left: 0.33em;
    background: white
}

关于html - html中带虚线下划线的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17716273/

相关文章:

tableofcontents - 在代码中使用目录?

jquery - 在CSS中隐藏滑动箭头按钮

html - 为什么 height 100% 不能将 div 完全扩展到页面底部?

html - <a> 标签会取消对齐

filter - 通过 CSS3(过滤器)更改图像颜色

c# - 使用 DocumentFormat.OpenXml (C#) 更新 .docx 文档中的目录

github-pages - 如何在渲染的Github页面README.md上生成目录(ToC)?

html - 在搜索框焦点上隐藏按钮

javascript - 弹出 :hover cannot be dismissed with blur()

Javascript - 自动启动/停止 setInterval