Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

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.

HTML

              
                <h1 class="Page-heading">Responsive Comparison Table</h1>

<div class="Table js-ColumnTable" data-columns="2">
    
    <div class="Table-item Table-heading">The Prestige</div>
    <div class="Table-item Table-heading">Interstellar</div>

    <div class="Table-item">1 - Chris Nolan ✓ </div>
    <div class="Table-item ">1 - Chris Nolan ✓ </div>

    <!-- The br is there to test vertical align-->
    <div class="Table-item">2 - Matthew
        <br /> McConaughey ✗ </div>
    <div class="Table-item">2 - Matthew McConaughey ✓ </div>

    <div class="Table-item">3 - Anne Hathaway✗ </div>
    <div class="Table-item">3 - Anne Hathaway ✓ </div>

    <div class="Table-item">4 - Hugh Jackman ✓ </div>
    <div class="Table-item">4 - Hugh Jackman ✗ </div>

    <div class="Table-item">5 - Michael Caine ✓ </div>
    <div class="Table-item">5 - Michael Caine ✓ </div>

</div>

<hr />

<div class="Table js-ColumnTable" data-columns="4">
    
    <div class="Table-item Table-heading">Eddard Stark</div>
    <div class="Table-item Table-heading">Robb Stark</div>
    <div class="Table-item Table-heading">Jon Snow</div>
    <div class="Table-item Table-heading">Arya Stark</div>

    <div class="Table-item">Male </div>
    <div class="Table-item">Male </div>
    <div class="Table-item">Male </div>
    <div class="Table-item">Female </div>

    <div class="Table-item">Doesn't have a direwolf </div>
    <div class="Table-item">Has a direwolf: Grey Wind</div>
    <div class="Table-item">Has a direwolf: Ghost</div>
    <div class="Table-item">Has a direwolf: Nymeria</div>

    <div class="Table-item">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quo nobis, ab, sunt similique quis, non culpa obcaecati ex sed excepturi aliquid minima aspernatur saepe maiores magni ipsum iusto sequi facere.</div>
    <div class="Table-item">Word</div>
    <div class="Table-item">Word</div>
    <div class="Table-item">Word</div>

    <div class="Table-item">Has a sword named Ice</div>
    <div class="Table-item">Best mates with the one and only GREATJON UMBER</div>
    <div class="Table-item">Has a sword named Longclaw</div>
    <div class="Table-item">Has a sword named Needle</div>

    <div class="Table-item">Lord of Winterfell, Warden of the North </div>
    <div class="Table-item">DAKINGINDANORF</div>
    <div class="Table-item">Knows nothing</div>
    <div class="Table-item">No one</div>

</div>

<hr />

<div class="Table Table--striped4 js-ColumnTable" data-columns="4">
    
    <div class="Table-item Table-heading">Eddard Stark</div>
    <div class="Table-item Table-heading">Robb Stark</div>
    <div class="Table-item Table-heading">Jon Snow</div>
    <div class="Table-item Table-heading">Arya Stark</div>

    <div class="Table-item">Male </div>
    <div class="Table-item">Male </div>
    <div class="Table-item">Male </div>
    <div class="Table-item">Female </div>

    <div class="Table-item">Doesn't have a direwolf </div>
    <div class="Table-item">Has a direwolf: Grey Wind</div>
    <div class="Table-item">Has a direwolf: Ghost</div>
    <div class="Table-item">Has a direwolf: Nymeria</div>

    <div class="Table-item">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quo nobis, ab, sunt similique quis, non culpa obcaecati ex sed excepturi aliquid minima aspernatur saepe maiores magni ipsum iusto sequi facere.</div>
    <div class="Table-item">Word</div>
    <div class="Table-item">Word</div>
    <div class="Table-item">Word</div>

    <div class="Table-item">Has a sword named Ice</div>
    <div class="Table-item">Best mates with the one and only GREATJON UMBER</div>
    <div class="Table-item">Has a sword named Longclaw</div>
    <div class="Table-item">Has a sword named Needle</div>

    <div class="Table-item">Lord of Winterfell, Warden of the North </div>
    <div class="Table-item">DAKINGINDANORF</div>
    <div class="Table-item">Knows nothing</div>
    <div class="Table-item">No one</div>

</div>
              
            
!

CSS

              
                /*--------------------------*/
/* Pretty pictures */
/*--------------------------*/

@pad : 10px;
*,
*:before,
*:after {
    box-sizing: border-box;
}

