Code Monkey home page Code Monkey logo

element-queries-spec's Introduction

CSS Element Queries

A spec for a container-style element query syntax in CSS

Read online: element-queries.html

What is this about?

This spec aims to define a syntax for scoped styles and element queries in a container query style, as well as the related selectors, functions, and units that make scoped styles and element queries versatile and powerful way to write layout-independent responsive conditions for elements in CSS.

Proposed Syntax

/* Scoped Style */
@element div {
  $this {
    background: lime;
  }
}

/* Element Query */
@element div and (min-width: 500px) {
  $this {
    background: lime;
  }
}

/* Container Query */
@element div and (min-width: 500px) {
  $this {
    background: lime;
  }
  html {
    background: red;
  }
}

/* Multiple Selectors */
@element #example-1, #example-2 {
  $this {
    background: lime;
  }
}

/* Multiple Conditions */
@element div and (min-width: 500px) and (min-characters: 5) {
  $this {
    background: lime;
  }
}

View Syntax Example: styles.css

Plugin & Demo

As a reference for the syntax described in the spec, I have included a JavaScript plugin that reads the proposed syntax and displays the desired behaviour of the proposed functionality.

View Plugin: element-queries.js

View Demo: demo.html

Related Projects

There are a few projects currently working with the syntax described in this spec:

Further Examples

More examples of this syntax can be found on Codepen by searching for "EQCSS".

Search Codepen for EQCSS: Codepen Search

Who am I?

I'm an independent web developer, not affiliated with any major companies. The research & development contained in this spec is my own.

How you can help

At this stage the work on this spec is focused on taking the existing EQCSS syntax for element queries as implemented by the EQCSS project and defining them in a more formal way so that other plugin builders could design plugins or tools that work with the EQCSS syntax as implemented by EQCSS.js

In the future once the first version of this document is complete, there will be an opportunity to extend the features described.

For now, the most productive way to provide input would be by contributing to the conversation in the Gitter chat room for the EQCSS project

Further Reading

element-queries-spec's People

Contributors

tomhodgins avatar

Watchers

 avatar  avatar

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.