How to format the 2nd last headline of level ## with css

I have this note

---
aliases: [Notiz, ]
tags: [Notiz, ] 

---

## 1 A
### 1.1 a
### 1.2 a
## 2 B
### 2.1 b
### 2.2 b
## 3 C
### 3.1 c
### 3.2 c
## 4 D
### 4.1 d
### 4.2 d
## 5 E
### 5.1 e
### 5.2 e

and I’d like to have a yellow background for the second last ## headline. In this case, this should format only this headline.

## 4 D 

The formating should work in preview and edit mode.

What works:

This code

.HyperMD-header-2:last-child  {
    background-color: green !important; 
}

.HyperMD-header-2:nth-last-child(2)  {
    background-color: yellow !important; 
}

Looks so:

image

But when I open the arrows, there is no formating anymore.

image

(There is no change in view mode at the moment.)

What can I do to see the headlines “## 4 D” background yellow formated in edit and view mode, independent of if the headline is open or closed?

I don’t know, but you might find out by inspecting the element when it’s in that state. A bit of a guide to that if needed: Obsidian CSS Quick Guide

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.