@import url(https://fonts.googleapis.com/css?family=Roboto:100,200,300,400,500,600);
body {
    background-color: #2196F3;
    font-family: "Roboto";
    font-weight: 300;
}

.Table {
    margin: @pad*2;
}

.Table-item.Table-heading {
    background-color: #8BC34A;
    color: white;
    font-size: 2em;
    padding: @pad*2;
}

.Table-item {
    padding: @pad;
    background-color: #EEEEEE;
    z-index: 1;
    /* box-shadow: 0px 5px 5px rgba(0, 0, 0, 0.5); */
    border-bottom: 1px solid white;
    font-size: 1em;
}

.Page-heading {
    font-size: 4em;
    font-family: "Roboto";
    font-weight: 100;
    color: white;
    text-align: center;
}









/* Responsive Table stuff */

.Table {
    display: flex;
    flex-direction: row;
    flex-flow: row wrap;
    max-width: 100%;
    flex: 0 1 auto;
    flex-basis: 100%;
    align-content: flex-start;
}

.Table-item {
    display: flex;
    flex: 1 1 auto;
    /* flex-basis: 45%; */
    /* max-width: 45%; */
    
    flex-direction: column;
    margin: 0;
    vertical-align: middle;
    justify-content: center;
}


.mxn-TableItems(@n, @i: 2) when (@i =< @n) {
    [data-columns~="@{i}"] {
        .Table-item {
            flex-basis: 100%/@i;
            max-width: 100%/@i;
        }
    }
    .mxn-TableItems(@n, (@i + 1));
}
.mxn-TableItems(6);

@media all and (max-width: 700px) {
    .Table .Table-item {
        flex-basis: 100%;
        width: 100%;
        max-width: 100%;
    }
    
    /* need to remember how to recursion :\ */    
    .mxn-innerResponsiveTableItems(@numCols, @i) when (@i > 1) {
        [data-columns~="@{numCols}"] {
            .Table-item:nth-of-type(@{i}) {margin-top: @pad; }
            .Table-item:nth-of-type(@{numCols}n+@{i}) {order: @i; }
        }
        .mxn-innerResponsiveTableItems(@numCols, (@i - 1));
    }
    .mxn-ResponsiveTableItems(@n, @i: 2) when (@i =< @n) {
        .mxn-innerResponsiveTableItems(@i, @i);
        .mxn-ResponsiveTableItems(@n, (@i + 1));
    }
    .mxn-ResponsiveTableItems(6);
}

/* no-flexbox polyfill along with the js  */
.Table-polyfilled.Table {
    display: table !important;
    .Table-row {
        display: table-row !important;
        width: 100% !important;
        .Table-item {
            display: table-cell !important;
            width: initial !important;
        }
    }
}



/* Striped goodness */
.mxn-TableStripes(@n, @i: 1) when (@i =< @n) {
    // 4 (number of columns) x 2 (every second row)
    @second-row: @n*2;
    @sel: ~"@{second-row}n + @{i}";
    div:not(.Table-heading).Table-item:nth-child(@{sel}) {
        background-color: #B6B6B6;
    }
    .mxn-TableStripes(@n, (@i + 1));
}
// Param of num columns
.Table--striped3 {
    .mxn-TableStripes(3);
}
.Table--striped4 {
    .mxn-TableStripes(4);
}

/* Basically, you target every second item in a column, then repeat for number of columns (hence why you need the parameter of number of columns). It compiles to something like this: */
/* 
.Table--striped {
    div:not(.Table-heading).Table-item:nth-child(8n+1) {
        background-color: pink;
    }
    div:not(.Table-heading).Table-item:nth-child(8n+2) {
        background-color: pink;
    }
    div:not(.Table-heading).Table-item:nth-child(8n+3) {
        background-color: pink;
    }
    div:not(.Table-heading).Table-item:nth-child(8n+4) {
        background-color: pink;
    }    
}
*/

              
            
!

JS

              
                ;(function($) {
    $.fn.polyfillColumns = function() {
        return this.each(function(e) {
            $masterTable = $(this);
            $masterTable.addClass("Table-polyfilled");
            var startSlice = 0,
                endSlice = startSlice + numberColumns,
                numberItems = $masterTable.children().length,
                $items = $masterTable.find(".Table-item"),
                numberColumns = parseInt($masterTable.attr("data-columns"));
            /*slice and dice!*/
            for (var i = 0; i < numberItems; i += numberColumns) {
            	startSlice = i;
                endSlice = startSlice + numberColumns;
                $items.slice(startSlice, endSlice).wrapAll( '<div class="Table-row"></div>' );    
            }
        });
    };
}(jQuery));


(function(){
    if (!Modernizr.flexbox) {
    	$(".js-ColumnTable").polyfillColumns();   
    }
}(jQuery));

              
            
!
999px

Console