-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Glosses in numbered examples #1
Comments
Oh, hi, @pavelrudnev! I have exactly the same question... |
There is an unelegant solution:
|
The thing is that the example number ought to be in a column of its own, so to speak – as if each example were put into a table containing one row and two columns – one for the number, and one for the rest. So that, if the the example is long, the next line won't start under the number, but under the first word of the first line. Also, some authors prefer to put the example number to the right of the example – that would be easy to do in a table, too, I guess. |
Hi @pavelrudnev , @agricolamz , and @twid -- Thanks so much for taking the time to use the lib and report the issue. Apologies for not replying sooner 😬 Current solutionsWith flexbox now widely supported, adding numbers is relatively simple. The general idea is to create a container with <style>
.example {
display: flex;
}
.example[data-example-number]::before {
content: attr(data-example-number) ")";
margin-top: 1em; /* match default <p> margin-top */
}
</style>
<figure class="example" data-example-number="1">
<div data-gloss>
<p>...</p>
<p>...</p>
<p>...</p>
</div>
</figure> To automate the numbering, you could use something like CSS counters: <style>
body {
counter-reset: gloss-number;
}
.example {
display: flex;
}
.example::before {
counter-increment: gloss-number;
content: counter(gloss-number) ")";
margin-top: 1em; /* match default <p> margin */
}
</style>
<figure class="example">
<div data-gloss>
<p>...</p>
<p>...</p>
<p>...</p>
</div>
</figure> If you don't like having to nest the glosses in a container like that, you could use <style type="text/css">
figure {
margin: 0;
}
[data-example-number] {
padding-left: 2em;
/* required so that the number is positioned relative to the gloss */
position: relative;
}
[data-example-number]::before {
content: attr(data-example-number) ")";
position: absolute;
left: 0;
}
</style>
<figure data-gloss data-example-number="1">
<p>...</p>
<p>...</p>
<p>...</p>
</figure> Flexbox also allows us to move the numbering to the right, as mentioned by @twid: <style type="text/css">
figure {
margin: 0;
}
[data-example-number] {
display: flex;
/* force the number and gloss to opposite sides */
justify-content: space-between;
}
/**
* using ::after instead of ::before, but we could also
* use the `order` property here, or change the
* `flex-direction` property in the container.
*/
[data-example-number]::after {
content: "(" attr(data-example-number) ")";
margin-top: 1em; /* match default <p> margin-top */
margin-left: 1em;
text-align: right; /* ensure text really is all the way to the right */
}
</style> I put together a demo showing each of these approaches: https://codesandbox.io/s/leipzigjs-2-ks9vi FutureI'm not sure if I want to pull these rules into the lib's stylesheet -- at least not yet. I'm definitely open to the idea, but at the same time, numbering feels very idiosyncratic to me, and I'm wary of having to implement a super flexible numbering system, when users could instead copy-paste some CSS snippets and get 95% of the way there. If / when we do add support for numbering, I think we'd want to support both the manual and automatic approaches:
I think the "containerless" Instead, we could automatically generate the containers we detect either of the following:
Thanks again for taking the time to open & comment on the issue. |
@bdchauvette I appreciate your thoughtful exposition on the issue of numbering. In trying to add to the productive conversation, is there no way to right align the numbers so that the white space is consistent between the numbers and the examples? Such as roman numerals in order lists, or leading zeros. see: https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type Also there should be perhaps a third trigger which say no-numbering to not use any number system at all. |
Hi @HughP! Thanks for adding to the conversation!
Just to clarify, would you like it to look something like the following?
If so, I think that should be do-able by adding two additional properties to the pseudo-element CSS:
e.g. [data-example-number]::before {
content: attr(data-example-number) ")";
margin-top: 1em; /* match default <p> margin-top */
+ width: 2em;
+ text-align: right;
} You could use this same approach with absolute positioning, but instead of using [data-example-number]::before {
content: attr(data-example-number) ")";
position: absolute;
+ right: calc(100% - 2em);
} You'll probably also want to bump up the
Definitely. I think this would continue to be the default option, considering how idiosyncratic number styling can be. |
Great little utility, very useful, thanks! I was wondering whether it was possible for the glosses to appear as numbered examples.
The text was updated successfully, but these errors were encountered: