Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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

              
                <link href="https://fonts.googleapis.com/css?family=Nunito&display=swap" rel="stylesheet">


<h1>A Pen of Pseudo Elements</h1>
<h2>This is a webpage full of useful ways to use pseudo elemts</h2>
<p>There are a bunch of useful ways to use pseudo elements that are easy to forget about, this pen shows a few ways I commonly use them myself.</p>

<p>The first way pseudo elements are used on this pen is for the background itself. Their are two colours here, the darkcyan uses the ::after pseudo element to stay 50% of the body's width. That means if the body changes height, the pseudo element will automatically match the new height. This is pretty useful! Rather than using two divs to create this background, the code is kept cleaner and concise using the ::after pseudo element.</p>

<p class="first-letter-p">Another way that pseudo elements can be used is for the first letter of a given element, in this case for the p tag. To do this, the ::first-letter pseudo element is used, and then common styling such as font-size, colour, text-decoration and other properties can be used. This is a great pseudo element for blogs and artcles, as it's a common styling practise to emphasise the first letter. I am using em to style the first letter because it stays relative to the paragraph, this means if the size of the paragraph text changes to 2rem from 1.1rem, the first-letter will also get bigger</p>

<p class="first-line-p">A similar pseudo element is ::first line. it works in the same way as first-letter, but it applies to all the text on the first line of a paragraph. The same sort of properties can be applied, as is shown on this paragraph.</p>

<p>My favourite way to use pseudo elements is for styling lists. The following list is styled using a ::before pseudo element to change the bullets to look consistent with the pen's theme.</p>

<ul>
  <li class="li-circle">Practise CSS stlying</li>
  <li class="li-circle">Use more pseudo elements</li>
  <li class="li-circle">Style this list</li>
  <li class="li-circle">Create beautiful websites!</li>
</ul>

<p>The below list uses triangle shaped bullet points. This is defined by the hex reference that can be found on the w3 schools list titled "UTF-8 Geometric Shapes"</p>

<ul>
  <li class="li-triangle">Practise CSS stlying</li>
  <li class="li-triangle">Use more pseudo elements</li>
  <li class="li-triangle">Style this list</li>
  <li class="li-triangle">Create beautiful websites!</li>
</ul>

<p>I've saved the best for last! using a ::before or ::after pseudo element to style links can add a nice flare to the hover or focus state. By scaling the X axis from 0 to 1 over a transition, a smooth underline is created.</p>

<div>
  <a href="#">Home</a>
  <a href="#">About</a>
  <a href="#">Contact</a>
</div>



<div class="links last-element">
  <a target="_blank" href="https://codepen.io/amykble">codepen</a>
  <a target="_blank" href="https://github.com/amykble">github</a>
  <a target="_blank" href="https://www.linkedin.com/in/amy-keable-a8a576187/">linkedin</a>
</div>
              
            
!

CSS

              
                body {
  font-family: 'Nunito', sans-serif;
  background-color: #2ecc71;
  color: #fafafa;
  position: relative;
}

body::after {
  content: '';
  position: absolute;
  display: block;
  width: 100%;
  height: 50%;
  background-color: #16a085;
  bottom: 25%;
  left: 0;
  transform: skewY(10deg);
  z-index: -1;
}

h1 {
  display: flex;
  justify-content: center;
  margin: 1rem;
}

h2 {
  display: flex;
  justify-content: center;
  font-weight: 300;
  margin: 1rem 5rem;
}

p {
  font-size: 1.1rem;
  line-height: 1.5rem;
  margin: 3rem 5rem 0 5rem;
}

.first-letter-p::first-letter {
  font-weight: 900;
  font-size: 1.3em;
}

.first-line-p::first-line {
  background-color: #1abc9c;
  font-weight: 800;
}

ul {
  font-size: 1.1rem;
  line-height: 1.5rem;
  margin: 3rem 5rem 0 5rem;
  padding-left: 0;
  list-style: none;
}

.li-circle::before {
  display: inline-block;
  content: '';
  border-radius: 50%;
  height: 0.5em;
  width: 0.5em;
  margin-bottom: 0.1em;
  margin-right: 1em;
  background-color: #ffeb3b;
}

.li-triangle::before {
  display: inline-block;
  content: '\25B8';
  margin-bottom: 0.1em;
  margin-right: 1em;
  color: #ffeb3b;
}

div {
  font-size: 1.1rem;
  line-height: 1.5rem;
  margin: 3rem 5rem 0 5rem;
}

a {
  text-decoration: none;
  margin-right: 3rem;
  color: #ffeb3b;
  transition-delay: 0.4s;
  position: relative;
}

a:hover, a:focus {
  color: #fafafa;
}

a::after {
  position: absolute;
  content: '';
  height: 2px;
  width: 120%;
  bottom: -2px;
  left: -10%;
  background-color: #fafafa;
  transition: transform 0.5s ease-in-out;
  transform: scaleX(0);
  transform-origin: right;
}

a:focus::after, a:hover::after {
  transform: scaleX(1);
  transform-origin: left;
}



.links {
  display: flex;
  justify-content: flex-end;
  margin-right: 0;
}

.last-element {
  padding: 6rem 0 3rem 0;
}
              
            
!

JS

              
                
              
            
!
999px

Console