Code Monkey home page Code Monkey logo

elm-css's Introduction

Type-safe <style> tags for elm-lang/html

When using elm-reactor, there's currently no way to (easily) include a CSS file for use by your view. The elm-css package allows you to code type-safe stylesheets in Elm and render them to your view like any other node.

What makes elm-css "type-safe" is that all the IDs and classes used by your HTML nodes are set by functions that are built when your stylesheets are created. This ensures that they will match up.

For example:

type Id = MyId
type Class = MyClass

-- import a font
imports = ["https://fonts.googleapis.com/css?family=Droid+Sans:400"]

-- create a rule
rule =
    { selectors = [Css.Class MyClass]
    , descriptor = [("font-family", "Droid Sans")]
    }
    
-- create the stylesheet
stylesheet = Css.stylesheet imports [rule]

-- render some HTML that uses it
render =
    Html.div []
        [ stylesheet.node
        , div [ stylesheet.class MyClass ] [ Html.text "Droid Sans!" ]
        ]

List of currently supported features:

  • @import urls
  • Type selectors (e.g. "div")
  • Id selectors (e.g. "#content")
  • Class selectors (e.g. ".menu-item")
  • Descendant selectors (e.g. "div table")
  • Immediate child selectors (e.g. "hr > p")
  • Sibling selectors (e.g. "li ~ li")
  • Adjacent selectors (e.g. "br + p")
  • Pseudo classes and elements (e.g. "p:first-line:first-letter::after")

elm-css's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

billstclair

elm-css's Issues

Publish version 1.1.2

Hi @massung,

I see that, following my PR, you created a 1.2.0 tag but the latest version (compatible with Elm 0.19) is actually 1.1.2, so your library is still considered "not updated" by elm install. Can you please create a new tag?

License.txt

I like your approach to CSS in Elm and would like to incorporate it in a project. Your elm-package.json indicates a BSD3 license by default. Please also add a License.txt file to your repo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.