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.

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

              
                <main>
<!--
Pen is used in this article:
https://medium.com/boana-stories/the-large-desktop-experience-in-responsive-design-fdca7d1fde2c#.c4agx9wrt

-->
<div class="choise-bar">
  <h3><i>1</i>Choose a layout option</h3>
  <button id="choose-limited" class="active">Fixed layout</button>
  <button id="choose-liquid">Liquid layout</button>
  <h3><i>2</i>Drag the handle</h3>
</div>

<div class="matrix">
  <div class="box-background"></div>
  <div class="breakpoint-bar">
    <div class="mobile-viewport-class"><span>Mobile</span></div>
    <div class="wide-mobile-viewport-class"><span>Landscape mobile<br> & Phablets</span></div>
    <div class="tablet-portrait-viewport-class"><span>Tablet Portrait</span></div>
    <div class="desktop-viewport-class"><span>Desktop and<br> Landcape Tablet</span></div>
    <div class="large-desktop-viewport-class active"><span>Large Desktop</span></div>
  </div>
  <div class="resizable-box" unselectable="on">
    <div class="resizable-box-content" unselectable="on">
      <!-- Start content -->
      <div class="grafic-container-box" unselectable="on">
        <div class="wrapper-box wrapper-box-fixed" unselectable="on">
          <div class="page">
            <span class="label">Layout</span>
          </div>
        </div>
      </div>
      <!-- End content -->
    </div>
    <div class="handle"></div>
  </div>
</div>
  
</main>
              
            
!

