Cutting corners

Snipping the corner off of an element.

by ritcheyer

HTML

<div class="cut">

    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.</p>

    <p>Cut-corner effect by <a href="https://twitter.com/csswizardry">Harry Roberts</a>. <small>(<a href="http://instagram.com/p/jICriQojM1/">Photo</a>)</small></p>

    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.</p>

    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean...

SCSS

/**
 * Create a cut-/folded-corner effect using CSS.
 *
 * This technique is deceptively simple. All we’re doing is: laying a pseudo
 * element over the top-right of our content; giving this element the same
 * background image as the page; masking off the bottom-left of this element’s
 * background-image by using the familiar CSS Triangles technique; creating a
 * placeholder element to occupy enough space to stop any content from running
 * underneath our clipped corner.
 */

// Define how large you would the cut-off corner to be, and how large you would
// like the padding of the content box to be. We use these numbers to work out
// the size of the palceholder element.
$content-cut-size:          50px;
$content-padding-size:      10px;

// Define some cosmetics. Set `$content-cut-color` to inherit
// `$content-background-color` in order to make the corner look cut; set it to
// something else (e.g. `#e4e4e4`) to make the corner look folded.
$content-background-color:  #fff;
$content-cut-color:         $content-background-color;

// Round corners?
$content-radius-size:       100px;

html {
    padding: 5%;
}

/**
 * Apply the same background image to the page and the pseudo-element that
 * will create the faux clipping effect.
 *
 * 1. Vital to make sure the two elements’ backgrounds always line up.
 */
html,
.cut:after {
    background-image: url(http://distilleryimage7.ak.instagram.com/479493067ca111e3a4d512349e812b63_8.jpg);
    background-attachment: fixed; /* [1] */
}

.cut {
    position: relative;
    padding: $content-padding-size;
    background-color: $content-background-color;
    border-radius: $content-radius-size
}

    /**
     * Create a couple of pseudo-elements to produce the effect.
     */
    .cut:before,
    .cut:after {
        content: "";
    }

    /**
     * A placeholder-style element to prevent content from continuing underneath the
     * clipped-corner element. Uncomment the lines below to see where it lies.
     */
   ...