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>CSS Stairway Nav with :has()</h1>

<p>Fork from <a href="https://codepen.io/chriscoyier/pen/AZYeer">Chris Coyier's "Stairway Hover Nav" Pen</a></p>

<p>This Pen is quoted in <a href="https://dskd.jp/archives/117.html">my blog.</a> I also explain a little about: has (), so please take a look.</p>

<div>
  <h2>One Step</h2> 
  <nav class="-step1">
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
  </nav>  
</div>

<div>
   <h2>Two Step</h2>
   <nav class="-step2">
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
  </nav>
</div>

<div>
   <h2>Three Steps</h2>
   <nav class="-step3">
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
  </nav>
</div>

<div>
  <h2>Four Steps</h2>
  <nav class="-step4">
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
    <a href="#">Navigation</a>
  </nav>
</div>
              
            
!

CSS

              
                :root {
  --step1-hs: 26, 95.1%;
  --step1-l: 48.2%;
  --step2-hs: 188, 87.6%;
  --step2-l: 41%;
  --step3-hs: 116, 88.1%;
  --step3-l: 42.7%;
  --step4-hs: 0, 0%;
  --step4-l: 40%;
  --z-index-1st: 3;
  --z-index-2nd: 2;
  --z-index-3rd: 1;
  --z-index-4th: 0;
  --transform-1st: scale(1.1) translateX(24px);
  --transform-2nd: scale(1.07) translateX(12px);
  --transform-3rd: scale(1.04) translateX(4px);
  --transform-4rd: scale(1.01) translateX(2px);
  --box-shadow-1st: 0 0 10px rgba(0, 0, 0, 0.75);
  --box-shadow-2nd: 0 0 10px rgba(0, 0, 0, 0.5);
}

/* color settings */
.-step1, .-step1 a { background-color: hsl(var(--step1-hs), var(--step1-l)) }
.-step2, .-step2 a { background-color: hsl(var(--step2-hs), var(--step2-l)) }
.-step3, .-step3 a { background-color: hsl(var(--step3-hs), var(--step3-l)) }
.-step4, .-step4 a { background-color: hsl(var(--step4-hs), var(--step4-l)) }

/* common a style */
nav a {
  display: block;
  padding: 10px;
  color: white;
  text-decoration: none;
  position: relative;
  transition: all 0.2s ease;
}

.-step1 a:hover {
  --step1-l: 63.2%;
  transform: var(--transform-1st);
  box-shadow: var(--box-shadow-1st);
  z-index: var(--z-index-1st);
}

.-step2 a:hover {
  --step2-l: 60%;
  transform: var(--transform-1st);
  box-shadow: var(--box-shadow-1st);
  z-index: var(--z-index-1st);
}

/* prev & next hover element */
.-step2 a:has(+ a:hover),
.-step2 a:hover + a {
  --step2-l: 49%;
  transform: var(--transform-2nd);
  box-shadow: var(--box-shadow-2nd);
  z-index: var(--z-index-2nd);
}


.-step3 a:hover {
  --step3-l: 57.7%;
  transform: var(--transform-1st);
  box-shadow: var(--box-shadow-1st);
  z-index: var(--z-index-1st);
}

/* prev & next hover element */
.-step3 a:has(+ a:hover),
.-step3 a:hover + a {
  --step3-l: 52.7%;
  transform: var(--transform-2nd);
  box-shadow: var(--box-shadow-2nd);
  z-index: var(--z-index-2nd);
}

/* 2prev & 2next hover element */
.-step3 a:has(+ a + a:hover),
.-step3 a:hover + a + a {
  --step3-l: 47.7%;
  transform: var(--transform-3rd);
  z-index: var(--z-index-3rd);
}


.-step4 a:hover {
  --step4-l: 60%;
  transform: var(--transform-1st);
  box-shadow: var(--box-shadow-1st);
  z-index: var(--z-index-1st);
}

/* prev & next hover element */
.-step4 a:has(+ a:hover),
.-step4 a:hover + a {
  --step4-l: 55%;
  transform: var(--transform-2nd);
  box-shadow: var(--box-shadow-2nd);
  z-index: var(--z-index-2nd);
}

/* 2prev & 2next hover element */
.-step4 a:has(+ a + a:hover),
.-step4 a:hover + a + a {
  --step4-l: 50%;
  transform: var(--transform-3rd);
  z-index: var(--z-index-3rd);
}

/* 3prev & 3next hover element */
.-step4 a:has(+ a + a + a:hover),
.-step4 a:hover + a + a + a {
  --step4-l: 45%;
  transform: var(--transform-4th);
  z-index: var(--z-index-4th);
}


body { 
  background: #222;
  color: white;
  padding: 20px;
}
body > div {
  width: 20%;
  float: left;
  margin-right: 5%;
}
h1 {
  font-size: 36px;
  margin: 0 0 10px 0;
}
h2 {
  margin: 0 0 10px 0; 
}
p a {
  color: hsl(var(--step2-hs), var(--step2-l))
}
              
            
!

JS

              
                // no js
              
            
!
999px

Console