我正在使用 google-code-prettify用于在我的博客中突出显示语法,该博客托管在 blogger 上。我的问题是我没有看到滚动条出现在我的预格式化代码块周围,即使代码太宽而无法适应指定的宽度。我正在用
格式化代码块<pre class="prettyprint lang-java prettyprinted" style=""> <code>public class MyVeryVeryLongClassname extends MyBaseClassWithAnEvenLongerName implements AnInterface, AnotherInterface, YetAnotherInterface { </code></pre>
在我的博客上,滚动条永远不会出现,并且线条超出了帖子栏的右边缘(例如,看看 this post ),使它看起来非常难看。 StackOverflow 将其显示为:
public class MyVeryVeryLongClassname extends MyBaseClassWithAnEvenLongerName implements AnInterface, AnotherInterface, YetAnotherInterface {
我使用 Firebug 来研究 stackoverflow 是如何做到这一点的,但我没有发现与我所做的有什么不同。我链接到与 SO(在他们自己的 CDN 上)使用的相同的 JS 文件。我也使用相同的样式。
那么,我需要做什么才能将滚动条添加到预先格式化的代码块中呢?
最佳答案
没关系,我找到了解决方案。我所需要做的就是将以下 CSS 属性添加到站点范围的 CSS 样式表中:
pre.prettyprint{
width: auto;
overflow: auto;
max-height: 600px
}
这介绍了滚动条。
关于javascript - 使用 google-code-prettify 美化代码的滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13946182/