Skip to content

Commit d53963a

Browse files
patrickhlaukekfranqueirombgower
authored
Tweak inline code and preformatted blocks (#4683)
Adds a contrasting border to preformatted blocks (mainly for code blocks, but a few others), gives a subtle style to inline code elements in prose Relates to #4193 and applies suggestion 1 (the box around the `pre`) and a slightly tweaked variant of suggestion 2b (the "subtle" style for `code`, with some extra selector shenanigans to avoid having the background when it's inside a link or already in a `pre` block) EDIT: as a quick before/after, see https://www.w3.org/WAI/WCAG22/Techniques/html/H85 and the preview here https://deploy-preview-4683--wcag2.netlify.app/techniques/html/h85 --------- Co-authored-by: Kenneth G. Franqueiro <[email protected]> Co-authored-by: Mike Gower <[email protected]>
1 parent 7b95287 commit d53963a

File tree

7 files changed

+36
-24
lines changed

7 files changed

+36
-24
lines changed

css/base.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,20 @@ figcaption {
491491
margin: 1em 0 0 0;
492492
}
493493
}
494+
495+
/* preformatted blocks - generally contain code element */
496+
497+
pre {
498+
padding: 1em;
499+
border: 1px solid var(--line-grey);
500+
background-color: var(--pure-white);
501+
}
502+
503+
/* inline code not in a preformatted block or link */
504+
505+
:not(:is(pre, a)) > code {
506+
font-size: 0.85em;
507+
background: #ebebeb;
508+
padding: 0 0.25em;
509+
display: inline-block;
510+
}

techniques/aria/ARIA19.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h3>Injecting error messages into a container with role=alert already present in
1414
</p>
1515
<p>jQuery is used to test if the inputs are empty on submit and inject error messages into the live region containers if so. Each time a new submit is attempted the previous error messages are removed from the container and new error messages injected.
1616
</p>
17-
<pre xml:space="preserve"><code class="language-javascript">$(document).ready(function(e) {
17+
<pre><code class="language-javascript">$(document).ready(function(e) {
1818
$('#signup').submit(function() {
1919
$('#errors').html('');
2020
if ($('#first').val() === '') {
@@ -28,8 +28,8 @@ <h3>Injecting error messages into a container with role=alert already present in
2828
}
2929
return false;
3030
});
31-
});</code>
32-
<code class="language-html">&lt;form name="signup" id="signup"&gt;
31+
});</code></pre>
32+
<pre><code class="language-html">&lt;form name="signup" id="signup"&gt;
3333
&lt;p id="errors" role="alert" aria-atomic="true"&gt;&lt;/p&gt;
3434
&lt;div&gt;
3535
&lt;label for="first"&gt;First Name (required)&lt;/label&gt;&lt;br&gt;

techniques/failures/F2.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ <h3>Using CSS to style the <code>p</code> element to look like a heading</h3>
88

99
<p>The author intended to make a heading but didn't want the look of the default HTML heading. So they used CSS to style the P element to look like a heading and they called it a heading. But they failed to use the proper HTML heading element. Therefore, the Assistive Technology could not distinguish it as a heading.</p>
1010

11-
<pre xml:space="preserve"><code class="language-html">&lt;style&gt;
11+
<pre><code class="language-html">&lt;style&gt;
1212
.heading1{
1313
font-family: Times, serif;
1414
font-size:200%;
1515
font-weight:bold;
1616
}
1717
&lt;/style&gt;
18-
</code>
19-
<code class="language-html">&lt;p class="heading1"&gt;Introduction&lt;/p&gt;
20-
&lt;p&gt;This introduction provides detailed information about how to use this ...&lt;/p&gt;</code>
21-
</pre>
18+
</code></pre>
19+
<pre><code class="language-html">&lt;p class="heading1"&gt;Introduction&lt;/p&gt;
20+
&lt;p&gt;This introduction provides detailed information about how to use this ...&lt;/p&gt;</code></pre>
2221

