<div class="resize">
  <div class="not-container">
    <div class="centering">
      <p><b>[div.not-container &gt; div.centering &gt; p]</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
      <p class="fixed"><b>[div.not-container &gt; div.centering &gt; p.fixed]</b></p>
    </div>
  </div>
  <div class="container">
    <div class="centering">
      <p><b>[div.container &gt; div.centering &gt; p]</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      <p class="alignfull"><b>[div.container &gt; div.centering &gt; p.alignfull]</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      <p class="alignwide"><b>[div.container &gt; div.centering &gt; p.alignwide]</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
      <p class="fixed"><b>[div.container &gt; div.centering &gt; p.fixed]</b></p>
    </div>
  </div>
</div>
body {
  margin: 0;
  padding-block: 50vb;
}
body * {
  background: rgb(128, 128, 128, 0.5);
  margin: 0;
}
body * + * {
  margin-block-start: 2rem;
}
b {
  color: red;
}
.resize {
  margin: auto;
  overflow: hidden;
  resize: both;
}
.container {
  container: container / inline-size;
}
.centering {
  margin-inline: max(0px, 50% - 240px);
}
.alignfull {
  margin-inline: calc(50% - 50cqi);
}
.alignwide {
  margin-inline: max(50% - 320px, 50% - 50cqi);
}
.fixed {
  margin: 0;
  position: fixed;
  inset-block-start: 0;
  inset-inline-start: 0;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.