<div class='slanted'>
    <p>I was updating my portfolio and wanted to use the forward <span class='no-break'>slash ( / )</span> as a graphic element in the site's main layout. It seemed like it would be easy at first glance, but as I began digging into it actually presented a few very interesting challenges.</p>
    <p>I started by looking around for examples of non-rectangular containers that allowed text to flow naturally inside of them. I assumed it'd be possible with CSS since programs like Adobe Illustrator and Microsoft Word have been doing it for years. I found the CSS Shapes Module and that works very well for simple text content. It can even full justify the text. However it doesn’t allow content to scroll within the container so as the user scrolls down, the entire slanted container appears to move left, which wasn’t the effect I wanted. Instead I took a simpler approach and simply added a transform: skew to the container:</p>
    <img class="normal" src="https://i.imgur.com/HLw6SuM.png" />
    <p class="normal">That was a good start, scrolling worked as expected and resizing was handled with only CSS, but the obvious problem is that now the text and images are slanted as well. I made a few attempts to solve this with CSS but eventually came up with an even simpler solution: create a new font with the reverse slant using FontForge, an open-source font editor.</p>
    <p>I'd chosen Roboto Condensed Light for the site's main content so I opened the .ttf file in FontForge, selected all the glyphs, and applied a skew of 14 degrees to compensate for the container’s slant, and saved it out as Roboto-Rev-Italic.ttf.
    <p>That worked great for text, even selecting functioned normally. For images and video, which are display:block elements I was able to simply apply the reverse slant to their transform property. Pseudoelements background give them to span the entire width of the container as well.
    <img src="https://i.imgur.com/HLw6SuM.png" />
    <p>See it in action at <a href="https://daveseidman.com" target="_blank">daveseidman.com</a> and use the comments section to suggest other methods, I’m curious to see other way of achieving the same effect. </p>
@import url('https://assets.codepen.io/9632/roboto-rev-italic.ttf');

@import url('https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@300&display=swap');

@font-face {
  font-family: 'Roboto Condensed Light';
  src: url('https://assets.codepen.io/9632/roboto-rev-italic.ttf') format('truetype');

$skew-amount: -14deg;

body, html {
  font-size: 14px;
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Roboto Condensed Light';
  font-variant-ligatures: none;
  background: gray;
  line-height: 1.5rem;

.no-break {
  white-space: nowrap;

.slanted {
  background: white;
  width: 50%;
  position: absolute;
  left: 50%;
  transform: translateX(-50%) skew($skew-amount);
  text-align: justify;
  overflow-x: hidden;
  overflow-y: auto;
  height: calc(100% - 2rem);
  padding: 1rem;
  font-family: 'Roboto Condensed Light';
  .normal {
    transform: none;
    font-family: 'Roboto Condensed', sans-serif;
  img {
    width: 100%;
    transform: skew(-$skew-amount);
    position: relative;
    &:after {
      display: block;
      content: '1';
      background: red;
      position: absolute;
      top: 0;
      left: 0;
      width: 200%;
      height: 100%;
View Compiled

External CSS

  1. https://daveseidman.com/assets/fonts/roboto-rev-italic.ttf

External JavaScript

This Pen doesn't use any external JavaScript resources.