CSS

              
                body {
  background-color: #f4f6f7;
  font-size:  75%; // 12px
  color: #4B4B4B;
  text-align: center;
  margin: 2em 0 0;
  font-family: Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

main {
  display: inline-block;
  width: 740px;
  text-align: left;
  border: 1px solid #ecf0f1;
  border-radius: 8px;
  padding: 20px;
  background: #fff;
}

$max-width-of-matrix: 58.333333em;  // 700px;
$min-width-of-matrix: 16.666666em;  // 200px;

.choise-bar {
  display: block;
  max-width: $max-width-of-matrix;
  width: auto;
  min-width: 320px;
  padding: 0 1em;
  text-align: left;
  h3 {
    font-weight: bold;
    display: block;
    margin: 3em auto 1em;
    i {
      font-style: normal;
      border-radius: 50%;
      width: 2em;
      height: 2em;
      padding-top: 0.4em;
      display: inline-block;
      text-align:center;
      background-color: #4B4B4B;
      color: #fff;
      position: relative;
      top: -0.1em;
      margin-right: 0.5em;

    }
  }
  button {
    outline: 0;
    border: 0;
    color: #fff;
    padding: 0.75em 2em;
    margin: 0 .25em;
    cursor: default;
    background-color: lightgrey;
    
    &:hover {
       box-shadow: 0px 1px 2px 0px rgba(0,0,0,0.3);
    }
    &:active {
      box-shadow: inset 0px 1px 3px 0px rgba(0,0,0,0.25);
    }
    &.active {
      cursor: pointer;
      background-color: #3997d3;
      box-shadow: none !important;
    }
  }
}

/* Interactive Matrix Grafics */
.matrix {
  width: 100%;
  margin: 2em auto 0;
  display: inline-block;
  user-select: none;
  position: relative;
  
  .box-background {
    background-color:  #f5f5f8;
    background-color: rgba(0,0,0,0.02);
    position: absolute;
    width: 100%;
    height: 16em;
    top: 4em;
  }
  .breakpoint-bar, .resizable-box {
    width: 56.25em;
    position: relative;
    float: left;
    clear: both;
  }
  .breakpoint-bar {
    height: auto;
    height: 3em;
    padding-left: 10%;
    margin-bottom: 1em;
    overflow: hidden;
    
    div {
      width: 20%;
      padding: 0.5em 0.5em 0 0.5em;
      float: left;
      text-align: right;
      color: #d0d0d0;
      
      span {
        font-size: 1em;
        vertical-align: middle;
        text-align: right;
      }
      &.active {
        color:#4B4B4B;
      }
      &.disabled {
      visibility: hidden;
      }
    }
  }
  .resizable-box {
    position: relative;
    min-width: $min-width-of-matrix;
    max-width: $max-width-of-matrix;
    height: 19em;
    width: 100%;
    margin-top: -3em;
    padding: 3em 0 0;
    cursor: auto;
    border-right: 1px solid #d0d0d0;
    .resizable-box-content {
      width: 100%;
      height: 100%;
      overflow: hidden;
    }
    .handle {
      width: 4em;
      height: 4em;
      position: absolute;
      text-align: center;
      top: 50%;
      margin-top: -1em;
      padding: 1.25em 0 0;
      right: -2em;
      border-radius: 50%;
      background-color: #4B4B4B;
      border-color: #fff;
      transition: background-color 300ms ease, border-color 300ms ease;
      &:before {
        content: '';
        display: inline-block;
        width: 0;
        height: 0;
        border-color: inherit;
        border-style: solid;
        border-top-width: .8em;
        border-top-color: transparent;
        border-bottom-width: .8em;
        border-bottom-color: transparent;
        border-right-width: .8em;
        border-left-width: 0;
        margin-right: .3em;
      }
      &:after {
        content: '';
        display: inline-block;
        width: 0;
        height: 0;
        border-color: inherit;
        border-style: solid;
        border-top-width: .8em;
        border-top-color: transparent;
        border-bottom-width: .8em;
        border-bottom-color: transparent;
        border-left-width: .8em;
        border-right-width: 0;
      }
      &:hover {
        cursor: pointer;
        cursor: col-resize;
        background-color: #000;
        border-color: #fff;
      }
    }
    span.area-info {
      display: block;
      position: absolute;
      text-align: center;
      font-size: 3.4em;
      font-family: Arial, sans-serif;
      color: rgba(0,0,0,0.4);
      width: 100%;
      top: 50%; 
      height: 1em;
      margin-top: -1.2em;
    }
  }
}


.grafic-container-box {
  min-width: $min-width-of-matrix;
  max-width: $max-width-of-matrix;
  height: 23.333333em;
  overflow: hidden;
  background-color: #3997d3;
  position: relative;
  overflow: hidden;
   
  .wrapper-box {
    position: relative;
    text-align: center;
    margin-left: auto;
    margin-right: auto; 
    min-width: 50%;
    max-width: 100%;
    width: auto;
    height: 100%;
    overflow: hidden;
    background-color: #96BDD9;
    background-color: rgba(255,255,255,0.3);
    padding: 0 1em;
    
    .page {
      background-color: rgba(255,255,255,0.3);      
      display: block;
      width: 100%;
      height: 100%;
      vertical-align: middle;
    }
    .label {
      display: inline-block;
      text-align: center;
      font-size: 2em;
      font-family: Arial, sans-serif;
      color: #e5e5e5;
      color: rgba(0,0,0,0.4);
      vertical-align: middle;
      line-height: 7.5em;
    }
  }
}

[foo], .grafic-container-box .wrapper-box {
    transition: max-width 150ms ease-in-out, width 150ms ease-in-out;
    
}
.grafic-container-box .wrapper-box-fixed {
    max-width: 560px;
    margin-left: auto;
    margin-right: auto; 
}
.grafic-container-box .wrapper-box-liquid {
    //max-width: 560px;
}


.grid-container {
    position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
    background: none !important;
    
}
.grid-container > div {
    padding: 0px;
    width: 8.333334%;
    height: 100%;
    float: left;
    overflow: hidden;
    background-color: #ebebeb;
}
[foo] , .grid-container > div {
    background-color: rgba(0,0,0,0.05);
    transition: width 300ms ease-in-out;
    
}

.grid-container > div > div {
    padding: 0px;
    margin: 0px 6px;
    width: auto;
    display: block;
    height: 100%;
    overflow: hidden;
    background-color: rgb(224, 224, 224);
    background-color: rgba(102,197,237,0.5);
}

.grid-container-16cols > div {
    width: 6.25%;
}
.grid-container span.grid-column-amount {
    display: block;
    position: absolute;
    text-align: center;
    font-size: 7em;
    font-family: Arial, sans-serif;
    color: #e5e5e5;
    color: rgba(0,0,0,0.4);
    width: 100%;
    top: 38%; 
    height: 1em;
    margin-top: -0.7em;
}

/* JS MEDIA QUERY */

/* media Desktop Class  */
.desktop .wrapper-box-maxwidth {
  max-width: none;
}
.desktop .wrapper-box-fixed {
  max-width: 440px;
}

/* media Tablet Portrait Class  */
.tablet-portrait .grid-container > div {
  width: 16.66666667%;
}
.tablet-portrait .grid-container > div:nth-child(even) {
  width: 0px;
}
.tablet-portrait .wrapper-box-fixed {
  max-width: 325px;
}
/* media wide mobile Class  */
.wide-mobile .grid-container > div {
  width: 25%;
}
.wide-mobile .grid-container > div:nth-child(3n) {
  width: 0px;
}
.wide-mobile .wrapper-box-fixed {
  max-width: 210px;
}
.wide-mobile .wrapper-box-mobilefluid {
  max-width: 100%;
}

/* media Mobile Class  */
.mobile .grid-container > div {
  width: 33.33333334%;
}
.mobile .grid-container > div:nth-child(1n+12) {
  width: 0px;
}
.mobile .wrapper-box-fixed {
  max-width: 200px;
}
.mobile .wrapper-box-mobilefluid {
  max-width: 100%;
}
              
            
!

JS

              
                $(document).ready(function() {

  // CHOISES
  $('#choose-liquid').bind('click', function() {
    $('.matrix .grafic-container-box .wrapper-box').addClass('wrapper-box-liquid').removeClass('wrapper-box-fixed ');
    $(this).addClass('active');
    $('#choose-limited').removeClass('active');
  });
  $('#choose-limited').bind('click', function() {
    $('.matrix .grafic-container-box .wrapper-box').removeClass('wrapper-box-liquid').addClass('wrapper-box-fixed ');
    $(this).addClass('active');
    $('#choose-liquid').removeClass('active');
  });

  // disable figure selection
  $('.matrix, .matrix *').on('selectstart', false);

  // figure handle
  $('.matrix .resizable-box .handle').bind('mousedown', function() {

    var obj = $(this).parent();
    var posContainer = $(obj).offset();
    var posContainerLeft = posContainer.left;

    $(window).bind('mouseup', function() {
      // undbind handlers
      $(window).unbind('mousemove');
      $(this).unbind('mouseup');
    });

    $(window).bind('mousemove', function(ev) {

      ev.preventDefault();

      var xValue = ev.pageX - posContainerLeft;

      if (xValue > parseInt($(obj).css('max-width'))) {
        xValue = parseInt($(obj).css('max-width'));
      }
      if (xValue < parseInt($(obj).css('min-width'))) {
        xValue = parseInt($(obj).css('min-width'));
      }

      $(obj).css('width', xValue + 'px');

      jsMediaQueries(obj);

    });
  });
});

// applying css classes like media queries
// requires an jquery-obj as the element to be added
function jsMediaQueries(obj) {
  var size = $(obj).children('.resizable-box-content').width(),
    className, activeViewportClass, amountGridColumns;
  $(obj).children('.resizable-box-content').removeClass('large-desktop desktop tablet-portrait wide-mobile mobile');
  $(obj).parent().children('.breakpoint-bar').children('div').removeClass('active');

  className = 'large-desktop';
  activeViewportClass = 'large-desktop-viewport-class';

  if (size < 560) {
    className = 'large-desktop desktop';
    activeViewportClass = 'desktop-viewport-class';
  }
  if (size < 440) {
    className = 'large-desktop desktop tablet-portrait';
    activeViewportClass = 'tablet-portrait-viewport-class';
  }
  if (size < 325) {
    className = 'large-desktop desktop tablet-portrait wide-mobile';
    activeViewportClass = 'wide-mobile-viewport-class';
  }
  if (size < 210) {
    className = 'large-desktop desktop tablet-portrait wide-mobile mobile';
    activeViewportClass = 'mobile-viewport-class';
  }

  $(obj).parent().children('.breakpoint-bar').find('.' + activeViewportClass).addClass('active');
  $(obj).children('.resizable-box-content').addClass(className);

}

// events for multiscreen strategy grafic
$('.matrix .viewport-support-range-box-handle-left, .matrix .viewport-support-range-box-handle-right').bind('mousedown', function(e) {

  e.preventDefault();

  var obj = $(this);
  var direction = $(this).attr("data-direction"),
    posContainer = $(this).parent().offset(),
    posParent = $(this).parent().parent().offset(),
    widthParent = $(this).parent().parent().width(),
    currentWidth = parseInt($(this).parent().width()),
    currentLeft = parseInt($(this).parent().css('left')),
    currentRight = parseInt($(this).parent().css('right'));

  $(window).bind('mouseup', function(ev) {

    // einrasten
    finalLeft = parseInt($(obj).parent().css('left')),
      finalRight = parseInt($(obj).parent().css('right'));
    $(obj).parent().animate({
      'left': (Math.floor(finalLeft / (widthParent / 5) + 0.5) * (widthParent / 5)) + 'px'
    }, 150);
    $(obj).parent().animate({
      'right': (Math.floor(finalRight / (widthParent / 5) + 0.5) * (widthParent / 5)) + 'px'
    }, 150);

    // adapt figures with flex blox
    var figureMaxWidth,
      figureMinWidth,
      disableViewportBarClasses = '';
    console.log(Math.floor(finalLeft * 5 / widthParent + 0.5))
    switch (Math.floor(finalLeft * 5 / widthParent + 0.5)) {
      case 0:
        figureMinWidth = 200;
        break;
      case 1:
        figureMinWidth = 211;
        disableViewportBarClasses = disableViewportBarClasses + '.mobile-viewport-class ';
        break;
      case 2:
        figureMinWidth = 326;
        disableViewportBarClasses = disableViewportBarClasses + '.mobile-viewport-class .wide-mobile-viewport-class ';
        break;
      case 3:
        figureMinWidth = 441;
        disableViewportBarClasses = disableViewportBarClasses + '.mobile-viewport-class .wide-mobile-viewport-class .tablet-portrait-viewport-class ';
        break;
      case 4:
        figureMinWidth = 561;
        disableViewportBarClasses = disableViewportBarClasses + '.mobile-viewport-class .wide-mobile-viewport-class .tablet-portrait-viewport-class .desktop-viewport-class ';
        break;
      default:
        figureMinWidth = 200;

    }
    switch (Math.floor(finalRight * 5 / widthParent + 0.5)) {
      case 4:
        figureMaxWidth = 210;
        break;
      case 3:
        figureMaxWidth = 325;
        break;
      case 2:
        figureMaxWidth = 440;
        break;
      case 1:
        figureMaxWidth = 560;
        break;
      case 0:
        figureMaxWidth = 700;
        break;
      default:
        figureMaxWidth = 700;
    }
    $('.matrix .resizable-box').delay(1000).css({
      'min-width': figureMinWidth + 'px',
      'max-width': figureMaxWidth + 'px'
    });

    // undbind handlers
    $(window).unbind('mousemove');
    $(obj).unbind('mouseup');

    // update flex figures
    var flexfigures = $('.figure .resizable-box');
    jsMediaQueries(flexfigures);

  });

  $(window).bind('mousemove', function(ev) {

    var leftValue, rightValue;
    ev.preventDefault();
    $(obj).parent().stop(true, true);

    // stop wenn to close to border
    if (ev.pageX < posParent.left) {
      ev.pageX = posParent.left;
    }
    if (ev.pageX > posParent.left + widthParent) {
      ev.pageX = posParent.left + widthParent;
    }
    if (direction == 'left' && ev.pageX >= (posParent.left + widthParent - (widthParent / 5))) {
      ev.pageX = posParent.left + widthParent - (widthParent / 5);
    }

    if (direction == 'left') {
      leftValue = ev.pageX - posContainer.left;
      $(obj).parent().css('left', currentLeft + leftValue + 'px');
    }
    if (direction == 'right') {
      rightValue = ev.pageX - posContainer.left - currentWidth;
      $(obj).parent().css('right', currentRight - rightValue + 'px');
    }

  });
});
              
            
!
999px

Console