Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <h1>
  Mask border for one side of an element
</h1>
<p>
  This demo uses the <strong>mask</strong> CSS property. You can use multiple values, so to get this effect we are chaining together our border (in this case, a caret icon) and a simple rectangle shape to take up the remainder of the element.
</p>
<div class="image-container">
  <!-- Image with a border on the left-hand side -->
  <div class="image border-left">
    <img src="https://images.unsplash.com/photo-1597163538726-ecc20df70005?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&izxid=eyJhcHBfaWQiOjE0NTg5fQ"/>
  </div>

  <!-- Image with a border on the right-hand side -->
  <div class="image border-right">
    <img src="https://images.unsplash.com/photo-1597163538726-ecc20df70005?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ"/>
  </div>

  <!-- Image with a top border -->
  <div class="image border-top">
    <img src="https://images.unsplash.com/photo-1597163538726-ecc20df70005?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ"/>
  </div>

  <!-- Image with a bottom border -->
  <div class="image border-bottom">
    <img src="https://images.unsplash.com/photo-1597163538726-ecc20df70005?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ"/>
  </div>
</div>
              
            
!

CSS

              
                /* Unrelated styles */
html {
  font-family: Inconsolata, sans-serif;
  text-align: center;
  background: #FFF8E1;
}

h1 {
  font-size: 21px;
}

p {
  font-size: 16px;
  line-height: 1.65;
  max-width: 550px;
  margin: 0 auto;
  margin-bottom: 10px
}

.image-container { 
  display: flex;
  max-width: 750px;
  margin: 0 auto;
}

.image {
  flex: 0 0 22%;
  margin-right: 3%;
}

.image img {
  width: 100%;
}

/* end unrelated styles */



/* 
The border: 
 - Using the mask CSS property, start the pattern on one side of the element. This can be top, right, bottom or left. 
 - Make the image a fixed width and height (these can be a percentage).
 - Repeat vertically or horizontally, depending on what side you want your border on. This can be `repeat-y` or `repeat-x`.

The remainder:
 - For our rectangle value, which will take up the remainder of the space, place this on the *opposite* side of whatever you chose for your border image.
 - If this is a top/bottom border, set the width/height to `calc(100% - [size-of-your-border]) auto`. 
 - If this is a left/right border, set the width/height to `auto calc(100% - [size-of-your-border])`. You may need to fiddle with the pixel value to make sure there's no gap on resize (in my example, you may note that I needed to set this to 10px rather than 16px)
 - This should repeat the same direction as your border, either `repeat-x` or `repeat-y`.


That's it!

*/

.border-left {
  -webkit-mask: url(https://assets.codepen.io/339955/caret-left.svg) left / 16px 16px repeat-y, 
                url(https://assets.codepen.io/339955/rect.svg) right / calc(100% - 10px) auto repeat-y;
  mask: url(https://assets.codepen.io/339955/caret-left.svg) left / 16px 16px repeat-y,
        url(https://assets.codepen.io/339955/rect.svg) right / calc(100% - 10px) auto repeat-y;
}

.border-right {
  -webkit-mask: url(https://assets.codepen.io/339955/caret-right.svg) right / 16px 16px repeat-y, 
                url(https://assets.codepen.io/339955/rect.svg) left / calc(100% - 10px) repeat-y;
  mask: url(https://assets.codepen.io/339955/caret-right.svg) right / 16px 16px repeat-y,
        url(https://assets.codepen.io/339955/rect.svg) left / calc(100% - 10px) repeat-y;
}


.border-top {
  -webkit-mask: url(https://assets.codepen.io/339955/caret-up.svg) top / 16px 16px repeat-x, 
                url(https://assets.codepen.io/339955/rect.svg) bottom / auto calc(100% - 10px) repeat-x;
  mask: url(https://assets.codepen.io/339955/caret-up.svg) top / 16px 16px repeat-x, 
        url(https://assets.codepen.io/339955/rect.svg) bottom / auto calc(100% - 10px) repeat-x;
}


.border-bottom {
  -webkit-mask: url(https://assets.codepen.io/339955/caret-down.svg) bottom / 16px 16px repeat-x, 
                url(https://assets.codepen.io/339955/rect.svg) top / auto calc(100% - 10px) repeat-x;
  mask: url(https://assets.codepen.io/339955/caret-down.svg) bottom / 16px 16px repeat-x, 
        url(https://assets.codepen.io/339955/rect.svg) top / auto calc(100% - 10px) repeat-x;
}
              
            
!

JS

              
                
              
            
!
999px

Console