There is some CSS to put the asides on the side[3] (with a ton of variations to make it play nice on mobile). Then there's a bit of JS to correctly line them up with <span> markers[4]. It was a bit more effort than I expected, and I don't like having to rely on JS, but the output is really nice, I think.
For example, take a look at this chapter[5], and try resizing your browser window or hitting it on a mobile device.
[1]: http://gameprogrammingpatterns.com/
[2]: https://github.com/munificent/game-programming-patterns/blob...
[3]: https://github.com/munificent/game-programming-patterns/blob...
[4]: https://github.com/munificent/game-programming-patterns/blob...