Search code examples
htmlcssfloatingfootnotes

Bullet lists in sidenotes with HTML and CSS


I want to make a html document with sidenotes (margin notes). I found a solution to make a floating frame at the right side of the main text with a specific CSS class in a <span> flag. It works fine!

Now, I would like to include bullets lists in these side notes but then my bullet list appear in the main text and not in the sidenote. See below :

enter image description here

I also tried to display the span as a block but it didn't change anything. Here his my HTML code for this example:

body {
  margin-right: 400px
}

.sidenotes {
  float: right;
  clear: right;
  margin-top: 0;
  margin-bottom: 0;
  background: #558844;
  vertical-align: baseline;
  position: relative;
  border: solid black 1pt;
  width: 200px;
  display: block;
  margin-right: -250px;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent suscipit eros ut ullamcorper vestibulum.
  <span class="sidenotes" style="display:block;">aaaa aaa aaa aa aaa aaa aaaa
    aaa aaa aaa aa aaa aaa aa aa aa aaaa aaaaa aaa aaa </span> tempor, tempor tellus vel, feugiat tellus. Mauris facilisis eget felis ut mattis. Suspendisse nec .
  <p>
    <p>Donec accumsan,
      <span class="sidenotes" style="display:block;">bbbb b bb bbbb bbb bbb bbb bbb b
    <ul>
    <li><p >cccccc ccccccccc cccc</p></li>
    <li><p >ddd dddd ddd ddd ddd d</p></li>
    </ul></span> augue non pharetra imperdiet, nisi urna aliquam lorem, nec vulputate mi ipsum vel risus. Ut vel urna ut ipsum bibendum tempor ut id massa. Sed id ante risus. </p>

I tried using a <div> which give the correct result in the side note but not in the main text. The line is breaking at "Donec accumsan" (like the paragraph style):

<p style="font-style:italic;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent suscipit 
eros ut ullamcorper vestibulum.
<span class="sidenotes">aaaa aaa aaa aa aaa aaa aaaa
aaa aaa aaa aa aaa aaa aa aa aa aaaa aaaaa aaa aaa</span> 
tempor, tempor tellus vel, feugiat tellus. Mauris facilisis eget felis 
ut mattis. Suspendisse nec .<p>
<p style="font-style:italic;">Donec accumsan, 
  <div class="sidenotes" ><p>bbbb b bb bbbb bbb bbb bbb bbb b</p>
    <ul>
      <li><p >cccccc ccccccccc cccc</p></li>
      <li><p >ddd dddd ddd ddd ddd d</p></li>
    </ul>
  </div> augue non pharetra imperdiet, nisi urna aliquam lorem, 
nec vulputate mi ipsum vel risus. Ut vel urna ut ipsum bibendum tempor ut 
id massa. Sed id ante risus.  </p>

which give:

enter image description here

Do you have an idea how to modify my code to allow paragraphs, bullet lists and numbered lists in my sidenotes without breaking the line in the main text?

If not, is there another way to make side notes (margin notes)?


Solution

  • It doesn't really make sense to place your notes mid paragraph, let alone mid sentence. If you want to provide a semantic link between content in the paragraph and the side not, use and actual a link.

    As I mentioned in a comment, you can not use ul or div mid p tag as you may only use phrasing content in a p tag. Using any other block level element will cause the p tag to close. See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p

    I would go with placing the side notes after the paragraph they pertain to. Using the :target pseudo class we can add a high-lite to the appropriate footnote when the link is clicked

    .sidenotes  {float:right; clear:right; background-color:#CCFFCC; width: 200px;}
    .sidenotes:target{border:1px solid red;}
    <div class="sidenotes" id="sidenote-a">aaaa aaa aaa aa aaa aaa aaaa
    aaa aaa aaa aa aaa aaa aa aa aa aaaa aaaaa aaa aaa</div> 
    <p style="font-style:italic;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent suscipit 
    eros ut ullamcorper <a href="#sidenote-a">vestibulum</a>.
    
    tempor, tempor tellus vel, feugiat tellus. Mauris facilisis eget felis 
    ut mattis. Suspendisse nec .<p>
    
    
     <div class="sidenotes" id="sidenote-b" ><p>bbbb b bb bbbb bbb bbb bbb bbb b</p>
        <ul>
          <li><p >cccccc ccccccccc cccc</p></li>
          <li><p >ddd dddd ddd ddd ddd d</p></li>
        </ul>
      </div>
    <p style="font-style:italic;">Donec <a href="#sidenote-b">accumsan</a>, 
      augue non pharetra imperdiet, nisi urna aliquam lorem, 
    nec vulputate mi ipsum vel risus. Ut vel urna ut ipsum bibendum tempor ut 
    id massa. Sed id ante risus.  </p>