cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <h1>Wrap-around ribbons with Sass</h1>
<hr />
<div class="wrapper">
    <div class="basic">
        <div class="container b1">Left ribbon</div>
        <div class="container b2">Right ribbon</div>
        <div class="container b3">Both ribbons</div>
    </div>
    <div class="implemented ">
        <div class="demo simple">
            <h2>Wrap-Around Ribbons</h2>
            <div class="box">
                <p>Basic Example</p>
            </div>
        </div>
        <div class="demo fancy">
            <h2>Wrap-around Ribbons</h2>
            <div class="box">
                <p>Fancy Example</p>
            </div>
        </div>
    </div>
</div>
<hr />
<p>Created by <a href="http://ricardozea.design/?=codepen" target="_blank" title="Link opens in a new tab">Ricardo Zea</a></p>
            
          
!
            
              //Put this whole mixin in your .scss file:
@mixin ribbon( $ribbon-color:black, $size-left:1em, $size-right:1em) {
    position: relative;
    &:before,
    &:after {
        content: "";
        position: absolute;
    }
    &:before {
        border-top: $size-left solid $ribbon-color;
        bottom: -$size-left;
        border-left: $size-left solid transparent;
        left: 0;
    }
    &:after {
        border-top: $size-right solid $ribbon-color;
        bottom: -$size-right;
        border-right: $size-right solid transparent;
        right: 0;
    }
}


/*Usage:
.selector { @include ribbon($y, 1em, 0); }

Explanation of mixin values:
A. $y: Is the color, I used a Sass variable but you can use whatever you want: #f00 - red - #ff0000
B. 1em: Is the dimensions of the ribbon(s)
C. "1em, 0": Means you're only doing the ribbon on the left
D. "0, 1em": Means you're only doing the ribbon on the right
E. "1em, 1em": Means you're  doing both ribbons  on left and right
*/

//This is the container to which you're going to apply the ribbon to
.container {
    display: inline;
    margin: 0 2%;
    padding: 40px 20px;
    background: $b;
}

//These are the ribbons themselves:

//Left ribbon
.b1 { @include ribbon($y, 1em, 0); }

//Right ribbon
.b2 { @include ribbon($y, 0, 1em); }

//Both ribbons
.b3 { @include ribbon($y, 1em, 1em); }


/*=========*/

//Demos on the right side with red headers
.demo {
    margin-bottom: 20px;
    &:last-of-type {
        margin: 0;
    }
}

//The red headings use the ribbons, see @include property below
h2 {
    @include ribbon(darken($r, 30%), 15px, 15px);
    width: 300px;
    margin: auto;
    padding: 2%;
    background: $r;
}

//Blue boxes under the header
.box {
    width: 270px;
    margin: auto;
    padding: 4%;
    clear: both;
    background: $g;
    box-shadow: inset 0 3px 0 rgba(black, .2);
    font-weight: bold;
}

//Gradient box, fancier-looking demo
.fancy {
    text-shadow: 0 -1px 0 rgba(black, 1);
    h2 {
        background-image: linear-gradient($r, darken($r, 20%));
        box-shadow: 0 2px 2px 1px rgba(black, .2);
    }
    .box {
        border-radius: 0 0 5px 5px;
        background-image: linear-gradient(darken($b, 25%), darken($b, 30%));
        box-shadow: 0 2px 4px 1px rgba(black, .2);
    }
}

//***********NOT NEEDED FOR DEMO***********
.wrapper {
    display: flex;
    & > div {
        padding: 20px 20px 30px;
        margin: 10px;
        background: rgba(white, .05);
        display: inline-block;
        width: 100%;
        border: rgba(white, .06) 1px solid;
        border-radius: 2px;
        box-shadow: 0 2px 2px rgba(black, .1);
    }
}

.basic {
    display: flex !important;
    align-items: center;
    justify-content: space-around;
    width: auto;
}

.new-window {
    position: relative;
    padding-right: 16px;
    &:after {
        content: '';
        display: block;
        width: 14px;
        height: 12px;
        position: absolute;
        top: 10%;
        right: 0;
        background: url(http://i.stack.imgur.com/3H2PQ.png) no-repeat;
    }
}
            
          
!
            
              /*
Original Article:
http://asgeirhoem.no/ex/css-wraparound-ribbon/

Inspired by this article:
http://www.kendallsdesign.com/blog/sass-mixin-wrap-around-ribbons

*/

//Add a title to the links that open in a new tab/window
$("a[target='_blank']").attr({title:'Opens in a new tab/window'}).addClass('new-window');

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console