css - 有没有办法像在编辑器中一样将相同的样式应用于不同的 XML 标签/突出显示语法?
问题描述
用户可以上传xml
具有不同元素的自定义文件,每个文件的外观和结构可能不同。例如:
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
或者
<file>
<name>Tove</name>
<lastname>Jani</lastname>
<title>Reminder</title>
<content>Don't forget me this weekend!</content>
</file>
如何将相同的样式应用于两个不同的xml
文件?例如,将文本涂成橙色,将标签涂成蓝色。
编辑:根据BoltClock
评论,我想突出显示语法本身,就像在某种编辑器中看到的那样。
解决方案
我会将所有内容包装到另一个元素(即)中,然后从那里开始:
info > *:nth-child(odd) {
display: block;
background: orange;
}
info > *:nth-child(even) {
display: block;
background: yellow;
}
info > * > *:nth-child(1) {
display: block;
font-weight: bold;
}
info > * > *:nth-child(2) {
display: block;
}
info > * > *:nth-child(3) {
display: inline-block;
font-weight: bold;
}
info > * > *:nth-child(3):after {
content: ' :';
}
info > * > *:nth-child(4) {
display: inline-block;
}
<info>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<file>
<name>Tove</name>
<lastname>Jani</lastname>
<title>Reminder</title>
<content>Don't forget me this weekend!</content>
</file>
</info>
希望这可以帮助。
推荐阅读
- flutter - Flutter - 无法在 Mac 上使用 Android Studio 构建 IOS 应用程序
- python - 为什么 isnumeric isdigit 和 isdecimal False 为 1.5?
- python - 如何更新 tkinter 标签上的实时数据?
- python - Python 更快的“如果”用法
- p5.js - P5.js平台游戏
- python - 在输入 NLP 模型之前,您是否必须清理您的测试数据?
- python-3.x - How to iterate through rows and add number increments based on whether a number in a column increases
- c# - 按特定顺序组合列表c#
- svg - Svelte / D3 函数获取路径上的点
- apache - 如何在 url 中获取带有斜杠的参数过滤器