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.

            
               <div class="container-center-all">
        <span class="title">
          <a href ="https://medium.com/free-code-camp/flexboxs-flex-basis-explained-83d1a01413b7" target="_blank">Read the medium article here</a>
        </span>
        <div class="content-section-block">
            <span class="title--secondary">
                flex-direction: <i>row;</i>
            </span>
            <span class="details">
                <b>height: 250px;</b> - <i>flex-basis: 250px;</i>
                <p>The true nature of flex-basis is best seen when using flex-wrap -
                    In this example, we are getting a block of 4 x 4 because the flex basis
                    is set at 250px in a box that is 500px <b>wide</b>, so there is only enough
                    room for 2 blocks on the <i>main axis, in this case, "Row" so horizontally</i>,
                    and the other two blocks drop below.
                    </br></br>
                    So what we see here is the flex-basis controlling the width!
                </p>
            </span>
            <span class="details"><b>Flex-basis direction &hArr; <i>horizontally</i></b></span>

            <input type="checkbox" class="btn--1-checkbox" id="btn1checkbox">
            <label for="btn1checkbox" class="btn btn--1">
                Turn <span class="btn--on-off"></span> flex-wrap
            </label>
            <div class="container-1">
                <div class="container-1__item">
                    <div class="container-1__item--inner">
                        <div class="center-numbers">1</div>
                    </div>
                </div>
                <div class="container-1__item">
                    <div class="container-1__item--inner">
                        <div class="center-numbers">2</div>
                    </div>
                </div>
                <div class="container-1__item">
                    <div class="container-1__item--inner">
                        <div class="center-numbers">3</div>
                    </div>
                </div>
                <div class="container-1__item">
                    <div class="container-1__item--inner">
                        <div class="center-numbers">4</div>
                    </div>
                </div>

                <span class="container-1__hover-direction-marker">
                    &hArr;
                </span>
                <span class="container-1__hover-details">
                    These boxes are taking on the default nature of a flex item by
                    shrinking to fit evenly due to <i>flex-shrink:</i> which is true by default.
                    The same thing would happen here if we had
                    set the width: 250px; but instead we can use flex basis when the
                    flex direction is set to row.
                </span>

                <span class="container-1__hover-details--2">
                    <i>height: 250px;</i></br>
                    <i>flex-basis: 250px;</i></br>
                    <i>flex-wrap: nowrap;</i></br>
                </span>
            </div>
        </div>

        <div class="content-section-block">
            <span class="title--secondary">
                flex-direction: <i>column;</i>
            </span>
            <span class="details">
                <b>width: 250px;</b> - <i>flex-basis: 250px;</i>
                <p>The true nature of flex-basis is best seen when using flex-wrap -
                    In this example, we are getting a block of 4 x 4 because the flex basis
                    is set at 250px in a box that is 500px <b>tall</b>, so there is only enough
                    room for 2 blocks on the <i>main axis, in this case, "Column" so vertically</i>,
                    and the other two blocks shift right.
                    </br></br>
                    So what we see here is the flex-basis controlling the height!
                </p>
            </span>
            <span class="details"><b>
                    Flex-basis direction
                    <div class="rotate-arrow">&hArr;</div>
                    <i>vertically</i></b>
            </span>
            <input type="checkbox" class="btn--2-checkbox" id="btn2checkbox">
            <label for="btn2checkbox" class="btn btn--2">
                Turn <span class="btn--on-off"></span> flex-wrap
            </label>
            <div class="container-2">
                <div class="container-2__item">
                    <div class="container-2__item--inner">
                        <div class="center-numbers">1</div>
                    </div>
                </div>
                <div class="container-2__item">
                    <div class="container-2__item--inner">
                        <div class="center-numbers">2</div>
                    </div>
                </div>
                <div class="container-2__item">
                    <div class="container-2__item--inner">
                        <div class="center-numbers">3</div>
                    </div>
                </div>
                <div class="container-2__item">
                    <div class="container-2__item--inner">
                        <div class="center-numbers">4</div>
                    </div>
                </div>

                <span class="container-2__hover-direction-marker rotate-arrow">
                    &hArr;
                </span>
                <span class="container-2__hover-details">
                    These boxes are taking on the default nature of a flex item by
                    shrinking to fit evenly due to <i>flex-shrink:</i> which is true by default.
                    The same thing would not happen here if we had
                    set the height: 250px; so as a best practice we should always use flex basis when the
                    flex direction is set to column to avoid unexpected results.
                </span>
                <span class="container-2__hover-details--2">
                    <i>width: 250px;</i></br>
                    <i>flex-basis: 250px;</i></br>
                    <i>flex-wrap: nowrap;</i></br>
                </span>
            </div>
        </div>
    </div>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Lato|Open+Sans');

$font-primary: 'Lato', sans-serif;
$font-copy-content: 'Open Sans', sans-serif;

$color-primary: #f1425d;
$color-secondary: #f17442;

$color-lightest-grey: #eee;
$color-midrange-grey: #a8a8a8;
$color-darkest-grey: #333;

$color-white: #fff;

* {
    margin: 0;
    padding: 0;
    box-sizing: inherit;
}

html {
  box-sizing: border-box;
}

