HTML / CSS自动编号标题? [英] HTML / CSS autonumber headings?

查看:224
本文介绍了HTML / CSS自动编号标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法(理想上很容易)使标题和部分在HTML / CSS自动编号?也许是一个JS库?

Is there a way (ideally easy) to make headings and sections autonumber in HTML/CSS? Perhaps a JS library?

还是这些东西在HTML中很难做?

Or is this something that is hard to do in HTML?

查看公司wiki的应用程序,但我们希望能够使用标题数字,就像我们在字处理程序中一样。

I'm looking at an application for a corporate wiki but we want to be able to use heading numbers like we always have in word processors.

推荐答案

如果您想知道如何操作,请参阅此其他问题在CSS中,答案可能是你正在寻找。

See this other question if you're wondering how to do it in CSS, the answer might be what you are looking for. But titel has a good proposition too, depending how your HTML document is made.

// Edit:

应该注意的是,正如Triptych在另一篇评论中所说的,只有当它是一个内部工具,你可以控制哪些浏览器使用和使用CSS是值得的,因为修改HTML将是困难的例子。支持此CSS功能有限。

It should be noted that, as Triptych said in another comment, this is of interest only if it's for an internal tool where you have control over which browsers are used and using CSS is worth it because modifying the HTML would be hard for example. Support of this CSS feature is limited.

使用 jQuery 做增量也。像这样未经测试的代码段:

It would of course be easy to use something like jQuery to do the increment also. Something like this untested snippet:

$(document).ready(function() {
  $('h1').each(function(index) {
    $(this).html((index + 1) + '. ' + $(this).html());
  });
});

不要忘记在您的文档中包含jquery.js文件。

Don't forget to include the jquery.js file in your document of course.

这篇关于HTML / CSS自动编号标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