【问题标题】:CSS - make Doxygen line numbers unselectableCSS - 使 Doxygen 行号无法选择
【发布时间】:2014-04-27 06:48:40
【问题描述】:

我正在制作一个自定义样式表以添加到 doxygen 输出文件,其目的是使网站元素不可选择,因此只有有用的代码/文本是可选择的。下面是删除行号的 CSS 规则示例。尽管似乎选择了正确的类,但使用全选或用鼠标拖动然后复制/粘贴到文本编辑器中仍然会复制行号。为什么会这样?另外,如何预防?

http://jsfiddle.net/b5cU2/1/

<div class="fragment"><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;{</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;    <a class="code" href="class_talon.html#a139bb330021efa545fd6047fa291dbeb">Set</a>(output);</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;}</div>
<div class="ttc" id="class_talon_html_a139bb330021efa545fd6047fa291dbeb"><div class="ttname"><a href="class_talon.html#a139bb330021efa545fd6047fa291dbeb">Talon::Set</a></div><div class="ttdeci">virtual void Set(float value, uint8_t syncGroup=0)</div><div class="ttdef"><b>Definition:</b> <a href="_talon_8cpp_source.html#l00070">Talon.cpp:70</a></div></div>
</div>

<style>
.lineno {
    background-color: red !important;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
.line:not(.lineno) {
    background-color: blue;
    -webkit-touch-callout: text !important;
    -webkit-user-select: text !important;
    -khtml-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
}
</style>

【问题讨论】:

  • 是 jQuery 的一个选项吗?我认为问题是您需要将这些 css 规则从 .lineno 添加到外部父级,还可以在此处找到更多信息:stackoverflow.com/questions/826782/…
  • “最简单”的方法是重新格式化代码,使行号和行内容位于不同的容器中。
  • 我可以选择.lineno的父母,但那有什么用呢?
  • 关于行号,我建议您使用 CSS 计数器来生成它们,这样它们就永远无法选择。这是example。它有很棒的browser support
  • 它们不是从0开始计数的,行号代表代码在源代码中的位置,所以它们不能用计数器动态生成

标签: css selection doxygen


【解决方案1】:

这是关于浏览器如何解释它的。 Firefox 做你想做的事,匹配的选择器不能被复制。如果您选择文本周围的元素,WebKit 允许复制文本。

您总是可以使用其他结构。赞this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-03
    • 1970-01-01
    • 2021-11-20
    • 2014-02-19
    • 2020-06-25
    • 2014-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多