首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在HTML/CSS中实现“命名定理”环境

在HTML/CSS中实现“命名定理”环境
EN

Stack Overflow用户
提问于 2019-03-13 22:36:16
回答 1查看 396关注 0票数 1

在数学文档中,您经常会看到历史上重要的定理或命名的定理,这些定理与文档中的其他定理不同。

现在我已经实现了编号定理:

代码语言:javascript
复制
body {
  counter-reset: theorem;
}
p.theorem {
  display: block; 
}
p.theorem::before {
  counter-increment: theorem; 
  content: "Theorem " counter(theorem) " \2014 "; 
}

因此,几乎可以用以下方法创建上面的内容:

代码语言:javascript
复制
<p class="theorem">
  This is your typical theorem, probably proved by the author of 
  the current paper, and doesn't need any special decoration.
</p> 
<p class="theorem">
  This theorem is important enough to warrant attribution to its author and a 
  reference to the entry in the bibliography where the author proves this theorem.
</p> 

但是,如何在网页上实现定理的命名/归属呢?天真地,我们必须将一些参数,name,传递到用于定理的标记,但我认为这在HTML/CSS中是不可能的。如果这是可能的话,如果name也有可能是一个超链接,链接到引用的工作,那就太好了。

还请参阅有关referencing theorems like you can do with LaTeX的相关问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-13 23:25:47

可以在CSS content属性中使用attr()引用元素属性的内容。

代码语言:javascript
复制
body {
  counter-reset: theorem;
}
p.theorem::before {
  counter-increment: theorem; 
  content: "Theorem " counter(theorem) " \2014 "; 
}
p.theorem[data-attribution]::before {
  content: "Theorem " counter(theorem) " (" attr(data-attribution) ")  \2014 ";
}
代码语言:javascript
复制
<p class="theorem">This is your typical theorem, probably proved by the author of the current paper, and doesn't need any special decoration.</p>
<p class="theorem" data-attribution="Noether">This theorem is important enough to warrant attribution to its author and a reference to the entry in the bibliography where the author proves this theorem.</p>

下面是一篇很好的文章:https://davidwalsh.name/css-content-attr

但是,如果不在混合中添加一些javascript,就无法使它成为一个可访问的链接。在这一点上,可能值得使用语义HTML来标记获取的内容--这肯定会更容易访问--使用如下模式:

代码语言:javascript
复制
.theorem {
    margin: 0 0 1em 0;
}
.theorem figcaption::after {
    content: " \2014 "
}
.theorem figcaption,
.theorem p {
    display: inline;
}
代码语言:javascript
复制
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<figure class="theorem">
    <figcaption>Theorem 1</figcaption>
    <p>This is your typical theorem, probably proved by the author of the current paper, and doesn't need any special decoration.</p>
</figure>
<figure class="theorem">
    <figcaption>Theorem 2 (Noether [<a href="#">1</a>])</figcaption>
    <p>This theorem is important enough to warrant attribution to its author and a reference to the entry in the bibliography where the author proves this theorem.</p>
</figure>

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55152190

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档