123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              - // here we generate the initial required data, something the server should 
- //  know about in order to generate the proper html and css.
- // this demo does not show a fully functional todo list, 
- //  as that would require server logic to perserve the state of the todos, 
- //  to enable the creation, deletion, modifying etc... of individual todos.
- function nth(n){ var a=n%10;return n+((n>13||n<10)?(a==1?"st":a==2?"nd":a==3?"rd":"th"):"th"); }
- todos = [];
- for(var i = 1; i <= 24; i++){ todos.push({ task: nth(i)+" task", done: Math.round(Math.random()) }); }

- // the todo template / form:
form(id="dumb-css" method="post" onsubmit="alert('this is not a usable form. there is no server logic to save todo changes');return false")
  - // remove the checked attribute on this (input#smart-css) to view what older browsers should see.
  - //   "older browsers" meaning any browser that doesn't support ~ and :checked selectors.
  input.invisible(type="checkbox" id="smart-css" tabindex="-1" checked)
  - // hidden todos state for disabling the update button / highlighting changes / everything 'smart'
  each todo, i in todos
    input.todo.invisible(type="checkbox" id="todo"+i name="is_"+i+"_done_b" title=todo.task checked=!!todo.done)
  #todos
    h1
      | Todos 
      small(style="-webkit-user-select:none")
    ul
      each todo, i in todos
        li(class="todo-item t"+i)
          label.todo-label.dumb-thing
            - // fallback todo checkbox, used for older browsers.
            input.real(type="checkbox" name="is_"+i+"_done_a" checked=!!todo.done)
            = " "+todo.task
          label.todo-label.smart-thing(for="todo"+i) 
            - // two checkboxes to illustrate the given todo state, 
            - //  as the real/'smart' checkboxes are somewhere in an ancestor parent
            input.faux.nc(type="checkbox" tabindex="-1")
            input.faux.c(type="checkbox" tabindex="-1" checked)
            = " "
            span= todo.task
    div
      .dumb-thing
        input.submit-changed(type="submit" name="save_set_a" value="Save")
      .smart-thing.submit-changed
        input(type="submit" name="save_set_b" value="Save")
        small.changed-todos= " "
      .smart-thing.submit-unchanged
        input(type="submit" name="save_set_b" value="Save" disabled)

- // the css magic:
- //  sorry about the mess and style inconsistency. 
- //  the <style> element should be visible on the page to debug the output.
- // some of the uses of "#smart-css ~ " are redundent/unnessesary.
style(style="display:block;font-family:monospace;white-space:pre-wrap;word-wrap:break-word;background:#111;color:#fff;padding:4px 7px")
    = "/* Generated CSS for "+todos.length+" todos. */\n"
    = "\n"
    = "/* boilerplate css */\n"
    = "body { margin: 10px; font: 14px/120% Sans-Serif; }\n"
    = "form { margin: 10px; border: 1px solid #ddd; padding: 8px 12px; border-radius: 4px; background: #fff; }\n"
    = "h1 { margin: 10px 0px; }\n"
    = "h1 small { font-size: 45%; font-weight: normal; vertical-align: middle; }\n"
    = "\n/* related to the hidden checkboxes */\n"
    = ".hidden { display: none; }\n"
    = ".invisible { position: absolute; top: 0px; left: 0px; width: 0px;height: 0px; }\n\n"
    = "\n\n"

    = "/* dumb-css boilerplate */\n"
    = "#dumb-css #todos .dumb-thing { display: block; }\n"
    = "#dumb-css #todos .smart-thing { display: none; }\n"
    = "#dumb-css #todos .todo-label { color: #000 }\n\n"

    = "/* smart-css todo boilerplate */\n"
    = "#smart-css:checked ~ #todos .dumb-thing { display: none }\n"
    = "#smart-css:checked ~ #todos .smart-thing { display: block }\n"
    = "#smart-css:checked ~ #todos .submit-unchanged { display: none }\n"
    = "#smart-css:checked ~ #todos .todo-item { color: #bbb }\n"
    = "#smart-css:checked ~ #todos .todo-item .faux { pointer-events: none }\n\n"

    = "/* todo counter magic */\n"
    = "#smart-css:checked {\n"
    = "  counter-reset: completed-todos total-todos changed-todos;\n"
    = "}\n"
    = "#smart-css:checked ~ .todo:checked {\n"
    = "  counter-increment: completed-todos total-todos;\n"
    = "}\n"
    = "#smart-css:checked ~ .todo {\n"
    = "  counter-increment: total-todos;\n"
    = "  outline: none;\n"
    = "}\n"
    = "#smart-css:checked ~ #todos h1 small:before {\n"
    = "  content: counter(completed-todos) '/' counter(total-todos);\n"
    = "}"
    = "\n\n"
    each todo, i in todos
      = "#smart-css:checked ~ #todo"+i+":focus ~ #todos .t"+i+" [type=checkbox]"+(i<todos.length-1?",\n":" ")
    = "{\n"
    = "  outline: 5px auto -webkit-focus-ring-color\n"
    = "}\n\n"

    each todo, i in todos
      = "#smart-css:checked ~ #todo"+i+":checked ~ #todos .t"+i+" .todo-label span"+(i<todos.length-1?",\n":" ")
    = "{\n"
    = "  text-decoration: line-through;\n"
    = "}\n\n"

    = "#smart-css:checked ~ "
    each todo, i in todos
      = "#todo"+i+":checked + "
    = "#todos h1 small:after {\n"
    = "  content: ' (hooray!)';\n"
    = "  font-weight: bold\n"
    = "}\n\n"

    each todo, i in todos
      = "#smart-css:checked ~ #todo"+i+(todo.done?":not(:checked)":":checked      ")+" ~ #todos .t"+i+(i<todos.length-1?",\n":" ")+""
    = "{\n"
    = "  color: rgb(0,100,200);\n"
    = "  counter-increment: changed-todos;\n"
    = "}\n\n"
    = "/* handling single change text */\n"
    each todo, i in todos
      = "#smart-css:checked ~ "
      each t, k in todos
        = "#todo"+k+(i!=k?(t.done?":checked":":not(:checked)"):(t.done?":not(:checked)":":checked"))
        = " ~ "
      = "#todos .changed-todos:after"+(i<todos.length-1?",\n":" ")+""
    = "{\n"
    = "  content: counter(changed-todos) ' change';\n"
    = "}\n\n"
    = "#smart-css:checked ~ #todos .changed-todos:after {\n"
    = "  content: counter(changed-todos) ' changes';\n}\n\n"

    = "/* each todo has a faux-checkbox to represent the real todo checkbox state */\n"
    each todo, i in todos
      = "#smart-css:checked ~ #todo"+i+":checked       ~ #todos .t"+i+" .nc,\n"
      = "#smart-css:checked ~ #todo"+i+":not(:checked) ~ #todos .t"+i+" .c"+(i<todos.length-1?",\n":" ")+""
    = "{\n  display: none\n}\n"


    = "/* update button magic */\n"
    = "#smart-css:checked ~ "
    each todo, i in todos
      = "#todo"+i+(todo.done?":checked":":not(:checked)")+" + "
    = "#todos .submit-changed {\n  display: none\n}\n"

    = "#smart-css:checked ~ "
    each todo, i in todos
      = "#todo"+i+(todo.done?":checked":":not(:checked)")+" + "
    = "#todos .submit-unchanged {\n  display: inline-block\n}"
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console