简体   繁体   English

我可以在列表编号中添加文字吗

[英]Can I add text to my list numbering

I have an ordered list like 我有一个有序列表

  1. content1 内容1
  2. content2 内容2
  3. content3 内容3

As it is for a road trip route, I want it to be: 由于是公路旅行路线,我希望它是:

Day 1 : content1 第一天:content1

Day 2 : content2 第2天:content2

Day 3 : content3 第三天:content3

I can of course write it down as text, but i prefer having it as a list. 我当然可以将其记录为文本,但我更喜欢将其作为列表。 Is this possible? 这可能吗?

 ol { position:relative; padding-left: 50px; } ol li:before { content:"Day"; position:absolute; left:0; } 
 <ol> <li>content1</li> <li>content2</li> <li>content3</li> </ol> 

check this 检查这个

You can do it without positioning the list items - resetting the list and letting pseudo elements to do the rest: 您可以在不定位列表项的情况下完成此操作-重置列表并让pseudo元素来完成其余工作:

  1. Reset the list style using list-style-type:none and padding:0 使用list-style-type:nonepadding:0重置列表样式

  2. Now use an increment counter to get the required list numbering 现在使用增量counter获取所需的列表编号

See demo below: 请参见下面的演示:

 ul { list-style-type: none; padding: 0; counter-reset: list; } ul li:before { content: 'Day ' counter(list) ' : '; counter-increment: list; } 
 <ul> <li>content1</li> <li>content2</li> <li>content3</li> </ul> 

var routes = {}

//add to a list
routes.Day1 = 'Going Here!';
routes.Day2 = 'Resting';
//and keep adding so on

//to print/list the routes
console.log(routes);

//give it the tag and data
function add2html(tag, data) {
   var element = document.getElementById(tag);
   element.replaceWith(data);
};

// to add to day1
add2html('day1', routes.Day1)

Not sure what you're using so defaulting to javascript. 不确定您使用的是什么,因此默认为javascript。 Then in html. 然后在html中。

<!-- using <li></li> will give you numbers before -->
<ul id="day1"></ul>

You can achieve this by defining it as unordered list. 您可以通过将其定义为无序列表来实现。 Then in css define ul list-style as none. 然后在CSS中将ul列表样式定义为none。 Then use css before for every li as li:nth-of-type(1) selector with content Day 1:, li:nth-of-type(2) selector with content Day 2: and position it appropriately. 然后对每个li使用css before作为内容为Day 1的li:nth-​​of-type(1)选择器,内容为Day 2的li:nth-​​of-type(2)选择器,并将其适当放置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM