Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can you automatically number cross-references in HTML+CSS, without JavaScript?
    primarykey
    data
    text
    <p>The usual method for creating cross-references in LaTeX is to put a <code>\label</code> inside something you want to refer to later, and then use <code>\ref</code>. So for example, writing <code>as we saw in Section~\ref{intro}</code> in the LaTeX source might produce "as we saw in Section 1" in the final output. Is it possible to get the same effect using just HTML and CSS? Newer features of CSS allow sections and so on to be numbered automatically, but I haven't found anything that lets you reference these counter values from elsewhere in the document.</p> <p>Here is a concrete example:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Cross references&lt;/title&gt; &lt;meta charset="utf-8"&gt; &lt;style type="text/css"&gt; body { counter-reset: section; } section &gt; h1::before { counter-increment: section; content: counter(section) ". "; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;section&gt; &lt;h1 id="intro"&gt;Introduction&lt;/h1&gt; &lt;p&gt;Pineapples contain essential vitamins.&lt;/p&gt; &lt;/section&gt; &lt;section&gt; &lt;h1&gt;Further discourse on pineapples&lt;/h1&gt; &lt;p&gt;As we saw in Section ??, pineapples contain essential vitamins.&lt;/p&gt; &lt;/section&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>In this example, all the section headings are prepended with an automatically generated number. I would like to know if there is any HTML markup or CSS styling I could use in place of <code>??</code> that will insert the number corresponding to <code>#intro</code>.</p> <p>I realize I could use <code>&lt;a href="#intro"&gt;</code> to create a cross-hyperlink to the Introduction, but I'd like to include the section number in the link text as well.</p> <p>If this is not possible with HTML and CSS alone, are there any JavaScript libraries for adding cross-references within a document?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload