<main class="main container">
  <section class="section position-fixed">
    <h2><code>position: fixed;</code></h2>
    <div class="fixed">Check out this text. It has <code>position: fixed;</code></div>
  </section>
  <p>Scroll and notice how the text with blue background remains <strong>fixed</strong> in the specified position</p>
  <p>In the example, the fixed text has following styles: <br />
    <strong style="display: inline-block; margin-top: 0.1rem; padding: 0.5rem 1rem; background-color:yellowgreen;">
      <code>
        div.fixed {
        position: fixed;
        top: 40vh;
        right: 25vw;
        left: 25vw;
        }
      </code>
    </strong>
  </p>
</main>
body{
  hright: 100vw;
}

.main > p {
  text-align: center;
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

.section {
  padding: 1rem;
  margin: 2rem auto;
  max-width: 400px;
  background-color: lightskyblue;
  /* text-align: center; */
  color: white;
  max-width: 100%;
}

.section h2 {
  font-size: 1.3rem;
  background-color: darkgreen;
  padding: 1rem;
}

.section p {
  font-size: 1.1rem;
  background-color: darkgreen;
  padding: 1rem;
}

.section .box {
  background-color: navy;
  width: 200px;
  height: 200px;
  margin: 2rem 0;
}

.section div.fixed {
  position: fixed;
  background-color: navy;
  top: 40vh;
  left: 25vw;
  right: 25vw;
  padding: 1rem;
  font-size: 1.2rem;
  text-align: center;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.