body {
    background-color: $color-lightest-grey;
    font-family: $font-copy-content;

    i {
        color: $color-darkest-grey;
    }
}

::selection {
    background-color: $color-darkest-grey;
    color: $color-lightest-grey;
  }

.container-center-all {
    text-align: center;
}

.content-section-block {
    display: inline-block;
    width: 500px;

    &:not(:last-child) {
        margin-right: -5px;
    }
}

.title {
    margin-top: 20px;

    &,
    a,
    &--secondary {
        display: block;

        font-weight: 700;
        margin-bottom: 10px;
        font-size: 25px;
        font-variant: small-caps;
        letter-spacing: 1px;
        color: #000;
        font-family: $font-primary;
    }

}

.details {
    display: block;

    margin-bottom: 10px;
    font-size: 20px;
    font-variant: small-caps;
    letter-spacing: 1px;

    p {
        font-variant: normal;
        margin-top: 7px;
        padding: 0 5px 0 5px;
        font-size: 14px;
    }

}

.container-1,
.container-2 {
    position: relative;

    background-color: $color-midrange-grey;
    text-align: center;
    width: 500px;
    height: 500px;

    display: flex;
    flex-wrap: wrap;

    overflow: hidden;

    &__item {
        color: $color-white;
        font-size: 40px;
        
        // Notice that flex-basis is applied to both
        flex-basis: 250px; // Where the magic happens

        &--inner {
            position: relative;

            border: 2px solid $color-midrange-grey;

            width: 100%;
            height: 100%;
        }

    }

    &__hover-direction-marker {
        display: inline-block;

        position: absolute;

        color: $color-white;
        font-size: 80px;

        opacity: 0;
        backface-visibility: hidden;

        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);

    }

    &__hover-details {
        display: inline-block;

        position: absolute;

        color: $color-white;
        opacity: 0;

        &--2 {
            opacity: 0;
            transform: translateX(400px);
        }

    }

}

.container-1 {
    flex-direction: row;

    &__item {
        // flex-direction: row;
        height: 250px;

        &--inner {
            background-color: $color-primary;
        }
    }

    &__hover-direction-marker {
        top: 140px;
        left: 23px;
    }

    &__hover-details {
        bottom: 35px;
        left: 25px;
        width: 245px;
        text-align: left;

        transform: translateX(-400px);

        &--2 {
            position: absolute;

            bottom: 35px;
            right: 25px;
            text-align: right;
        }
    }
}

.container-2 {
    flex-direction: column;

    &__item {
        // flex-direction: column;
        width: 250px;

        &--inner {
            background-color: $color-secondary;
        }
    }

    &__hover-direction-marker {
        top: 3px;
        left: 160px;
    }

    &__hover-details {
        top: 20px;
        right: 25px;
        width: 200px;

        text-align: right;

        transform: translateX(400px);

        &--2 {
            position: absolute;

            bottom: 35px;
            right: 25px;
            text-align: right;
        }

    }
}

.center-numbers {
    position: relative;

    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}


.btn {
    display: inline-block;
    position: relative;

    margin-bottom: 10px;
    width: 50%;
    padding: 5px 10px;
    text-transform: uppercase;
    text-decoration: none;
    color: $color-white;
    cursor: pointer;

    box-shadow: inset -1px -1px 1px rgba(0, 0, 0, 0.4);

    &--1,
    &--2 {
        &:hover {
            opacity: .8;
        }
    }

    &--1 {
        background-color: $color-primary;
    }

    &--2 {
        background-color: $color-secondary;
    }

}

// Functionality

.btn--1-checkbox:checked~.container-1 {
    flex-wrap: nowrap;
}

.btn--2-checkbox:checked~.container-2 {
    flex-wrap: nowrap;
}

.btn--1-checkbox:checked~.container-1>.container-1__hover-direction-marker,
.btn--2-checkbox:checked~.container-2>.container-2__hover-direction-marker {
    opacity: 1;
    transition: opacity .7s .5s ease-in;
}

.btn--1-checkbox:checked~.container-1>.container-1__hover-details,
.btn--1-checkbox:checked~.container-1>.container-1__hover-details--2,
.btn--2-checkbox:checked~.container-2>.container-2__hover-details,
.btn--2-checkbox:checked~.container-2>.container-2__hover-details--2 {
    opacity: 1;
    transform: translateX(0);
    transition: all .4s;
}

.btn--1-checkbox:checked ~ .btn--1,
.btn--2-checkbox:checked ~ .btn--2  {
    opacity: .8;
    box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.4);
    transform: translate(1px, 1px);
}

.btn--1-checkbox:checked ~ .btn--1 > .btn--on-off,
.btn--2-checkbox:checked ~ .btn--2 > .btn--on-off {
    &::before {
        display: inline-block;
    }
    &::after {
        content: "off";
        display: none;
    }
}

.btn--on-off {
    &::before {
        color: black;
        font-weight: 700;
        content: "on";
        display: none;
    }
    &::after {
        content: "off";
        display: inline-block;
    }
}

.btn--1-checkbox, .btn--2-checkbox { display: none; }
.rotate-arrow { display: inline-block; transform: rotate(90deg); }
            
          
!
            
              // please feel free to leave comments if you have any advice for changes / additions to this ;-) 

            
          
!
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