简体   繁体   English

更改CSS <li> Javascript或CSS中具有不同ID的项目

[英]Change CSS for <li> items with different ID in Javascript or CSS

Hy, I want to apply a css style for all my < li > tags after their id...the problem is that these tags have different id(autoincremental)...I made a screenshot in my firebug: 嗨,我想对所有<li>标签使用ID的css样式...问题是这些标签具有不同的id(自动递增)...我在萤火虫中制作了一个屏幕截图:

在此处输入图片说明

For all < li > items, ID is "abc_dev_view_menu_i*",where * is a number wich increments for each new item I add. 对于所有<li>项目,ID为“ abc_dev_view_menu_i *”,其中*是我添加的每个新项目的增量数字。

So how to manage this,how to apply the same style for all < li > in this case where the number from ID increments each time I add one item?I tried with javascript,using getElementById but nothing worked until now 那么如何管理这个问题,如何在所有<li>情况下都应用相同的样式 ,在这种情况下,每次我添加一项时ID的数字都会增加?

Use this attribute selector: 使用此属性选择器:

li[id^="abc_dev_view_menu_i"] {
   /* common style */
}

this CSS rule will apply a style to each li whose id attribute starts with abc_dev_view_menu_i (regardless of the incremental counter) 此CSS规则会将样式应用于其id属性以abc_dev_view_menu_i开头的每个li (与增量计数器无关)

或者,您可以对要应用样式的所有li使用单个类

build the id with a loop instruction, 使用循环指令建立ID,

for (i .....) id="abc_dev_view_menu_i"+i; 对于(i .....)id =“ abc_dev_view_menu_i” + i;

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

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