|
154 | 154 | clear: left; // 1 |
155 | 155 | font-weight: font-weight.$medium; // 2 |
156 | 156 | margin-inline-end: 1ch; // 3 |
| 157 | + |
| 158 | + /// If there is no field value, don't bother displaying the field name. |
| 159 | + &:has(+ .field-value:empty) { |
| 160 | + display: none; |
| 161 | + } |
157 | 162 | } |
158 | 163 |
|
159 | | - /// 1. Field values appear slightly muted. |
160 | | - /// 2. Because values may break onto new lines, we need to use bottom margin |
161 | | - /// to continue vertical rhythm. We only apply this when the field value is |
162 | | - /// the last of its type: We can't use `:last-child` because it is often |
163 | | - /// followed by an empty paragraph. (This can be simplified once |
164 | | - /// `margin-trim` is widely supported!) |
| 164 | + /// Field values appear slightly muted. |
| 165 | + |
165 | 166 | .field-value { |
166 | | - color: var(--theme-color-text-muted); // 1 |
| 167 | + color: var(--theme-color-text-muted); |
| 168 | + |
| 169 | + /// Empty field values need to clear floats to maintain margin. |
| 170 | + &:empty { |
| 171 | + clear: left; |
| 172 | + float: none; |
| 173 | + |
| 174 | + /// If the browser supports `:has()`, we can hide the field value entirely |
| 175 | + /// since the field name will be hidden as well. |
| 176 | + @supports selector(:has(+ :empty)) { |
| 177 | + display: none; |
| 178 | + } |
| 179 | + } |
167 | 180 |
|
| 181 | + /// Because values may break onto new lines, we need to use bottom margin |
| 182 | + /// to continue vertical rhythm. We only apply this when the field value is |
| 183 | + /// the last of its type: We can't use `:last-child` because it is often |
| 184 | + /// followed by an empty paragraph. (This can be simplified once |
| 185 | + /// `margin-trim` is widely supported!) |
168 | 186 | &:not(:last-of-type) { |
169 | | - margin-block-end: var(--rhythm, #{size.$rhythm-default}); // 2 |
| 187 | + margin-block-end: var(--rhythm, #{size.$rhythm-default}); |
170 | 188 | } |
171 | 189 | } |
172 | 190 | } |
0 commit comments