javascript - 使用 google-code-prettify 美化代码的滚动条

标签 javascript scrollbar pretty-print

我正在使用 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/

相关文章:

jquery - 延迟加载无法设置可滚动 : {virtual: true} in Kendo Grid

python - Pandas :无法导入名称邻接

javascript - 将 JSON "rows"与 "colums"合并到新对象中

javascript - 如何使用按钮更改文本颜色

javascript - 更改div的滚动条颜色

java - VSCode 中没有安装 'java' 文件的格式化程序

java - 通过使用 xml :message 在 xslt 中输出变量的完整 XML 进行调试

javascript - 使用 jQuery 模拟 4 向运动

javascript - HTML5 input type=number 应该只允许无符号整数

javascript - 如何使滚动条居中?