0

I'm building a template for writing some technical documentation. I'd love to do this with as little Javascript as possible. I am including a minimal example

When the screen is wide, it floats references in span tags to the left margin. When the screen gets narrow (e.g., on mobile devices), there's not enough digital real estate to display a left margin, and I would like to display the references immediately after the paragraph (or, perhaps, at the end of the <section>). I have seen other people suggest doing this with some absolute positioning, but I don't think that works in my case, since there might be multiple references in a single paragraph. Another option that I've seen presented is to put all of the margin notes for a paragraph in a single <aside> block that gets floated to the margin. For various reasons, I'd love to be able to put the span tag as close as possible to the text that it refers to. In a perfect world, I want to keep the html as semantic as possible, so I don't want to wrap each paragraph in another div tag or table tag.

One near solution that I've been able to do (shown in the Codepen example) is to display the paragraph as a flexbox, and change the order of the reference spans so that they display after the main text. This almost works, except that by changing the paragraph to display as a flexbox, every continuous line of text between a span gets rendered as a block, which creates awkward line breaks. I've tried a number of CSS tricks to try to get the remaining text to wrap as it normally would if there were no span tags, but I'm beginning to be convinced that this is not supported (perhaps with some clever CSS selectors display: content)

article {
    margin-left: 25%;
    padding: 5px;
    
}

main {
    margin-left: auto;
    margin-right: auto;
    max-width: 800px;
    flex-wrap:wrap;
    
}

section {
    margin-top: 40px;
}

h1 {
  width: calc(125% - 10px);
  margin-left: -25%;
  text-align: center;
}

h2 {
  width: calc(125%);
  margin-left: calc(-33%);
  border-top: 1px solid gray;
  padding-top: 10px;
  padding-left: 40px;
}

span.ref {
  float: left;
  clear: both;
  width: calc(33% - 8px);
  margin-left: -33%;
  hyphens: auto;
  font-size: 14px;
  color: #666;
  text-align: left;
}

@media only screen and (max-width: 500px) {
  
  article {
    margin-left: 0px;
  }
  
  h1, h2 {
    margin-left: 0;
    padding-left: 0;
    width: 100%;
  }
  
  p {
    display: flex;
    flex-direction: column;
  }
  
  span.ref {
    order: 2;
    float: none;
    margin-left: 0px;
  }
  
 p > span.ref:first-of-type {margin-top: 10px;}
  
  
}
<body>
    <main>
        <article>
            <h1>Document Title</h1>
            <section>
                <h2>First section of the document</h2>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras fringilla porta est nec rhoncus. Vestibulum ultricies molestie ante, vel fringilla turpis tempor at. Maecenas eu leo justo. Aliquam scelerisque metus in massa hendrerit [1], <span class="ref">[1] Wikipedia. </span>non condimentum augue pharetra. Etiam in lorem eu nibh sagittis [2] <span class="ref">[2] A fancy textbook</span> lacinia sit amet eu odio. Quisque ultricies lacinia dignissim. Suspendisse blandit urna justo, et blandit metus tincidunt at. Quisque vel varius enim.
              </p>
              <p>
                Aenean cursus vestibulum libero, eu vulputate nisi efficitur sit amet. Praesent quis metus ac leo eleifend tempus. Praesent ac mauris eleifend, luctus ligula vel, interdum lectus. Donec iaculis in est non iaculis. Nullam vulputate, lorem quis placerat condimentum, risus lectus feugiat neque, id auctor augue elit ut enim. Donec vel rutrum massa. Nunc laoreet nulla et eleifend facilisis. Morbi scelerisque velit sit amet libero viverra mattis. Vivamus non porta neque, et rhoncus mi. In lectus nisl, faucibus nec sem sed, ullamcorper commodo ante. Aliquam ac massa imperdiet, viverra lacus eget, convallis ex. Phasellus tempus lacinia enim id tincidunt.
              </p>
            </section>
          <section>
            <h2>A second section</h2>
          </section>
        </article>
    </main>
</body>
Jonathan Wheeler
  • 2,539
  • 1
  • 19
  • 29
  • Without JS the system will be difficult to maintain - as soon as another reference is added or removed somewhere the author has to go through the text updating the numbering. Is it worth it just to remove a few lines of code? even having to repeat the numbers as now feels a bit uncomfortable - semantically not quite right. – A Haworth Jun 12 '23 at 03:14

