如何为HTML列表上的数字设置样式? [英] How to style the number on a html list?

查看:1651
本文介绍了如何为HTML列表上的数字设置样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在有序列表上设置或增加数字的大小

Is it possible to style or increase the size of the numbers only on a ordered list?

list ol 转换为仅使用CSS的 wikihow 步骤。

I am planning on turning a ordered list ol into something like wikihow steps using CSS only.

以下是一个演示示例: http://jsfiddle.net/ejRzy/ 1 /

Here is a example to play with: http://jsfiddle.net/ejRzy/1/

推荐答案

它可以使用CSS3而不是100%的跨浏览器(ie IE7)。使用伪:在元素和计数器复位和计数器增量之前,您可以隐藏列表样式并创建自己的。

It can be done using CSS3 but not 100% cross browser (namely IE7). using the pseudo :before element and counter-reset and counter-increment you can hide the list-style and create your own.

这里是一篇介绍如何操作的文章:对有序列表号进行样式设置

here is an article outlining how: Styling ordered list numbers

这里是从该文章创建的演示。

and here is a demo built from that article.

也是在可怕的链接腐烂的情况下 - 这里是主要的CSS代码所需的(这可以应用于任何有序列表)

Also in case of the dreaded link rot - here is the main CSS code required (this can be applied to any ordered list)

ol {
    counter-reset:li; /* Initiate a counter */
    margin-left:0; /* Remove the default left margin */
    padding-left:0; /* Remove the default left padding */
}
ol > li {
    position:relative; /* Create a positioning context */
    margin:0 0 6px 2em; /* Give each list item a left margin to make room for the numbers */
    padding:4px 8px; /* Add some spacing around the content */
    list-style:none; /* Disable the normal item numbering */
    border-top:2px solid #666;
    background:#f6f6f6;
}
ol > li:before {
    content:counter(li); /* Use the counter as content */
    counter-increment:li; /* Increment the counter by 1 */
    /* Position and style the number */
    position:absolute;
    top:-2px;
    left:-2em;
    -moz-box-sizing:border-box;
    -webkit-box-sizing:border-box;
    box-sizing:border-box;
    width:2em;
    /* Some space between the number and the content in browsers that support
       generated content but not positioning it (Camino 2 is one example) */
    margin-right:8px;
    padding:4px;
    border-top:2px solid #666;
    color:#fff;
    background:#666;
    font-weight:bold;
    font-family:"Helvetica Neue", Arial, sans-serif;
    text-align:center;
}
li ol,
li ul {margin-top:6px;}
ol ol li:last-child {margin-bottom:0;}​

此代码将生成自定义排序列表;虽然不是你要求的风格。我会把定制工作留给你:)欢呼

This code will produce a custom ordered list; albeit not the style you asked for. I will leave the customization work upto you :) cheers

这篇关于如何为HTML列表上的数字设置样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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