CSS Text Rotation | Rotated Header Text

12/17/2020

Contents

Demo

Full Screen

Code

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>CSS Text Rotation</title>
    <link rel="stylesheet" type="text/css" href="https://demo.plantpot.works/assets/css/normalize.css">
    <link rel="stylesheet" href="https://use.typekit.net/opg3wle.css">
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="container">
      <div class="box">
        <div class="box-header">
          <div class="box-header-title">
            <h1>Vertical Text</h1>
          </div>
        </div>
        <div class="box-body">
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,
            sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
            Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
            Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
            Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
          </p>
        </div>
      </div>
    </div>
  </body>
</html>

CSS

@charset "utf-8";
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 16px;
}
body {
  background-color: #929eb3;
  color: #3d3935;
  font-family: futura-pt, sans-serif;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}
#container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  padding: 15px;
}
.box {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 420px;
  height: 200px;
  border: 2px solid #ffa931;
}
.box-header {
  position: relative;
  width: 50px;
  height: 100%;
  background: #ffa931;
}
.box-header .box-header-title {
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  bottom: -2px;
  left: 50px;
  transform-origin: bottom left 50px;
  transform: rotate(-90deg);
  width: 200px;
  height: 50px;
}
.box-header .box-header-title h1 {
  margin: 0;
  font-size: 1.5rem;
  text-align: center;
}
.box-body {
  width: 370px;
  height: 100%;
  background-color: #fff;
}
.box-body p {
  padding: 15px;
  font-size: 1rem;
}
@media screen and (max-width: 480px) {
  .box {
    width: 100%;
  }
  .box-header {
    width: 40px;
  }
  .box-header .box-header-title {
    left: 40px;
    transform-origin: bottom left 40px;
    height: 40px;
  }
  .box-header .box-header-title h1 {
    font-size: 1.25rem;
  }
  .box-body {
    width: calc(100% - 40px);
    overflow-x: hidden;
    overflow-y: scroll;
  }
  .box-body p {
    padding: 10px;
  }
}