3 Answers3

1

As you dont want javascript, the only way I could think of is to have the references duplicated, one visible only for desktop other visible only for mobile:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      article {
        margin-left: 25%;
        padding: 5px;
      }

      main {
        margin-left: auto;
        margin-right: auto;
        max-width: 800px;
        flex-wrap: wrap;
      }

      section {
        margin-top: 40px;
      }

      h1 {
        width: calc(125% - 10px);
        margin-left: -25%;
        text-align: center;
      }

      h2 {
        width: calc(125%);
        margin-left: calc(-33%);
        border-top: 1px solid gray;
        padding-top: 10px;
        padding-left: 40px;
      }

      span.ref {
        float: left;
        clear: both;
        width: calc(33% - 8px);
        margin-left: -33%;
        hyphens: auto;
        font-size: 14px;
        color: #666;
        text-align: left;
      }

      .ref-mobile-container {
        display: none;
      }

      @media only screen and (max-width: 700px) {
        article {
          margin-left: 0px;
        }

        h1,
        h2 {
          margin-left: 0;
          padding-left: 0;
          width: 100%;
        }

        span.ref.desktop {
          display: none;
        }

        .ref-mobile-container {
          display: block;
          margin-top: 10px;
        }

        span.ref {
          display: inline;
          float: none;
          margin-left: 0;
        }
      }
    </style>
  </head>
  <body>
    <main>
      <article>
        <h1>Document Title</h1>
        <section>
          <h2>First section of the document</h2>
          <p class="">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras fringilla porta est nec rhoncus. Vestibulum
            ultricies molestie ante, vel fringilla turpis tempor at. Maecenas eu leo justo. Aliquam scelerisque metus in
            massa hendrerit [1],
            <span class="desktop ref">[1] Wikipedia. </span>non condimentum augue pharetra. Etiam in lorem eu nibh
            sagittis [2] <span class="desktop ref">[2] A fancy textbook</span> lacinia sit amet eu odio. Quisque
            ultricies lacinia dignissim. Suspendisse blandit urna justo, et blandit metus tincidunt at. Quisque vel
            varius enim.
          </p>
          <div class="ref-mobile-container">
            <span class="ref">[1] Wikipedia. </span>
            <span class="ref">[2] A fancy textbook</span>
          </div>
          <p>
            Aenean cursus vestibulum libero, eu vulputate nisi efficitur sit amet. Praesent quis metus ac leo eleifend
            tempus. Praesent ac mauris eleifend, luctus ligula vel, interdum lectus. Donec iaculis in est non iaculis.
            Nullam vulputate, lorem quis placerat condimentum, risus lectus feugiat neque, id auctor augue elit ut enim.
            Donec vel rutrum massa. Nunc laoreet nulla et eleifend facilisis. Morbi scelerisque velit sit amet libero
            viverra mattis. Vivamus non porta neque, et rhoncus mi. In lectus nisl, faucibus nec sem sed, ullamcorper
            ex. Phasellus tempus lacinia enim id tincidunt.Aenean cursus vestibulum libero, eu vulputate nisi efficitur
            sit amet. Praesent quis metus ac leo eleifend tempus. Praesent ac mauris eleifend, luctus ligula vel,
            interdum lectus. Donec iaculis in est non iaculis. Nullam vulputate, lorem quis placerat condimentum, risus
            lectus feugiat neque, id auctor augue elit ut enim. Donec vel rutrum massa. Nunc laoreet nulla et eleifend
            facilisis. Morbi scelerisque velit[3] <span class="desktop ref">[3] ChatGPT. </span> sit amet libero viverra
            mattis. Vivamus non porta neque, et rhoncus mi. In lectus nisl, faucibus nec sem sed, ullamcorper commodo
            ante. Aliquam ac massa imperdiet, viverra[4] <span class="desktop ref">[4] Stack Overflow. </span> lacus
            eget, convallis ex. Phasellus tempus lacinia enim id tincidunt.Aenean cursus vestibulum libero, eu vulputate
            nisi efficitur sit amet. Praesent quis metus ac leo eleifend tempus. Praesent ac mauris eleifend, luctus
            ligula vel,[5] <span class="desktop ref">[5] Bing. </span> interdum lectus. Donec iaculis in est non
            iaculis. Nullam vulputate, lorem quis placerat condimentum, risus lectus feugiat neque, id auctor augue elit
            ut enim. Donec vel rutrum massa. Nunc laoreet nulla et eleifend facilisis. Morbi scelerisque velit sit amet
            libero viverra mattis. Vivamus non porta neque, et rhoncus mi. In lectus nisl, faucibus nec sem sed,
            ullamcorper commodo ante. Aliquam ac massa imperdiet, viverra lacus eget, convallis ex. Phasellus tempus
            lacinia enim id tincidunt.
          </p>
          <div class="ref-mobile-container">
            <span class="ref">[3] ChatGPT. </span>
            <span class="ref">[4] Stack Overflow. </span>
            <span class="ref">[5] Bing. </span>
          </div>
        </section>
        <section>
          <h2>A second section</h2>
        </section>
      </article>
    </main>
  </body>
