https://github.com/binarybirds/swift-css
An awesome Swift CSS DSL library using result builders.
https://github.com/binarybirds/swift-css
Last synced: about 1 year ago
JSON representation
An awesome Swift CSS DSL library using result builders.
- Host: GitHub
- URL: https://github.com/binarybirds/swift-css
- Owner: BinaryBirds
- License: mit
- Created: 2021-07-11T04:32:20.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-07-30T18:27:28.000Z (almost 3 years ago)
- Last Synced: 2025-04-05T23:15:06.622Z (about 1 year ago)
- Language: Swift
- Homepage:
- Size: 168 KB
- Stars: 65
- Watchers: 6
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftCss
An awesome Swift CSS DSL library using result builders.
```swift
let css = Stylesheet {
Media {
All {
Background("#222")
}
Root {
Color(.blue)
}
Element(.div) {
BackgroundColor(.red)
Color(.white)
TextAlign(.left)
}
.pseudo(.nthChild(2))
}
Media("only screen and (max-width: 600px)") {
Id("custom-identifier") {
Background("#222")
Color(.cyan)
}
Class("custom-class") {
Background("#333")
Color(.aliceBlue)
}
Selector("ul > li > a") {
Background("black")
Color(.red)
.important()
}
.pseudo(.hover)
}
}
print(StylesheetRenderer(minify: false, indent: 4).render(css))
```
## Install
You can simply use `SwiftCss` as a dependency via the Swift Package Manager:
```swift
.package(url: "https://github.com/binarybirds/swift-css", from: "1.0.0"),
```
Add the `SwiftCss` product from the `swift-css` package as a dependency to your target:
```swift
.product(name: "SwiftCss", package: "swift-css"),
```
Import the framework:
```swift
import SwiftCss
```
That's it.
## Credits & references
- [Cascading Style Sheets](https://www.w3.org/Style/CSS/)
- [CSS Snapshot 2020](https://www.w3.org/TR/css-2020/)
- [CSS Working Group Editor Drafts](https://drafts.csswg.org/)
- [W3Schools CSS reference](https://www.w3schools.com/cssref/)
- [CSS: Cascading Style Sheets](https://developer.mozilla.org/en-US/docs/Web/CSS)
- [CSS3](https://www.quackit.com/css/css3/)