Javascript 使用GoogleCodePretify修饰代码的滚动条
我在我的博客中使用语法突出显示,这是在blogger上托管的。我的问题是,我看不到滚动条出现在预先格式化的代码块周围,即使代码太宽,无法在指定的宽度内显示。我正在用Javascript 使用GoogleCodePretify修饰代码的滚动条,javascript,scrollbar,pretty-print,Javascript,Scrollbar,Pretty Print,我在我的博客中使用语法突出显示,这是在blogger上托管的。我的问题是,我看不到滚动条出现在预先格式化的代码块周围,即使代码太宽,无法在指定的宽度内显示。我正在用 <pre class="prettyprint lang-java prettyprinted" style=""> <code>public class MyVeryVeryLongClassname extends MyBaseClassWithAnEvenLongerName implements An
<pre class="prettyprint lang-java prettyprinted" style=""> <code>public class MyVeryVeryLongClassname extends MyBaseClassWithAnEvenLongerName implements AnInterface, AnotherInterface, YetAnotherInterface { </code></pre>
在我的博客上,滚动条从来没有出现过,线条超出了帖子栏的右边缘(例如,看一看),这让它看起来非常难看。StackOverflow显示的相同内容如下:
public class MyVeryVeryLongClassname extends MyBaseClassWithAnEvenLongerName implements AnInterface, AnotherInterface, YetAnotherInterface {
我用Firebug来研究stackoverflow是如何做到这一点的,我无法发现与我现在所做的有什么不同。我正在链接到与SO使用的相同的JS文件(在他们自己的CDN上)。我也用同样的风格
那么,我需要做什么才能将滚动条添加到预格式化的代码块中呢?没关系,我找到了解决方案。我所需要做的就是将以下CSS属性添加到站点范围的CSS样式表中:
pre.prettyprint{
width: auto;
overflow: auto;
max-height: 600px
}
这介绍了滚动条。在我的, 但我使用以下CSS代码修复了它:
pre.prettyprint {
display: block;
overflow: auto;
width: auto;
/* max-height: 600px; */
white-space: pre;
word-wrap: normal;
padding: 10px;
}
我在上找到了代码。实际上我真的不知道有什么区别,我在github上找到了这个css。