fix sidenote width and add partial nesting support
This commit is contained in:
parent
60eea00b88
commit
54bcec280d
@ -10,7 +10,7 @@
|
|||||||
margin-left: 0.05rem;
|
margin-left: 0.05rem;
|
||||||
|
|
||||||
&:after {
|
&:after {
|
||||||
font-size: 0.75rem;
|
font-size: 0.75em;
|
||||||
position: relative;
|
position: relative;
|
||||||
bottom: 0.3rem;
|
bottom: 0.3rem;
|
||||||
color: #8c0606;
|
color: #8c0606;
|
||||||
@ -23,7 +23,8 @@
|
|||||||
|
|
||||||
&:before {
|
&:before {
|
||||||
content: counter(sidenote) " ";
|
content: counter(sidenote) " ";
|
||||||
/* absolute positioning puts it at the top-left corner of the sidenote */
|
/* absolute positioning puts it at the top-left corner of the sidenote, overlapping with the content
|
||||||
|
(because the sidenote is floated it counts as a positioned parent, I think) */
|
||||||
position: absolute;
|
position: absolute;
|
||||||
/* translate moves it out to the left (and just a touch up to mimic the superscript efect)
|
/* translate moves it out to the left (and just a touch up to mimic the superscript efect)
|
||||||
-100% refers to the width of the element, so it pushes it out further if necessary (i.e. two digits instead of one) */
|
-100% refers to the width of the element, so it pushes it out further if necessary (i.e. two digits instead of one) */
|
||||||
@ -46,7 +47,7 @@
|
|||||||
.sidenote {
|
.sidenote {
|
||||||
--gap: 2rem;
|
--gap: 2rem;
|
||||||
--sidenote-width: min(14rem, calc(50vw - var(--gap) - var(--content-width) / 2));
|
--sidenote-width: min(14rem, calc(50vw - var(--gap) - var(--content-width) / 2));
|
||||||
max-width: var(--sidenote-width);
|
width: var(--sidenote-width);
|
||||||
hyphens: auto;
|
hyphens: auto;
|
||||||
position: relative;
|
position: relative;
|
||||||
float: right;
|
float: right;
|
||||||
@ -55,6 +56,12 @@
|
|||||||
margin-bottom: 0.7rem;
|
margin-bottom: 0.7rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nested.sidenote {
|
||||||
|
margin-right: 0;
|
||||||
|
margin-top: 0.7rem;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.dismiss {
|
.dismiss {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@ -127,6 +134,21 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
|
let noteBody;
|
||||||
|
let nested = false;
|
||||||
|
onMount(() => {
|
||||||
|
// check to see if the parent node is also a sidenote, if so move this one to the end
|
||||||
|
let parentNote = noteBody.parentElement.closest('span.sidenote');
|
||||||
|
if (parentNote) {
|
||||||
|
noteBody.remove();
|
||||||
|
parentNote.appendChild(noteBody);
|
||||||
|
nested = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
const id = Math.random().toString().slice(2);
|
const id = Math.random().toString().slice(2);
|
||||||
let toggle;
|
let toggle;
|
||||||
|
|
||||||
@ -146,7 +168,7 @@
|
|||||||
|
|
||||||
<label for={id} on:click={toggleState} class="counter"></label>
|
<label for={id} on:click={toggleState} class="counter"></label>
|
||||||
<input {id} bind:this={toggle} type="checkbox" class="sidenote-toggle" />
|
<input {id} bind:this={toggle} type="checkbox" class="sidenote-toggle" />
|
||||||
<span class="sidenote">
|
<span class="sidenote" class:nested bind:this={noteBody}>
|
||||||
<label class="dismiss" for={id} on:click={toggleState}>×</label>
|
<label class="dismiss" for={id} on:click={toggleState}>×</label>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</span>
|
</span>
|
Loading…
x
Reference in New Issue
Block a user