2322
<div class="note">
2423
<p>In this case, the proper approach would be to use CSS to style the <code>H1</code> element in HTML.</p>

techniques/failures/F37.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ <h3></h3>
1919
the form when a radio button is selected instead of using a submit
2020
button. </p>
2121

22-
<pre xml:space="preserve"><code class="language-html">&lt;script&gt;
22+
<pre><code class="language-html">&lt;script&gt;
2323
function goToMirror(theInput) {
2424
var mirrorSite = "https://download." + theInput.value + "/";
2525
window.open(mirrorSite);
2626
}
27-
&lt;/script&gt;</code>
28-
...
29-
<code class="language-html">&lt;form name="mirror_form" id="mirror_form" action="" method="get"&gt;
27+
&lt;/script&gt;</code></pre>
28+
<pre><code class="language-html">&lt;form name="mirror_form" id="mirror_form" action="" method="get"&gt;
3029
&lt;p&gt;Please select a mirror download site:&lt;/p&gt;
3130
&lt;p&gt;
3231
&lt;input type="radio" onclick="goToMirror(this);" name="mirror"

techniques/failures/F50.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525

2626
// kick it off
2727
show();
28-
&lt;/script&gt;</code>
29-
...
30-
<code class="language-html">&lt;span id="blink1"&gt;This content will blink&lt;/span&gt;</code></pre>
28+
&lt;/script&gt;</code></pre>
29+
<pre><code class="language-html">&lt;span id="blink1"&gt;This content will blink&lt;/span&gt;</code></pre>
3130
</section>
3231
</section><section id="tests"><h2>Tests</h2>
3332
<section class="procedure"><h3>Procedure</h3>

techniques/failures/F88.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<p>In the following example of a failure, the HTML <code>align</code> attribute is used to create justified text.</p>
99

10-
<pre xml:space="preserve"><code class="language-html">&lt;p align="justify"&gt;
10+
<pre><code class="language-html">&lt;p align="justify"&gt;
1111
Peter Piper picked a peck of pickled peppers
1212
A peck of pickled peppers Peter Piper picked
1313
If Peter Piper picked a peck of pickled peppers
@@ -18,13 +18,12 @@
1818

1919
<p>In this example of a failure, the CSS text-align property is used to create justified text.</p>
2020

21-
<pre xml:space="preserve"><code class="language-css">p {text-align: justify}</code>
22-
<code class="language-html">&lt;p&gt;
21+
<pre><code class="language-css">p {text-align: justify}</code></pre>
22+
<pre><code class="language-html">&lt;p&gt;
2323
How much wood would a woodchuck chuck if a woodchuck could chuck wood?
2424
He would chuck, he would, as much as he could, and chuck as much wood
2525
As a woodchuck would if a woodchuck could chuck wood.
26-
&lt;/p&gt;</code>
27-
</pre>
26+
&lt;/p&gt;</code></pre>
2827
</section>
2928
</section><section id="tests"><h2>Tests</h2>
3029
<section class="procedure"><h3>Procedure</h3>

techniques/failures/F94.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ <h2>Examples</h2>
2727
<section class="example">
2828
<h3>Failure example 1</h3>
2929
<p>The following CSS and HTML snippet uses VW units to size the text.</p>
30-
<pre xml:space="preserve"><code class="language-css">/* CSS */
30+
<pre><code class="language-css">/* CSS */
3131
.callout {
3232
font-size:1vw;
33-
}</code>
34-
35-
<code class="language-html">&lt;p class="callout"&gt;Text that scales by viewport units&lt;/p&gt;</code></pre>
33+
}</code></pre>
34+
<pre><code class="language-html">&lt;p class="callout"&gt;Text that scales by viewport units&lt;/p&gt;</code></pre>
3635
<p class="working-example">Example <a href="../../working-examples/failure-viewport-units/">page with an example of text sized in <code>vh</code> units</a>.</p>
3736
</section>
3837
</section>

0 commit comments

Comments
 (0)