</html>
Paulo Fernando
  • 3,148
  • 3
  • 5
  • 21
1

I had another crack and was able to get it working with a single version (with some caveats). No need to duplicate the references or adjust the base HTML at all.

Note: I'm using :has selector that is not currently supported in FireFox. How do you enable :has() selector on Firefox Firefox enable :has() selector

Spans need to be 'yanked' right out of their default inline spot with position: absolute to have the residual paragraph text move up where the reference spans were previously.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>References in left column for desktop. References below paragraphs for mobile.</title>
<style>

:root {
  --main-max-width:         800px;
  --citation-col-width:     180px;
  --span-reference-top:     1.3rem;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  padding-top: 1rem;
  padding-bottom: 1rem;
  font-family: sans-serif;
  font-size: 1rem;
  line-height: 1.35;
  background: #fafafa;
  color: #1a1a1a;
}

article {
  padding: 1rem;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,.2); 
}

main {
  margin-right: auto;  
  margin-left: auto;
  max-width: var(--main-max-width);
}

section.grid-2-col {
  display: grid;
  /* 2 COLUMNS: FIXED PX WIDTH THEN RESIDUAL IS TAKEN UP */
  grid-template-columns: var(--citation-col-width) 1fr;
  grid-column-gap: 1rem;
  margin-top: 2.5rem;
}

section.grid-2-col h2 {
  grid-column: span 2;
}

section.grid-2-col p {
  /* PARAS START IN GRID 2ND COLUMN */
  grid-column-start: 2;
  margin-top: 0;
  margin-bottom: .7rem;
  position: relative;
}

section.grid-2-col span.ref {
  /* HAD TO POSITION ABSOLUTE TO HIDE OVERFLOWING REFERENCES */
  position: absolute;
  display: block;
  max-width: var(--citation-col-width);
  /* NEGATIVE VALUE (* -1), -CITATION COLUMN WIDTH - COL GAP */
  left: calc((var(--citation-col-width) * -1) - 1rem);
  /* WHEN WRAPPING SPANS OVERLAPPED */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: .8rem;
  color: #666;
}

/* UP TO 4 REFERENCES PER PARA (ADD MORE IF REQUIRED) */
section.grid-2-col span.ref:nth-of-type(1) {
  top: 0;
}

section.grid-2-col span.ref:nth-of-type(2) {
  top: var(--span-reference-top);
}

section.grid-2-col span.ref:nth-of-type(3) {
  top: calc(var(--span-reference-top) * 2);
}

section.grid-2-col span.ref:nth-of-type(4) {
  top: calc(var(--span-reference-top) * 3);
}

h1, h2 {
  font-weight: 400;
  margin-top: 0;
  margin-bottom: .8rem;
}

h1 {
  font-size: 2.8rem;
  color: #9d9d9d;
  border-bottom: 1px solid #9d9d9d;
  margin-bottom: 2.5rem;
}

h2 {
  font-size: 1.5rem;
}

