Attributvergabe in CSS
bearbeitet von
@@Gerd
> wie kann ich das CSS möglichst kurz darstellen?
>
> ~~~ CSS
> th.Land {
> text-align:left;
> }
> th.PLZ {
> text-align:center;
> }
> th.Stadt {
> text-align:right;
> }
> td.Land {
> text-align:left;
> }
> td.PLZ {
> text-align:center;
> }
> td.Stadt {
> text-align:right;
> }
> ~~~
```css
.Land{text-align:left}.PLZ{text-align:center}.Stadt{text-align:right}
```
(Unter der Voraussetzung, dass keine anderen Elemente außer den Tabellenzellen diese Klassen tragen. Ansonsten:
```css
th,td{&.Land{text-align:left}&.PLZ{text-align:center}&.Stadt{text-align:right}}
```
)
Aber was ist der Sinn von „möglichst kurz“? „Möglichst lesbarer“ Code wäre ein erstrebenswerteres Ziel:
```css
th, td {
&.Land {
text-align:left;
}
&.PLZ {
text-align:center;
}
&.Stadt {
text-align:right;
}
}
```
🖖 Live long and prosper
{:@en}
--
*“In my home, the America I love, the America I've written about, that has been a beacon of hope and liberty for 250 years, is currently in the hands of a corrupt, incompetent and treasonous administration. Tonight, we ask all who believe in democracy and the best of our American spirit, to rise with us, raise your voices against authoritarianism, and let freedom reign.”*{:@en}
— Bruce Springsteen, Manchester 2025-05-14