用于在<ol>标记中设置OrderedList编号样式的CSS

时间:2016-11-16 02:06:22

标签: html css

我想左对齐一个有序列表,还要更改该有序列表中列表编号的样式。这是我的CSS:

.tour-features ol {
    text-align:left;
}

.tour-features ol > li:before {
    font-size: 24px;
    font-family: impact, sans-serif;    
}

以下是我在HTML中调用它的方法

<ol class="tour-features">
    <li>Check out our suggested Egypt Tours.</li>
    <li>Contact us for a free quote today.</li>
    <li>Let us customize any tour just for you.</li>
</ol>

它不起作用。 Here's my Codepen showing the result。没有什么变化。没有列表的左对齐,也没有更改有序列表中数字的默认外观。

我确信这很简单。我只是没有看到它。

1 个答案:

答案 0 :(得分:3)

您的css为2016-10-03 to 2016-10-10而不是.tour-features ol,您必须使用ol.tour-features,如下所示。

&#13;
&#13;
padding-left
&#13;
/*ol.tour-features {
    padding-left: 15px;
}

ol.tour-features > li {
    font-size: 24px;
    font-family: impact, sans-serif;    
}*/

ol.tour-features {
	counter-reset:li; /* Initiate a counter */
	margin-left:0; /* Remove the default left margin */
	padding-left:0; /* Remove the default left padding */
}
ol.tour-features > 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.tour-features > 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;}
&#13;
&#13;
&#13;