@media only screen and (max-width: 799px) {
  article {
padding-right: .5rem;
padding-left: .5rem;
  }

  section.grid-2-col {
/* DON'T NEED GRID NOW */
display: block;
  }
  
  section.grid-2-col span.ref {
left: unset;
max-width: 90vw;
  }

  /* UP TO 4 REFERENCES PER PARA (ADD MORE IF REQUIRED) */
  section.grid-2-col span.ref:nth-of-type(1) {
top: 100%;
  }

  section.grid-2-col span.ref:nth-of-type(2) {
top: calc(100% + var(--span-reference-top));
  }

  section.grid-2-col span.ref:nth-of-type(3) {
top: calc(100% + var(--span-reference-top) * 2);
  }

  section.grid-2-col span.ref:nth-of-type(4) {
top: calc(100% + var(--span-reference-top) * 3);
  }

  /* ALLOW DYNAMIC SPACE FOR ABSOLUTE REFERENCES */
  section.grid-2-col p:has(span.ref:nth-of-type(1)) {
border-bottom: solid var(--span-reference-top) transparent;
  }

  section.grid-2-col p:has(span.ref:nth-of-type(2)) {
border-bottom: solid calc(var(--span-reference-top) * 2) transparent;
  }

  section.grid-2-col p:has(span.ref:nth-of-type(3)) {
border-bottom: solid calc(var(--span-reference-top) * 3) transparent;
  }

  section.grid-2-col p:has(span.ref:nth-of-type(4)) {
border-bottom: solid calc(var(--span-reference-top) * 4) transparent;
  }
}
</style>
</head>
<body>
<main>
    <article>
        <h1>Document title</h1>
        <section class="grid-2-col">
          <h2>First section of the document</h2>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras fringilla porta est nec rhoncus. Vestibulum ultricies molestie ante, vel fringilla turpis tempor at. Maecenas eu leo justo. Aliquam scelerisque metus in massa hendrerit [1], <span class="ref">[1] Wikipedia, truncated long text length to reference</span>. Etiam [2] <span class="ref">[2] A fancy textbook</span> lacinia. Quisque [3] <span class="ref">[3] Another less fancy manuscript reference</span> ultricies lacinia dignissim. Suspendisse [4] <span class="ref">[4] Another far less fancy reference</span> et blandit metus tincidunt at. Quisque vel varius enim.</p>
          <p>Aenean cursus vestibulum libero, eu vulputate nisi efficitur sit amet. Praesent quis metus ac leo eleifend tempus. Praesent ac mauris eleifend, luctus ligula vel, interdum lectus. Donec iaculis in est non iaculis. Nullam vulputate, lorem quis placerat condimentum, risus lectus feugiat neque, id auctor augue elit ut enim. Donec vel rutrum massa. Nunc laoreet nulla et eleifend facilisis. Morbi scelerisque velit sit amet libero viverra mattis. Vivamus non porta neque, et rhoncus mi. In lectus nisl, faucibus nec sem sed, ullamcorper commodo ante. Aliquam ac massa imperdiet, viverra lacus eget, convallis ex. Phasellus tempus lacinia enim id tincidunt.</p>
        </section>
        <section class="grid-2-col">
          <h2>Second section of the document</h2>
          <p>Aenean cursus vestibulum libero, eu vulputate nisi efficitur sit amet. Praesent quis metus ac leo eleifend tempus. Praesent ac mauris eleifend, luctus ligula vel, interdum lectus. Donec iaculis in est non iaculis. Nullam vulputate, lorem quis placerat condimentum, risus lectus feugiat neque, id auctor augue elit ut enim. Donec vel rutrum massa. Nunc laoreet nulla et eleifend facilisis. Morbi scelerisque velit sit amet libero viverra mattis. Vivamus non porta neque, et rhoncus mi. In lectus nisl, faucibus nec sem sed, ullamcorper ex. Phasellus tempus lacinia enim id tincidunt.Aenean cursus vestibulum libero, eu vulputate nisi efficitur sit amet. Praesent quis metus ac leo eleifend tempus. Praesent ac mauris eleifend, luctus ligula vel, interdum lectus. Donec iaculis in est non iaculis. Nullam vulputate, lorem quis placerat condimentum, risus lectus feugiat neque, id auctor augue elit ut enim. Donec vel rutrum massa. Nunc laoreet nulla et eleifend facilisis. Morbi scelerisque velit [3] <span class="ref">[3] ChatGPT. </span> sit amet libero viverra mattis. Vivamus non porta neque, et rhoncus mi. In lectus nisl, faucibus nec sem sed, ullamcorper commodo ante. Aliquam ac massa imperdiet, viverra [4] <span class="ref">[4] Stack Overflow. </span> lacus eget, convallis ex. Phasellus tempus lacinia enim id tincidunt.Aenean cursus vestibulum libero, eu vulputate nisi efficitur sit amet. Praesent quis metus ac leo eleifend tempus. Praesent ac mauris eleifend, luctus ligula vel, [5] <span class="ref">[5] Bing. </span> interdum lectus. Donec iaculis in est non iaculis. Nullam vulputate, lorem quis placerat condimentum, risus lectus feugiat neque, id auctor augue elit ut enim. Donec vel rutrum massa. Nunc laoreet nulla et eleifend facilisis. Morbi scelerisque velit sit amet libero viverra mattis. Vivamus non porta neque, et rhoncus mi. In lectus nisl, faucibus nec sem sed, ullamcorper commodo ante. Aliquam ac massa imperdiet, viverra lacus eget, convallis ex. Phasellus tempus lacinia enim id tincidunt.</p>
        </section>
    </article>
