Html 如何在标签的值中应用css
我有一个Html 如何在标签的值中应用css,html,css,reactjs,Html,Css,Reactjs,我有一个,它包含多个值,如` label = {Student[name] + '(' + "20" + ')'} 现在,我如何为标签的第二个值,即,提供一些marginLeft:'2rem' ”(“+”20“+”)”在同一标签中。使标签的内容类似于: label = '<span>' + {Student[name] + '(' + "20" + ')' + '</span>'} .my-wrapper > span
,它包含多个值,如`
label = {Student[name] + '(' + "20" + ')'}
现在,我如何为标签的第二个值,即,提供一些marginLeft:'2rem'
”(“+”20“+”)”
在同一标签中。使标签的内容类似于:
label = '<span>' + {Student[name] + '(' + "20" + ')' + '</span>'}
.my-wrapper > span {
margin-left: 2rem;
}
.my-wrapper > span:first-of-type {
margin-left: 0;
}
我认为这应该行得通。用任何通用父选择器替换.my包装器
更新:或者在一份声明中:
.my-wrapper > span:not(:first-of-type) {
margin-left: 2rem;
}
您可以在标签和css中写入
id
=“label”
#使用qvotaxon答案标记{margin left:2rem}
label = '<span class="myClz">' + {Student[name] + '(' + "20" + ')' + '</span>'}
.myClz:not(:first-child) {
margin-left: 2rem;
}
label=''+{Student[name]+'('+“20”+')'+'}
.myClz:不是(:第一个孩子){
左边距:2em;
}
在需要marginLeft的任何位置为这些值放置一个带有类的span,然后将marginLeft:'2rem'
添加到该resp类中!您知道CSS中的子选择器吗?您可以使用第n个子对象和目标对象,您可以在值周围添加无需类的跨距。并为所有子项添加边距。然后,通过将“类型的第一个”设置为“左边距0;”,可以覆盖第一个跨距的左边距@AniruddhaShevlelabel={Student[name]+(20)}
,这是给我的[object object]
,如何更正?谢谢这不起作用,因为每个html文档的ID应该是唯一的。OP希望为标签中的每个学生添加边距,第一个学生除外。因此将有多个元素。不应该使用ID,因为在这种情况下它不能是唯一的。在这种情况下,无论如何都不需要添加ID。