首页 > 解决方案 > 如何在标签的值内应用 css

问题描述

我有一个<label>包含多个值,如`

label = {Student[name] +  '(' + "20" + ')'}

现在我怎样才能marginLeft: '2rem'为标签的第二个值提供一些,即

'(' + "20" + ')'在同一个标​​签中。

标签: htmlcssreactjs

解决方案


使它的标签内容变为:

label = '<span>' + {Student[name] +  '(' + "20" + ')' + '</span>'}

然后在你的css中做类似的事情:

.my-wrapper > span {
    margin-left: 2rem;
}

.my-wrapper > span:first-of-type {
    margin-left: 0;
}

我认为这应该有效。将 .my-wrapper 替换为任何通用父选择器。

更新:
或在单个语句中:

.my-wrapper > span:not(:first-of-type) {
    margin-left: 2rem;
}

推荐阅读