</main>
</body>
</html>
Kerry7777
  • 4,246
  • 1
  • 18
  • 28
  • Good attempt, but using flexbox or grid for the `p` in narrow viewports creates "awkward line breaks" as the OP stated due to each instance of text string and `span` being treated as separate boxes. On wider viewports, multiple references on the same line will be positioned on top of each other. As for hiding the overflow, I suppose it could be made visible and more legible (with background declarations) on hover. – Tim R Jun 15 '23 at 03:02
  • Thanks, I don't think there is a way to achieve the desired layout (no line breaks) with the current HTML markup and CSS. On wider viewports multiple span references should still be on separate lines as they are set to display:block. You could possibly do 'titles' (tooltip) on anchor tags to references if truncated. – Kerry7777 Jun 15 '23 at 05:14
  • 1
    Indeed, I don't think the OP's desire is currently possible with the imposed restrictions but I'm curious to see if anybody comes up with something. I confirmed the absolute positioning overlap in Developer Tools simply by deleting text so that two wound up on the same line. Being 'block' doesn't change the absolute positioning. – Tim R Jun 15 '23 at 05:20
  • Made me laugh when I got down voted for answering this edge case situation here @SO with my previous answer, haha. This new answer works where browsers (FireFox) support new CSS selector :has. – Kerry7777 Jun 18 '23 at 04:20
  • I think this is a brilliant solution to this request. Smart use of `nth-of-type()` and `calc()` for positioning so they don't overlay when moved to the side, and using `:has()` to create space when positioned at the bottom. Especially if you already had a downvote, I think you should have created a new answer since I believe that you changed your answer enough to be a different solution (but I'm still new here so maybe I'm mistaken.) – Tim R Jun 19 '23 at 04:25
  • Cool Tim R. This question was tricky and made me think. Likely to need some minor tweaks with different font-size units. I went to add a new answer by clicking the 'Add Another Answer' button and the interface prompted me to adjust/update the initial (down voted) answer. I'm still learning here as well. Thanks for keeping it real and pointing out the shortcomings of the original answer. Cheers mate. @Jonathan Wheeler can you please pay the bounty money $$$ (expires tomorrow)? I think this is the closest answer so far. – Kerry7777 Jun 19 '23 at 23:32
  • @Kerry7777 I am **so** sorry! I saw your original answer and thought "hmm... I already thought of that, and it didn't quite do the trick." I saw some notification activity in my email, but I was scanning for new answers and not reading comments. You deserve the full bounty, but I only saw this after the bounty expired :( :( :(. I upvoted your answer and marked it as the accepted answer. – Jonathan Wheeler Aug 20 '23 at 14:27
  • @Jonathan Wheeler No problem mate, thanks for your message, haha. Yeah I understand your situation and moving on with other life issues fast. The bounty would have been nice but that wasn't the main motivating factor. SO is a great place to test your skills and help the community members. I hope you found a solution to your webpage dilemma. Thanks again, – Kerry7777 Aug 21 '23 at 07:03
0

I suggest placing the links at the bottom of the paragraph on the desktop version, and on mobile they will be where you need them. Also, don't forget about accessibility. Something like this:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-width: 320px;
}

:root{
  --gap: 20px;
  --line-height: 1.33;
}

main {
  margin: 0 auto;
  padding: var(--gap);
  max-width: 800px;
  line-height: var(--line-height);
}

article,
section {
  display: flex;
  flex-direction: column;
  row-gap: var(--gap);
}

h1 {
  text-align: center;
}

h2 {
  border-top: 1px solid gray;
  padding: var(--gap) 0;
}

@media (min-width: 768px) {
  p{
    position: relative;
    padding-left: 33.333%;
  }
}


.refs {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding-top: calc(var(--gap) / 2);
  margin-top: calc(var(--gap) / 2);
  border-top: solid 1px;
  color: #666;
  font-size: 14px;
}

@media (min-width: 768px){
  .refs{
    position: absolute;
    width: calc(33.333% - var(--gap));
    left: 0;
    bottom: 0;
    max-height: 100%;
    overflow-y: auto;
    margin: 0;
    border: 0;
    padding: 0;
  }
}

.ref {
  display: flex;
  flex: none;
  max-width: 100%;
}

.ref a {
  height: calc(var(--line-height) - 4px);
  line-height: var(--line-height);
  color: inherit;
  margin: 2px;
}

.ref a:first-child {
  flex: auto;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 1px;
  overflow: hidden;
}

.ref a:last-child {
  flex: none;
}

:target {
  background-color: yellow;
}
<main>
  <article>
    <h1>Document Title</h1>
    <section>
      <h2>First section of the document</h2>
      <p>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras fringilla porta est nec rhoncus. Vestibulum ultricies molestie ante, vel fringilla turpis tempor at. Maecenas eu leo justo. Aliquam scelerisque metus in massa
          hendrerit
          <a id="content-ref-1" href="#ref-1" aria-label="link to hendrerit description">[1]</a>,
        non condimentum augue pharetra. Etiam in lorem eu nibh
          sagittis
          <a id="content-ref-2" href="#ref-2" aria-label="link to sagittis description">[2]</a>
        lacinia sit amet eu odio. Quisque ultricies lacinia dignissim. Suspendisse blandit urna justo, et blandit metus tincidunt at. Quisque vel varius enim.
        <span class="refs">
          <span class="ref" id="ref-1">
            <a href="#" title="[1] Wikipedia.">[1] Wikipedia.</a>
            <a href="#content-ref-1" aria-label="back to content" title="back to content">&#8617;</a>
          </span>
          <span class="ref" id="ref-2">
            <a href="#" title="[2] A fancy textbook A fancy textbook fancy textbook A fancy textbook A fancy textbook">[2] A fancy textbook A fancy textbook fancy textbook A fancy textbook A fancy textbook</a>
            <a href="#content-ref-2" aria-label="back to content" title="back to content">&#8617;</a>
          </span>
        </span>
      </p>
      <p>
        Aenean cursus vestibulum libero, eu vulputate nisi efficitur sit amet. Praesent quis metus ac leo eleifend tempus. Praesent ac mauris eleifend, luctus ligula vel, interdum lectus. Donec iaculis in est non iaculis. Nullam vulputate, lorem quis placerat condimentum, risus lectus feugiat neque, id auctor augue elit ut enim. Donec vel rutrum massa. Nunc laoreet nulla et eleifend facilisis. Morbi scelerisque velit sit amet libero viverra mattis. Vivamus non porta neque, et rhoncus mi. In lectus nisl, faucibus nec sem sed, ullamcorper commodo ante. Aliquam ac massa imperdiet, viverra lacus eget, convallis ex. Phasellus tempus lacinia enim id tincidunt.
      </p>
    </section>
    <section>
      <h2>A second section</h2>
    </section>
  </article>
</main>
imhvost
  • 4,750
  • 2
  • 8
  • 10
  • This is a good solution for traditional methods but doesn't stick to the OP's question of how to position the inline element that is presented at the reference point (instead of at another place in the document as in this example.) – Tim R Jun 18 '23 at 01:13
  • 1
    The OP states: immediately after the paragraph (or, perhaps, at the end of the
    ) This answer is great, it doesn't make sense to have the text in the same source order as provided in the question when the text is never even read in that position anyway.
    – Morgan Feeney Jun 20 '23 at 22:58