简体   繁体   English

我怎样才能使 li 标签计数器样式在 DOM 中贯穿

[英]how can i make li tag counter style line through in DOM

i want my li tag in a ol tag have a line all over it but it just put the line on the content of the li tag how can i make it work?我希望我的 li 标签在 ol 标签中有一条线,但它只是把线放在 li 标签的内容上 我怎样才能让它工作? my code:`我的代码:`

ol.type = "i";
var li1 = document.createElement("li");
var li2 = document.createElement("li");
var li3 = document.createElement("li");
var li4 = document.createElement("li");
var li5 = document.createElement("li");

li1.textContent = "user dashboard";
ol.appendChild(li1);
li2.textContent = "admin dashboard";
ol.appendChild(li2);
li3.textContent = "authentication";
ol.appendChild(li3);
var ul = document.createElement("ul");
var li11 = document.createElement("li");
var li12 = document.createElement("li");
var li13 = document.createElement("li");
li11.textContent = "login";
ul.appendChild(li11);
ol.appendChild(ul);
li12.textContent = "register";
li12.style.textDecoration = "line-through";
ul.appendChild(li12);
ol.appendChild(ul);
li13.textContent = "log out";
ul.appendChild(li13);
ol.appendChild(ul);
li4.textContent = "about page";
ol.appendChild(li4);
li5.textContent = "contact page";
li5.style.textDecoration = "line-through";
ol.appendChild(li5);
document.body.appendChild(ol);
`

my code is on the left side but i want it to be like the right side`` enter image description here我的代码在左侧,但我希望它像右侧一样`` enter image description here

Use list-style-position: inside;使用list-style-position: inside;

https://codepen.io/battletag13/pen/OJROGjr https://codepen.io/battletag13/pen/OJROGjr

It's not supported in every browser but is supported on both Chrome/Chromium & Firefox.并非所有浏览器都支持它,但 Chrome/Chromium 和 Firefox 都支持它。

If I am not misunderstanding then you want a border around the LI tag instead of having the text cut down with a line:如果我没有误解,那么您需要在 LI 标签周围加一个边框,而不是用一行将文本截断:

...
//li12.style.textDecoration = "line-through";
li12.style.border = "1px solid red";
...
//li5.style.textDecoration = "line-through";
li5.style.border = "1px solid red";

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

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