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.

Will you give this article a +1 ? Thanks in advance


About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

No comments: