Giter Club home page Giter Club logo

css-encapsulation-today's Introduction

CSS encapsulation today

This repo attempts to document the ways to have CSS encapsulation today.

In a drawing:

Use cases (the why):

  • Re-using components across websites
    • A component can be anything: a video player, a PDF viewer, a weather widget, an HTML5 ad

iframe

See the iframe/ folder.

An iframe in the most basic encapsulation method and since it's so old it works everywhere. Basically you are referencing a new HTML page inside the other one.

  • Advantages

    • Easy to implement
    • Works everywhere
  • Disadvantages

    • 2 HTTP requests for the HTML
    • The element container (iframe) doesn't scale with the page automatically
    • Parent site can't touch what is happening in the frame

Manual scoping

No example here. Basically you make sure styles don't touch other styles by prefixing everything and never using !important and taking great care in specifity matters.

Scoped stylesheets

Scoped stylesheets are not a solution to CSS encapsulation. The only thing scoped styles does is limit styles to a particular element in the DOM. It doesn't prevent styles from the parent page to cascade to the "component".

See the style-scoped/ folder.

  • Advantages

    • Easy to implement
  • Disadvantages

    • Browser support is limited (there is a polyfill)
    • Not a solution since styles bleed through

resources

Web components

Possibly the best solution. What we actually want.

See the two demos in directories shadow-dom and 'custom elements`.

  • Advantages

    • Encapsulate styles OR provide hooks for styling to parent element (see Reaching into Shadows with CSS here)
  • Disadvantages

    • Has to be polyfilled for now using Polymer
    • Relatively unstable, everything is being developed as we speak

See Polymer project.

Resources

css-encapsulation-today's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

css-encapsulation-today's Issues

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.