Utilizing CSS with the given HTML structure (simplified for clarity):
<nav id="colorNav">
<ul>
<li class="green">
<a href="#" class="icon-home"></a>
<ul>
<li><a href="#">Back to the tutorial</a></li>
<li><a href="#">Get help</a></li>
</ul>
</li>
<li class="red">
<a href="#" class="icon-cogs"></a>
<ul>
<li><a href="#">Payment</a></li>
<li><a href="#">Notifications</a></li>
</ul>
</li>
</ul>
</nav>
The CSS selector targets the :before
pseudo-element on the inner-most li
elements that are also the first elements within their parent:
#colorNav li ul li:first-child:before
An omitted comment in your provided code, present in the original tutorial, reads:
/* the pointer tip */
These rules pertain to creating a small triangle at the top of dropdown menus, pointing upwards towards their corresponding block (illustrated below, highlighted by a red circle):
Subsequent styles outline the creation of this triangular shape:
content: none; /* Pseudo-element devoid of content */
position: absolute; /* Positioned absolutely */
width: 1px; /* 1-pixel width */
height: 1px; /* 1-pixel height */
border: 5px solid transparent; /* Initial border style applied */
border-bottom-color: #313131; /* Custom bottom border color */
left: 50%; /* Centered horizontally */
top: -10px; /* 10px above the element */
margin-left: -5px; /* Centered horizontally */
The end result is a CSS-created triangle using only borders.