aboutsummaryrefslogtreecommitdiff
path: root/build/keynote-slides-css/index.html
blob: 1c009fa462bb84f93fe22f3bc668b476a4431a1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="color-scheme" content="dark light">
	<link rel="icon" href="data:,">
	<title>Keynote Slides with Pure CSS</title>
	<link href="/atom.xml" type="application/atom+xml" rel="alternate" title="Atom feed for blog posts" />
	<link href="/rss.xml" type="application/rss+xml" rel="alternate" title="RSS feed for blog posts" />
<style>*{box-sizing:border-box;}body{font-family:sans-serif;line-height:1.33;margin:0 auto;max-width:650px;padding:1rem;}blockquote{background:rgba(0,0,0,0.1);border-left:4px solid;padding-left:5px;}img{max-width:100%;}pre{border:1px solid;overflow:auto;padding:5px;}table{text-align:left;width:100%;}.footnotes{font-size:90%;}</style>
</head>

<nav>
	<a href="#menu">Menu &darr;</a>
</nav>

<main>
<h1 id="keynote-slides-with-pure-css">Keynote Slides with Pure CSS</h1>
<p>2020-06-22</p>
<p>There are a great deal of options available on the web and built into most operating systems when you need to create presentation &#47; keynote slides. You could use native software like LibremOffice Impress, Powerpoint, Apple&#8217;s Keynote, etc. You could also decide to use preexisting web-based apps like Google Slides or an open source project such as RevealJS. All of these are good options.</p>
<p>But thinking more about how overly complex these apps are implemented, it got me wondering if I could quickly code up a presentation slide framework with pure CSS and barely any code.</p>
<p>This is what I came up with:</p>
<h2 id="the-demo">The Demo</h2>
<p><a href="https://codepen.io/bradleytaunt/pen/jOWBJZb">Live CodePen Example</a></p>
<p>Yes, I know this is <em>ugly</em>, but this was created as a barebones skeleton for others to build upon. The demo uses a simple set of <code>radio</code> inputs that correspond to their own individual <code>slide</code> element. The framework looks at the currently <code>checked</code> input, then changes the <code>opacity</code> and <code>z-index</code> of its corresponding slide item. Pretty straightforward stuff!</p>
<p>Let&#8217;s break down each piece:</p>
<h2 id="the-html">The HTML</h2>
<pre><code>&#60;div class="slider"&#62;
    &#60;input type="radio" name="pagination" value="1" checked&#62;
    &#60;input type="radio" name="pagination" value="2"&#62;
    &#60;input type="radio" name="pagination" value="3"&#62;
    &#60;input type="radio" name="pagination" value="4"&#62;
    &#60;input type="radio" name="pagination" value="5"&#62;

    &#60;div class="slide"&#62;
        &#60;h2&#62;Slide 1&#60;&#47;h2&#62;
    &#60;&#47;div&#62;
    &#60;div class="slide"&#62;
        &#60;h2&#62;Slide 2&#60;&#47;h2&#62;
    &#60;&#47;div&#62;
    &#60;div class="slide"&#62;
        &#60;h2&#62;Slide 3&#60;&#47;h2&#62;
    &#60;&#47;div&#62;
    &#60;div class="slide"&#62;
        &#60;h2&#62;Slide 4&#60;&#47;h2&#62;
    &#60;&#47;div&#62;
    &#60;div class="slide"&#62;
        &#60;h2&#62;Slide 5&#60;&#47;h2&#62;
    &#60;&#47;div&#62;
&#60;&#47;div&#62;
</code></pre>
<p>There isn&#8217;t a whole lot going on here. We are just including a set of <code>radio</code> inputs (based on how many slides are desired) along with their corresponding <code>slide</code> class elements. You might notice we don&#8217;t do anything to specifically target each individual slide item - you&#8217;ll see why we don&#8217;t need to in the CSS section!</p>
<h2 id="the-css-scss">The CSS (SCSS)</h2>
<pre><code>&#47;* Basic default styles *&#47;
.slider {
    height: 100%;
    left: 0;
    position: fixed;
    top: 0;
    width: 100%;

    .slide {
        height: 100%;
        opacity: 0;
        position: absolute;
        width: 100%;
        z-index: -2;
    }
}

input[type="radio"] { cursor: pointer; }

&#47;* Target slide item based on currently checked radio *&#47;
input[type="radio"]:nth-of-type(1):checked ~ .slide:nth-of-type(1),
input[type="radio"]:nth-of-type(2):checked ~ .slide:nth-of-type(2),
input[type="radio"]:nth-of-type(3):checked ~ .slide:nth-of-type(3),
input[type="radio"]:nth-of-type(4):checked ~ .slide:nth-of-type(4),
input[type="radio"]:nth-of-type(5):checked ~ .slide:nth-of-type(5) {
    opacity: 1;
    z-index: 1;
}

&#47;* Individual slide styling *&#47;
.slide:nth-of-type(1) { background: dodgerblue; }
.slide:nth-of-type(2) { background: crimson; }
.slide:nth-of-type(3) { background: rebeccapurple; }
.slide:nth-of-type(4) { background: goldenrod; }
.slide:nth-of-type(5) { background: pink; }
</code></pre>
<p>Again, not much to see here. We use CSS to look down through the DOM for each <code>radio</code> elements slide &#8220;partner&#8221;. We do this by targeting the <code>nth-of-type</code> on both elements. Simple stuff.</p>
<p>Some drawbacks to this approach:</p>
<ul>
<li>You need to manually target each new slide you add (color, styling, content, etc.)</li>
<li>Lack of animations might require extra work to implement (maybe 3rd party libraries- ke AOS?)</li>
<li>Probably won&#8217;t be best for extremely long&#47;complex presentation slides</li>
</ul>
<p>That&#8217;s it! Hope you enjoy playing around with it.</p>
<footer role="contentinfo">
    <h2>Menu Navigation</h2>
    <ul id="menu">
        <li><a href="/">Home</a></li>
        <li><a href="/projects">Projects</a></li>
        <li><a href="/uses">Uses</a></li>
        <li><a href="/wiki">Wiki</a></li>
        <li><a href="/resume">Resume</a></li>
        <li><a href="/colophon">Colophon</a></li>
        <li><a href="/now">Now</a></li>
        <li><a href="/donate">Donate</a></li>
        <li><a href="/atom.xml">RSS</a></li>
        <li><a href="#top">&uarr; Top of the page</a></li>
    </ul>
    <small>
        Built with <a href="https://git.sr.ht/~bt/barf">barf</a>. <br>
        Maintained with ♥ for the web. <br>
        Proud supporter of <a href="https://usefathom.com/ref/DKHJVX">Fathom</a> &amp; <a href="https://nextdns.io/?from=74d3p3h8">NextDNS</a>. <br>
        The content for this site is <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>.<br> The <a href="https://git.sr.ht/~bt/bt.ht">code for this site</a> is <a href="https://git.sr.ht/~bt/bt.ht/tree/master/item/LICENSE">MIT</a>.
    </small>
</footer>