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 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

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

              
                <main>
<h1>Links with Marginalia Notes, Take 2</h1>
<p>Another attempt to create an accessible and more fully-responsive version of the link style used in <a href="https://thecorrespondent.com/5575/our-fate-was-sealed-long-before-november-8-and-not-because-the-elections-rigged/1576889402275-7591b019" class="link-main" aria-describedby="note-1"><cite>The Correspondent</cite>.</a> <span id="note-1" role="complementary" class="link-note article">The Sarah Kendzior article I was reading is also recommended, separate from the web design.</span> Each link in the main text has an associated marginalia note, describing the linked resource. </p>
<p>
  In <cite>The Correspondent</cite>, there are actually two versions of the link in the markup: a regular link, displayed on narrower screens, or the linked marginalia note plus a plain text span for wider screens.  The switch was done with media queries, however, and the <a href="https://w3c.github.io/aria/aria/aria.html#aria-hidden" class="link-main" aria-describedby="note-2"><code>aria-hidden</code> attribute</a> <span id="note-2" role="complementary" class="link-note book">The official definition of <code>aria-hidden</code> warns against overuse.</span> that hides the duplication is never removed when the plain link is hidden with <code>display: none</code>.  In addition to ensuring that a basic link is always accessible, I wanted to make the text of the note accessible, for screen reader users and also for mobile users.
</p>
<p>
  I included both the link text and the note inside a single, always displayed link in my <a href="https://codepen.io/AmeliaBR/pen/QGNPWb?editors=1100" target="_blank" class="link-main" aria-describedby="note-5">original pen</a>. <span id="note-5" role="complementary" class="link-note picture">The original should look mostly the same on wide screens, but it has additional hover effects I couldn't re-create here.</span>  In this version, the note is a separate element inserted after the link.  Both versions use transforms to slide the note into view on narrow screens when it is touched/hovered.  The main reason for the markup change was to allow the note to be tapped into view on a mobile touch screen, without activating the link.  On wide screens, a transparent overlay (that is actually a psuedo-element for the link) is used to make the top of each note clickable. I'd also be interested in feedback from regular touchscreen users on whether this improves usability&mdash;and also feedback from desktop & mouse users on whether it noticeably detracts from usability!
</p>
<p>
  Another usability question: on narrow screens, I'm currently letting the off-screen notes create a horizontal scrollbar.  Easy to prevent with hidden overflow, but should I?  Is it nice to be able to swipe the screen and see all the notes at once? Or does that interfere with browser/OS swipe gestures?
<p>
  <p>For screen-readers, the note has a <a href="https://w3c.github.io/aria/aria/aria.html#complementary" class="link-main" aria-describedby="note-6">role of <code>complementary</code></a>. <span id="note-6" role="complementary" class="link-note article">A complementary item in ARIA should be exposed similar to an HTML <code>&lt;aside&gt;</code> element, but try not to get mixed up, like I originally did, and use <code>aside</code> as the role name!</span>  Since it is no longer actually part of the link text, I've indicated the connection via the <code>aria-describedby</code> attribute.  I'd be interested in other suggestions for how best to indicate that this is a parenthetical note, interrupting the main text, while still being part of the link.
</p>
<p>
  One extra benefit of this structure is reduced markup: the inline link is just an <code>&lt;a&gt;</code> element, there is no extra <code>&lt;span&gt;</code>.  You could probably even drop the class on the link; it is only used to trigger the creation of the transparent touch target that hovers over the note in the margin.  I don't think it would be a big problem if a target was created even for links without notes.
</p>
<p>Printer's latin follows with two more sample links (that don't actually link anywhere):</p>
<p>Magni optio, ab tempore id cum excepturi ea possimus distinctio dolore eos <a href="#a" class="link-main" aria-describedby="note-3">nulla consequatur</a> <span id="note-3" role="complementary" class="link-note article">No consequences? That was disputed in this article.</span> autem ex ducimus aperiam a repudiandae iusto perspiciatis odit obcaecati culpa, in voluptas. Voluptate, provident fuga.</p>
<p>Ea accusamus, <a href="#b" class="link-main" aria-describedby="note-4">blanditiis rerum</a> <span id="note-4" role="complementary" class="link-note book">An entire chapter on the blandest rerum of all.</span> voluptatum itaque quam suscipit nam, at ullam alias! Ea, eum quia beatae sequi quidem iure voluptas, qui totam, ullam, assumenda mollitia perferendis temporibus a! Quasi, tempora!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias, suscipit ea quod reiciendis eaque tenetur quis, numquam eum laborum ipsum ipsam similique obcaecati nulla dicta laboriosam omnis provident dolorem voluptates!</p>
</main>
              
            
!

CSS

              
                body {
  font-family: Georgia, sans-serif;
  background-color: lightGray;
  color: #004;
  margin: 0.5rem;
  padding-right: 10.5rem;
  hyphens: auto;
}
main {
  background-color: #fec;
  padding: 0.5rem;
  padding-right: 1rem;
  max-width: 50em;
  margin: auto;
}
p {
  line-height: 1.4;
}
a {
  color: inherit;
  text-decoration: none;
  background: gray;
  background: linear-gradient(currentColor, currentColor) 0 1em / 100% 1px no-repeat;
}
a.link-main::after,
a + .link-note {
  display: block;
  float: right;
  clear: right;
  position: relative;
  width: 11rem;
  box-sizing: border-box;
  margin-right: -12rem;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  background: lightgray;
  font-size: 90%;
  line-height: 1.1;
}
a.link-main::after{
  /* positioned above the icon-line in the note, 
     as a click-grabber */
  content: "";
  z-index: 100; 
  height: 1.5rem;
  margin-bottom: -1.5rem;
  left: -1rem;
  border-radius: 0.75rem;
  background: transparent;
  //background: green;
}
a + .link-note::before {
  content: " ";
  display: block;
  margin: 0 0.2rem 0.2rem 0.6rem;
}
a + .link-note.book::before {
  content: "📖";
} 
a + .link-note.article::before {
  content: "📰";
} 
a + .link-note.picture::before {
  content: "🖼️";
} 
a + .link-note::after {
  content: "";
  display: block;
  box-sizing: border-box;
  width: 1.2rem; height: 1.2rem;
  top: 0.25rem;
  left: -0.5rem;
  background-color: #fec;
  border: solid 0.4rem lightgray;
  border-radius: 50%;
  position: absolute;
}
a:hover, a:focus {
  color: #c21;
  outline: none;
}
a:hover + .link-note::after,
a:focus + .link-note::after {
  background-color: currentColor;
}

a:hover + .link-note::before,
a:focus + .link-note::before {
  color: #fec; /* provide contrast if emoji aren't substituted */
  text-shadow: 0.2em 0.15em 0 #004;
}
@media (max-width: 40em) {
  body {
    padding-right: 0.5em;
    margin: 0;
  }
  a + .link-note {
    z-index: 200;
  }
  a + .link-note {
    margin-top: 1.4rem;
    clear: none;
    transition: transform 0.2s ease-out;
  }
  a + .link-note::after {
    top: 0;
    left: -1rem;
    width: 2.1em;
    height: 2.1em;
    border-width: 0.7em;
  }
  a.link-main::after {
    content: normal; 
    /* don't try to have a touch target over top of a moving note */
  }
  .link-note:hover, 
   a:focus + .link-note {
    transition-timing-function: ease-in;
    transform: translateX(-10rem);
    color: #004;
    z-index: auto;
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console