Properties can be added in the YAML frontmatter using
—
property1: value_of_property1
—
Additionally, properties can be added inline in the note itself, using property2:: value_of_property2.
I would like to create a CSS snippet to hide the inline property names from my notes. For example, if my note contains the following inline property: definition:: Some definition
I would like to hide the property name definition::, and only see the property value Some definition in preview mode.
Ideally, the property names would be hidden on inactive lines, and only display on active lines (on which my cursor is placed). An example of this is the following snippet to hide block IDs on inactive lines:
/* Hide block IDs on inactive lines */
.cm-blockid {
opacity: 0;
}
/* Show block IDs on active lines */
.cm-active .cm-blockid {
opacity: 1;
}
Things I have tried
I’ve looked on the internet and asked chatGPT, but did not find a satisfactory solution.
Well, not sure who makes it happen, but you can indeed style inline fields using CSS. If you’re using the [ ... ] the syntax you can write CSS selectors to target the key and/or value for a given key name separately. If you use the ( ... ) by default the key is hidden, but currently it also means you need to target all of those values as a group.
I can hopefully write up some examples when I get to computer later on today.
Which markup has been introduced by dataview or not intrigued me a little bit, so I tried the following document in my test vault (with Dataview installed) and in the Sandbox vault with nothing installed:
---
tags:
- f74691
myPropertyField: myPropertyValue
---
questionUrl:: http://forum.obsidian.md/t//74691
bodyInlineField:: body inline value
Another paragraph with a [squaredField:: squaredValue] and a (roundField:: roundValue).
`$= dv.span(dv.current())`
The following screenshots with explanations and CSS selectors are from reading mode.
Here we can see that the property fields are just the same, as expected, but none of the dataview enabled selectors are available, so neither bodyInlineField, squaredField or roundField are selectable by CSS.
In short, all of the fields defined above are available through dataview, but only the myPropertyField (and its value) and squaredField (and its value) is fully available for styling through CSS.
So the way to hide the key from something like [definition:: Some definition] in reading mode would be to use:
/* Hide (or format) the key element */
.inline-field-key[data-dv-key="definition"] {
display: none;
}
/* To apply formatting for the key value */
.inline-field-key[data-dv-key="definition"] + .inline-field-value {
background-color: inherit;
}
Sadly though, this only applies to reading mode, as live preview only allows for styling of the myPropertyField as can be seen in the image below.