All Projects → marcj → Css Element Queries

marcj / Css Element Queries

Licence: mit
CSS Element-Queries aka Container Queries. High-speed element dimension/media queries in valid css.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects
typescript
32286 projects

Projects that are alternatives of or similar to Css Element Queries

Fitty
✨ Makes text fit perfectly
Stars: ✭ 3,321 (-21.15%)
Mutual labels:  responsive
Re Flex
Resizable Flex layout container components for advanced React web applications
Stars: ✭ 349 (-91.71%)
Mutual labels:  responsive
Coderedcms
A content management system for marketing websites based on Django and Wagtail.
Stars: ✭ 386 (-90.84%)
Mutual labels:  responsive
Beautiful Jekyll
✨ Build a beautiful and simple website in literally minutes. Demo at https://beautifuljekyll.com
Stars: ✭ 3,778 (-10.3%)
Mutual labels:  responsive
Detection
ASP.NET Core Detection with Responsive View for identifying details about client device, browser, engine, platform, & crawler. Responsive middleware for routing base upon request client device detection to specific view.
Stars: ✭ 335 (-92.05%)
Mutual labels:  responsive
Responsive Bootstrap Toolkit
Responsive Bootstrap Toolkit allows for easy breakpoint detection in JavaScript
Stars: ✭ 364 (-91.36%)
Mutual labels:  responsive
Email Templates
📫 Create, preview, and send custom email templates for Node.js. Highly configurable and supports automatic inline CSS, stylesheets, embedded images and fonts, and much more!
Stars: ✭ 3,291 (-21.87%)
Mutual labels:  responsive
React Responsive Modal
Simple responsive react modal
Stars: ✭ 429 (-89.81%)
Mutual labels:  responsive
Kube
Kube is a professional and a responsive Hugo theme for developers and designers that offers a documentation section mixed with a landing page and a blog.
Stars: ✭ 349 (-91.71%)
Mutual labels:  responsive
Element Queries Spec
A spec for a Container-Style Element Query Syntax
Stars: ✭ 375 (-91.1%)
Mutual labels:  responsive
Guillotine
jQuery plugin to crop images within an area (fully responsive), allowing to drag (touch support), zoom and rotate.
Stars: ✭ 318 (-92.45%)
Mutual labels:  responsive
Minimal
Personal blog theme powered by Hugo
Stars: ✭ 330 (-92.17%)
Mutual labels:  responsive
React Native Responsive Grid
Bringing the Web's Responsive Design to React Native
Stars: ✭ 369 (-91.24%)
Mutual labels:  responsive
Layout
Flutter | Create responsive layouts for mobile, web and desktop
Stars: ✭ 312 (-92.59%)
Mutual labels:  responsive
React Social Network
Simple React Social Network
Stars: ✭ 409 (-90.29%)
Mutual labels:  responsive
Ember Light Table
Lightweight, contextual component based table for Ember 2.3+
Stars: ✭ 310 (-92.64%)
Mutual labels:  responsive
Postcss Responsive Type
Automagical responsive typography, built on PostCSS
Stars: ✭ 363 (-91.38%)
Mutual labels:  responsive
Fresnel
An SSR compatible approach to CSS media query based responsive layouts for React.
Stars: ✭ 431 (-89.77%)
Mutual labels:  responsive
Argon Dashboard
Argon - Dashboard for Bootstrap 4 by Creative Tim
Stars: ✭ 429 (-89.81%)
Mutual labels:  responsive
Django Cruds Adminlte
django-cruds is simple drop-in django app that creates CRUD for faster prototyping
Stars: ✭ 373 (-91.14%)
Mutual labels:  responsive

CSS Element Queries

Gitter

Element Queries is a polyfill adding support for element based media-queries to all new browsers (incl. IE7+). It allows not only to define media-queries based on window-size but also adds 'media-queries' functionality depending on element (any selector supported) size while not causing performance lags due to event based implementation.

It's a proof-of-concept event-based CSS element dimension query with valid CSS selector syntax.

Features:

  • no performance issues since it listens only on size changes of elements that have element query rules defined through css. Other element query polifills only listen on window.onresize which causes performance issues and allows only to detect changes via window.resize event and not inside layout changes like css3 animation, :hover, DOM changes etc.
  • no interval/timeout detection. Truly event-based through integrated ResizeSensor class.
  • automatically discovers new DOM elements. No need to call javascript manually.
  • no CSS modifications. Valid CSS Syntax
  • all CSS selectors available. Uses regular attribute selector. No need to write rules in HTML/JS.
  • supports and tested in webkit, gecko and IE(10+)
  • min-width, min-height, max-width and max-height are supported so far
  • works with any layout modifications: HTML (innerHTML etc), inline styles, DOM mutation, CSS3 transitions, fluid layout changes (also percent changes), pseudo classes (:hover etc.), window resizes and more
  • no Javascript-Framework dependency (works with jQuery, Mootools, etc.)
  • Works beautiful for responsive images without FOUC

More demos and information: http://marcj.github.io/css-element-queries/

Examples

Element Query

.widget-name h2 {
    font-size: 12px;
}

.widget-name[min-width~="400px"] h2 {
    font-size: 18px;
}

.widget-name[min-width~="600px"] h2 {
    padding: 55px;
    text-align: center;
    font-size: 24px;
}

.widget-name[min-width~="700px"] h2 {
    font-size: 34px;
    color: red;
}

As you can see we use the ~= attribute selector. Since this css-element-queries polyfill adds new element attributes on the DOM element (<div class="widget-name" min-width="400px 700px"></div>) depending on your actual CSS and element's dimension, you should always use this attribute selector (especially if you have several element query rules on the same element).

<div class="widget-name">
   <h2>Element responsiveness FTW!</h2>
</div>

Responsive image

    <div data-responsive-image>
        <img data-src="http://placehold.it/350x150"/>
        <img min-width="350" data-src="http://placehold.it/700x300"/>
        <img min-width="700" data-src="http://placehold.it/1400x600"/>
    </div>

Include the javascript files at the bottom and you're good to go. No custom javascript calls needed.

<script src="src/ResizeSensor.js"></script>
<script src="src/ElementQueries.js"></script>

See it in action:

Here live http://marcj.github.io/css-element-queries/.

Demo

Module Loader

If you're using a module loader you need to trigger the event listening or initialization yourself:

var ElementQueries = require('css-element-queries/src/ElementQueries');

 //attaches to DOMLoadContent
ElementQueries.listen();

//or if you want to trigger it yourself.
// Parse all available CSS and attach ResizeSensor to those elements which have rules attached
// (make sure this is called after 'load' event, because CSS files are not ready when domReady is fired.
ElementQueries.init();

Issues

  • So far does not work on img and other elements that can't contain other elements. Wrapping with a div works fine though (See demo).
  • Adds additional hidden elements into selected target element and forces target element to be relative or absolute.
  • Local stylesheets do not work (using file:// protocol).
  • If you have rules on an element that has a css animation, also add element-queries. E.g. .widget-name { animation: 2sec my-animation, 1s element-queries;}. We use this to detect new added DOM elements automatically.

License

MIT license. Copyright Marc J. Schmidt.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].