Last active
June 8, 2021 15:29
-
-
Save psebborn/3003095af2ff200126fe to your computer and use it in GitHub Desktop.
Sentence case for CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CSS doesn't have a text-transform: sentence case, | |
// so here's a little mixin to spoof it for you | |
@mixin sentence-case() { | |
text-transform: lowercase; | |
&:first-letter { | |
text-transform: uppercase; | |
} | |
} | |
// USAGE: | |
.form-label { | |
@include sentence-case(); | |
} | |
// COMPILED CSS: | |
.form-label { | |
text-transform: lowercase; | |
} | |
.form-label:first-letter { | |
text-transform: uppercase; | |
} |
After further thinking I went with these.
.case-none { text-transform: none }
.case-upper { text-transform: uppercase }
.case-lower { text-transform: lowercase }
.case-proper { text-transform: capitalize }
.letter-upper::first-letter { text-transform: uppercase }
.letter-lower::first-letter { text-transform: lowercase }
You can compose class="case-lower letter-upper"
to produce sentence case.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was working on some classes like this and came across this thread on google.
If you use classes like this then you could compose
class="case-lower case-sentence"
to get the first effect when you need it but otherwise have sentence just uppercase the first letter.