Remove Vertical Scrollbars in SyntaxHighlighter

SyntaxHighlighter created by Alex Gorbatchev is a code syntax highlighter developed in JavaScript. It basically makes your code snippets beautiful.

Many a times even when not required, a vertical scroll gets added to your code as shown here:

syntax-highlighter-scroll

The scroll appears in some browsers (especially Chrome) as the default style set in shCoreDefault.css is overflow: auto. If you do not want a vertical scrollbar, you can always do this:


.syntaxhighlighter { 
overflow-y: hidden !important; 
}

The overflow-y property specifies what to do with the edges of the content if it overflows the element's content area. Setting this to hidden will make the vertical scrollbar disappear. You do not have to add a style for the horizontal scroll bar as it already exists in shCoreDefault.css.

If for some reason, the scroll does not disappear even after setting the overflow-y property then prefix the class with a container class. For eg: my code blocks are contained in a div with ‘code’ class. In this case, I can prefix the class as follows:

.code .syntaxhighlighter {
overflow-y: hidden !important;
}

and you will find that the vertical scrollbar now disappears.




About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: