Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Querious</h1>
<h2>Element Query Demo</h2>
<p>This is not a serious element query plugin, just an experiment to demonstrate what the concept of element queries is about, prove how support can be written in JavaScript, and to highlight the features and limitations of such an approach.</p>
<h3>Limitations:</h3>
<ul>
  <li>not container-query style, works on individual elements only
  <li>can only use PX units
  <li>can only apply one instance of each condition per element
  <li>doesn't support IE9, and likely some other browsers too
</ul>
<h3>Element Query Demos</h3>

<h4>Min-width: <code>data-width=500</code></h4>
<div data-width=500></div>

<h4>Min-width &amp; Max-width: <code>data-width=400,600</code></h4>
<div data-width=400,600></div>

<h4>Min-height: <code>data-height=50</code></h4>
<div data-height=50>----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---- -----</div>

<h4>Min-characters &amp; Max-characters: <code>data-characters=5,10</code></h4>
<input data-characters=5,10 placeholder="Type 5-10 Characters">

<h4>Min-words &amp; Max-words: <code>data-words=2,5</code></h4>
<textarea data-words=2,5 placeholder="Type 2-5 words"></textarea>

<h4>Min-children: <code>data-children=4</code></h4>
<div data-children=4>This <strong>div</strong> contains <u>4</u> <strong>different</strong> <u>elements</u></div>

<blockquote>For a more fully-featured, easier-to-use, and more powerful element query syntax check out <a href=http://elementqueries.com>http://elementqueries.com</a></blockquote>
              
            
!

CSS

              
                .data-width { background: lime; }
.data-height { color: red; }
.data-characters { background: violet; }
.data-words { background: orange; }
.data-children { background: gold; }
              
            
!

JS

              
                /* Querious Element Query Demo: https://github.com/tomhodgins/querious */
var querious = (function(){
  var queries = [
    ['data-width','tag.offsetWidth'],
    ['data-height','tag.offsetHeight'],
    ['data-characters','(tag.value||tag.innerHTML).length'],
    ['data-words','var c=0,t=tag.value||tag.innerHTML;t.replace(/\\w\\b/g,function(){c++});c'],
    ['data-children','tag.querySelectorAll("*").length'],
  ]
  function scanQueries(){
    for (var i=0; i<queries.length; i++){
      if (document.querySelector('['+queries[i][0]+']')){
        scanTags(i)
      }
    }
  }
  function scanTags(query){
    var tag = document.querySelectorAll('['+queries[query][0]+']')
    for (var i=0; i<tag.length; i++){
      processTag(query,tag[i])
    }
  }
  function processTag(query,tag){
    var unit = tag.getAttribute(queries[query][0]).split(','),
        condition = queries[query][0],
        test = queries[query][1],
        min = unit[0],
        max = unit[1]
    if (
      ((unit.length === 1) && (min <= eval(test)))
      || ((unit.length === 2) && ((min <= eval(test)) && (eval(test) <= max)))
    ){
      tag.classList.add(condition)
    } else {
      tag.classList.remove(condition)
    }
  }
  window.addEventListener('load',scanQueries)
  window.addEventListener('resize',scanQueries)
  document.addEventListener('keyup',scanQueries)
  document.addEventListener('click',scanQueries)
})();
              
            
!
999px

Console