Style scrollbar
Author: s | 2025-04-24
In this section, we will explore the different ways of styling scrollbars as listed below: a) Styling a specific scrollbar. b) Styling the default scrollbar separately. c) Styling all scrollbars at once; a). Styling a specific scrollbar. Scrollbar style in wpf according to below image. 5. WPF Scrollbar over content. 1. WPF Scrollbar Style issue. 2. WPF, learning to style scrollbar. 22. WPF ScrollBar styles. 5. In WPF, how to customize the style of ScrollBar in
Styling Scrollbars with CSS: The Modern Way to Style Scrollbars
The web page UI design with custom scrollbar adds an extra value to your website. Custom scrollbars make the website feel and look different. The browser’s scrollbar can be customized using CSS. Using CSS pseudo-element, you can easily change the default scrollbar style with your custom style. In this tutorial, we will show how you can make custom scrollbar and customize the look of the browser’s scrollbar with Webkit (pseudo element).WebKit allows you to styling scrollbars with your custom CSS. If scrollbar pseudo-element is defined, WebKit turns off the built-in scrollbar style and use the style provided in CSS under ::-webkit-scrollbar element.Here we’ll provide short CSS code snippet to change the default scrollbar style and create a custom scrollbar with WebKit. We’ll use only 3 pseudo-element, webkit-scrollbar, webkit-scrollbar-track, and webkit-scrollbar-thumb in WebKit. Use the following CSS in your web page to make custom scrollbars.Custom Scrollbar Style 1:::-webkit-scrollbar { width: 12px;}::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); border-radius: 10px;}::-webkit-scrollbar-thumb { border-radius: 10px; -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);}Custom Scrollbar Style 2:::-webkit-scrollbar { width: 12px;}::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); border-radius: 10px;}::-webkit-scrollbar-thumb { border-radius: 10px; -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);}Custom Scrollbar Style 3:::-webkit-scrollbar{ width: 12px; background-color: #F5F5F5;}::-webkit-scrollbar-track{ -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); background-color: #F5F5F5;}::-webkit-scrollbar-thumb{ background-color: #F90; background-image: -webkit-linear-gradient(90deg,rgba(255, 255, 255, .2) 25%,transparent 25%,transparent 50%,rgba(255, 255, 255, .2) 50%,rgba(255, 255, 255, .2) 75%,transparent 75%,transparent)}Custom Scrollbar in DivYou can create custom scrollbar for div content with Webkit. The element class or id need to be specified in webkit-scrollbar, webkit-scrollbar-track, and webkit-scrollbar-thumb. The following code snippets makes custom scrollbar for a specific div using CSS.HTML Code:div class="content"> div>CSS Code:.content::-webkit-scrollbar { width: 12px;}.content::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); border-radius: 10px;}.content::-webkit-scrollbar-thumb { border-radius: 10px; -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);}Scrollbar Selectors (Pseudo Elements)The following pseudo elements are available for customizing the browser’s scrollbar.::-webkit-scrollbar – Select the scrollbar.::-webkit-scrollbar-button – Select the buttons on the scrollbar.::-webkit-scrollbar-thumb – Select the draggable scrolling handle.::-webkit-scrollbar-track – Select the progress bar of the scrollbar.::-webkit-scrollbar-track-piece – Select the progress bar without handle.::-webkit-scrollbar-corner – Select the bottom corner of the scrollbar.::-webkit-resizer – Select the draggable resizing handle.ConclusionIn our example code snippet, only some basic styles are provided for the custom scrollbar. You can change the custom scrollbars style based on your web page UI. To customize the scrollbar, specify the CSS with ::-webkit-scrollbar, ::-webkit-scrollbar-track, and ::-webkit-scrollbar-thumb pseudo elements. CSSScrollbarWebkit Do you want to get implementation help, or enhance 0 0 L 4 4 L 8 0 Z"/> /Grid> /ControlTemplate> !– HorizontalScrollBar Template using the previously created Templates –> ControlTemplate x:Key="HorizontalScrollBar" TargetType="{x:Type ScrollBar}"> Grid > Grid.ColumnDefinitions> ColumnDefinition MaxWidth="18″/> 0.00001*"/> ColumnDefinition MaxWidth="18″/> 3″ CornerRadius="2″ Background="#F0F0F0″ /> RepeatButton Grid.Column="0″ Style="{StaticResource ScrollBarLineButton}" Width="18″ Command="ScrollBar.LineLeftCommand" Content="M 4 0 L 4 8 L 0 4 Z" /> Track Name="PART_Track" Grid.Column="1″ IsDirectionReversed="False"> Track.DecreaseRepeatButton> RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageLeftCommand" /> /Track.DecreaseRepeatButton> Track.Thumb> Thumb Style="{StaticResource ScrollBarThumb}" Margin="0,1,0,1″ Background="{StaticResource NormalBrush}" BorderBrush="{StaticResource NormalBorderBrush}" /> /Track.Thumb> Track.IncreaseRepeatButton> RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageRightCommand" /> /Track.IncreaseRepeatButton> /Track> RepeatButton Grid.Column="3″ Style="{StaticResource ScrollBarLineButton}" Width="18″ Command="ScrollBar.LineRightCommand" Content="M 0 0 L 4 4 L 0 8 Z"/> /Grid> /ControlTemplate> !– Style for overall ScrollBar –> Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}"> Setter Property="SnapsToDevicePixels" Value="True"/> Setter Property="OverridesDefaultStyle" Value="true"/> Style.Triggers> Trigger Property="Orientation" Value="Horizontal"> Setter Property="Width" Value="Auto"/> Setter Property="Height" Value="18″ /> Template" Value="{StaticResource HorizontalScrollBar}" /> /Trigger> Trigger Property="Orientation" Value="Vertical"> Setter Property="Width" Value="18″/> Height" Value="Auto" /> Setter Property="Template" Value="{StaticResource VerticalScrollBar}" /> /Trigger> /Style.Triggers> /Style> !– Style for overall ScrollViewer –> Style x:Key="FavsScrollViewer" TargetType="{x:Type ScrollViewer}"> Setter Property="OverridesDefaultStyle" Value="True"/> Setter Property="Template"> Setter.Value> ControlTemplate TargetType="{x:Type ScrollViewer}"> Grid> Grid.ColumnDefinitions> ColumnDefinition Width="Auto"/> ColumnDefinition/> /Grid.ColumnDefinitions> Grid.RowDefinitions> RowDefinition/> RowDefinition Height="Auto"/> /Grid.RowDefinitions> ScrollContentPresenter Grid.Column="1″/> PART_VerticalScrollBar" Value="{TemplateBinding VerticalOffset}" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/> ScrollBar Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Row="1″ Grid.Column="1″ Value="{TemplateBinding HorizontalOffset}" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/> /Grid> /ControlTemplate> /Setter.Value> /Setter> /Style> /Window.Resources> Grid x:Name="LayoutRoot"> ScrollViewer RenderTransformOrigin="0.5,0.5″ HorizontalAlignment="Stretch" Margin="0,0,0,0″ Width="Auto" HorizontalScrollBarVisibility="Visible" Style="{StaticResource FavsScrollViewer}"> /ScrollViewer> /Grid>/Window>And if you want to try this for yourself, here is a VS 2008 demo project.Scrollbar styling: scrollbar-color - CodePen
Not every page on my blog, but this particular page has a custom scrollbar. Look at the scrollbar carefully. Yes, its different from a default scrollbar. Its a custom designed scrollbar. I'll show you how to create a cool responsive custom scrollbar using pure CSS. Scrollbars are very common. You will see it in a web page, in elements like or etc. If you want to add a scrollbar to an element like a , you’ll have to use the CSS overflow property. Scrollbars can be vertical (Y-axis) or horizontal (X-axis). Implementing a custom scrollbar to elements is the same. In this example, I’ll create vertical custom scrollbar on a , which is just 5px wide. .scroll { overflow-y: scroll; height: 130px; width: 300px; background-color: #fff; margin: 0 0 10px 0; } .scroll::-webkit-scrollbar { width:5px; } .scroll::-webkit-scrollbar-track { -webkit-box-shadow:inset 0 0 6px rgba(0,0,0,0.3); border-radius:5px; } .scroll::-webkit-scrollbar-thumb { border-radius:5px; -webkit-box-shadow: inset 0 0 6px red; } We often use the !important property in CSS to ignore rules or styles applied to an element and instead apply rules that has !important property. You can further override the !important rules using ... Try it Now, let me explain all the CSS pseudo-elements that I have used inside the tag. The ::-webkit-scrollbar is used to style an element’s scrollbar.• ::-webkit-scrollbar – Here I have specified the width of scroll bar, which is 5px. You can change the pixel according to your choice. • ::-webkit-scrollbar-track – In here I have assigned some values for the track. The track is where the scroll bar moves up and down. You can change the rgba() value to, let’s say, green and see how it looks. For example, rgba(255,10,0,0.5) Note: The rgba() function defines colours using red, blue, green and alpha. The alpha specifies opacity. • ::-webkit-scrollbar-thumb – Here. In this section, we will explore the different ways of styling scrollbars as listed below: a) Styling a specific scrollbar. b) Styling the default scrollbar separately. c) Styling all scrollbars at once; a). Styling a specific scrollbar.Scrollbar styling with ::-webkit-scrollbar stopped working in
Download VS 2008 demo projectA while ago, I was looking at the Infragistics WPF showcase, Tangerine and I was quite jealous about the scrollbars that they managed to use. I mean styling a Button is one thing, but the ScrollBar is made of lots of nasty different control parts, (Part_XXX elements). Incidentally, I wrote an article about Part_XXX elements in a WPF article over at CodeProject right here if you are interested.Anyways, to cut a long story short, I decided to try and have a go at Styling a bigger control such as ScrollViewer. And guess what I managed to do it. Hooray!This is what it looks like: My Styled ScrollViewer Original ScrollViewer This blog entry outlines the steps I went through.Step 1Look up and copy the original ScrollViewer and ScrollBar Templates from MSDN, for example: I pasted that code from MSDN into a Resources file in a WPF window.Step 2I examined the control parts required for the full ScrollViewer/Scrollbar controls. This was fairly ok actually as the MSDN default Styles and pretty easy to follow.From looking at the default styles, it became clear that I needed to look at the following Style/Templates if I wished to re-style a ScrollViewer, as all of these were used in the default Style for the ScrollViewer somewhere.Step 3I then decided which parts I want to swap out. I chose to swap out and proceeded to hack the default Style/Templates to achieve the look I was after.Anyway, the results ScrollViewer looks like the following image: RepeatButton Thumb ScrollBar ScrollViewer When you consider the following image, you can see why these are the Style/Templates that need to be altered.So basically after that, it's just a question of cutting code. So without further ado, here is the code:Window xmlns=" xmlns:x=" xmlns:mc=" x:Class="ScrollViewerTemplate.Window1″ x:Name="Window" Title="Window1″ Width="200″ Height="200″> /*hides vertical scrollbar*/}Code language: CSS (css)Bonus: Hide but still ScrollNow here’s a bonus tip if you want to just hide the scroll bars but not completely get rid of the functionality that the scrollbars provide you can use the following code on your website:HTML:h2>Bonus: Scroll but hide Scrollbarsh2> div class="bonusBox"> p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsum repellendus sapiente ex, placeat dolor ut!...p> div>Code language: HTML, XML (xml)CSS:/* Hide scrollbar for IE, Edge and Firefox */.bonusBox { height: 200px; width: 400px; border: 1px solid green; overflow-y: scroll; -ms-overflow-style: none; /* IE and Edge */ scrollbar-width: none; /* Firefox */}/* Hide scrollbar for Chrome, Safari and Opera */.bonusBox::-webkit-scrollbar { display: none;}Code language: CSS (css)ConclusionIn this tutorial, we learn how we can control the overflow of content on a website, and how we can disable scroll with CSS we also got a bonus tip on implementing the scroll functionality but also hiding the scroll bars.We used codedamn playgrounds in this tutorial and how can try it out yourself by forking this playground.I hope you liked reading this article! ?You can read more on the codedamn blogP.S: I have won many hackathons and worked on many projects. You can connect with me on LinkedIn to know about hackathon ideas, internship experiences, and Development tips.Force scrollbar to classic style when overlay scrollbars are
Highcharts.setOptions({ lang: { rangeSelectorZoom: '' }, chart: { backgroundColor: '#000000', zooming: { resetButton: { theme: { fill: '#f23644', stroke: 'none', style: { color: '#ffffff' }, r: 8, states: { hover: { style: { color: '#000000' } } } } } } }, title: { style: { color: '#b0abab', fontSize: '2em' } }, xAxis: { labels: { style: { color: '#b0abab' } } }, yAxis: { labels: { style: { color: '#b0abab' } } }, navigator: { series: { fillColor: { linearGradient: [0, 0, 0, 40], stops: [ [0, '#5c0d13'], [1, '#000000'] ] } }, xAxis: { labels: { style: { color: '#ffffff', opacity: 1, textOutline: '#000000' } } }, maskFill: 'rgba(181, 145, 143, 0.2)', handles: { backgroundColor: '#5f5959', borderRadius: '50%', width: 20, height: 20 } }, exporting: { buttons: { contextButton: { symbolStroke: '#d9d7d7', theme: { fill: '#000000', states: { hover: { fill: '#000000' }, select: { fill: '#f23644' } } } } } }, scrollbar: { barBackgroundColor: '#5f5959', trackBorderColor: '#5f5959' }, rangeSelector: { buttonTheme: { fill: 'none', stroke: 'none', 'stroke-width': 0, r: 8, style: { color: '#d9d7d7', fontWeight: 'bold', fontSize: '1em' }, states: { select: { fill: '#f96772', style: { color: '#000000' } }, hover: { fill: 'none', stroke: '#f96772', 'stroke-width': 1, style: { color: '#ffffff' } } } } }, plotOptions: { area: { threshold: null, color: '#f23644', fillColor: { linearGradient: [0, 0, 0, 450], stops: [ [0, '#5c0d13'], [1, '#000000'] ] } } }, tooltip: { backgroundColor: '#212020', style: { color: '#ffffff' } }});Highcharts.stockChart('container', { title: { text: 'BTCETH', align: 'left' }, xAxis: { tickLength: 0, lineWidth: 0, crosshair: { width: 1, color: '#616161', zIndex: 3 } }, scrollbar: { barBorderRadius: 4, height: 8, margin: 0, trackBorderRadius: 4 }, yAxis: { gridLineWidth: 0, offset: 30, accessibility: { description: 'price in Ethereum' } }, navigator: { enabled: false, xAxis: { gridLineWidth: 0 }, outlineWidth: 0, handles: { lineWidth: 0 } }, rangeSelector: { buttonPosition: { align: 'right' }, buttonSpacing: 10, inputEnabled: false, selected: 1 }, data: { csvURL: ' firstRowAsNames: false, startRow: 1 }, tooltip: { shape: 'rect', shadow: false, borderWidth: 0 }, series: [{ name: 'BTC-ETH Price', type: 'area', tooltip: { valueDecimals: 2, pointFormat: '{point.y}' } }]});Scrollbar styling with ::-webkit-scrollbar stopped working in chrome
Of a scrollbar if you want to draw any at all.Removing Cool Scroll BarsIf for some strange reason you want to turn off cool scrollbars, then simply call the UninitializeCoolSB API, passing the handle to the window. You do not need to call this function when your window is destroyed, as the cool scrollbars will automatically remove themselves in this instance.A Note About the Source CodeThis library is written entirely in the C language, and uses no other library other than the standard win32 API. In order to encapsulate the code, it was necessary to package all of the implementation code into a single file, with all functions given static linkage so they don't conflict with other functions in your projects. This is a drawback of using C. It would be better to split the source into separate files which deal with specific scrollbar functions - such as drawing code in one file, mouse code in another and so on. However, this would require the use of namespaces to encapsulate the library, and namespaces are only available in C++. I thought that reaching a wider audience was more important in this case, but feel free to use your C++ compiler instead.I should also take this opportunity to defend my use of C++ style comments in a C project. My reason: I find it tedious to use the C-style comments. Also, every C compiler for Windows that I tried accepts C++ comments with no problem. In fact, the new C99 standard allows the use of C++ style comments, but the project will compile fine on older compilers also. So there.IMPORTANTThere is a file called userdefs.h which can be used to include or exclude certain features of the cool scrollbar library. If you don't want support for inserted buttons, for example, then you can #undef the INCLUDE_BUTTONS definition, which will result in a smaller code size. There are many features which can be altered in this way, and they are all fully documented in this file.Why You Can't Customize a Standard Windows Control(Only relevant under Windows 95,98,ME)Someone is bound to complain that they can't add cool scrollbars to a tree-view control, or an edit control, so I'll explain why this isn't possible.Firstly, it is quite possible to custom-draw the scrollbars on a standard window. All you need to do is call InitializeCoolSB, after all. However, internally, the standard windows all make use of the standard scrollbar functions such as SetScrollInfo and SetScrollPos. This is a problem, because these functions cause a window's scrollbars to be re-drawn, and this redraw does not get performed via a WM_NCPAINT message. Whenever you resize a standard window, or scroll up and down in one, the standard scrollbar API will be called, and this will cause your nicely drawn custom scrollbars to be over-written. So, unless you have the source-code to a window or control, you cannot apply the cool scrollbar library to it, because you must call the CoolSB_xxx API functions to perform all scrolling operations. In this section, we will explore the different ways of styling scrollbars as listed below: a) Styling a specific scrollbar. b) Styling the default scrollbar separately. c) Styling all scrollbars at once; a). Styling a specific scrollbar.Download WordPress Custom Scrollbar – Style Your Scrollbars
Data-medium-file=" data-large-file=" src=" alt="Screenshot of a carousel containing an image of a cat with indicator buttons below showing 1 filled circle and 3 unfilled circles" srcset=" 481w, 150w, 300w" sizes="(max-width: 481px) 100vw, 481px">For this, we will need a little bit of JavaScript. We can use the scrollTo() API with {behavior: 'smooth'}, which tells the browser to smoothly scroll to a given offset:function scrollToItem(itemPosition, numItems, scroller) { scroller.scrollTo({ scrollLeft: Math.floor( scroller.scrollWidth * (itemPosition / numItems) ), behavior: 'smooth' })}The only trick here is that Safari doesn’t support smooth scroll behavior and Edge doesn’t support scrollTo() at all. But we can detect support and fall back to a JavaScript implementation, such as this one.Here is my technique for detecting native smooth scrolling:function testSupportsSmoothScroll () { var supports = false try { var div = document.createElement('div') div.scrollTo({ top: 0, get behavior () { supports = true return 'smooth' } }) } catch (err) {} return supports}Being careful to set aria-labels and aria-pressed states for the buttons, and adding a debounced scroll listener to update the pressed state as the user scrolls, we end up with something like this:View in full modeYou can also add generic “go left” and “go right” buttons; the principle is the same.Hiding the scrollbar (optional)Now, the next piece of the puzzle is that most carousels don’t have a scrollbar, and depending on the browser and OS, you might not like how the scrollbar appears.Also, our carousel already includes all the buttons needed to scroll left and right, so it effectively has its own scrollbar. So we can consider removing the native one.To accomplish this, we can start with overflow-x: auto rather than overflow-x: scroll, which ensures that at least if there’s only one image (and thus no possibility of scrolling left or right), the scrollbar doesn’t show.Beyond that, we may be tempted to add overflow-x: hidden, but this actually makes the list entirely unscrollable. Bummer.So we can use a little hack instead. Here is some CSS to remove the scrollbar, which works in Chrome, Edge, Firefox, and Safari:.scroll { scrollbar-width: none; -ms-overflow-style: none;}.scroll::-webkit-scrollbar { display: none;}And it works! TheComments
The web page UI design with custom scrollbar adds an extra value to your website. Custom scrollbars make the website feel and look different. The browser’s scrollbar can be customized using CSS. Using CSS pseudo-element, you can easily change the default scrollbar style with your custom style. In this tutorial, we will show how you can make custom scrollbar and customize the look of the browser’s scrollbar with Webkit (pseudo element).WebKit allows you to styling scrollbars with your custom CSS. If scrollbar pseudo-element is defined, WebKit turns off the built-in scrollbar style and use the style provided in CSS under ::-webkit-scrollbar element.Here we’ll provide short CSS code snippet to change the default scrollbar style and create a custom scrollbar with WebKit. We’ll use only 3 pseudo-element, webkit-scrollbar, webkit-scrollbar-track, and webkit-scrollbar-thumb in WebKit. Use the following CSS in your web page to make custom scrollbars.Custom Scrollbar Style 1:::-webkit-scrollbar { width: 12px;}::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); border-radius: 10px;}::-webkit-scrollbar-thumb { border-radius: 10px; -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);}Custom Scrollbar Style 2:::-webkit-scrollbar { width: 12px;}::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); border-radius: 10px;}::-webkit-scrollbar-thumb { border-radius: 10px; -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);}Custom Scrollbar Style 3:::-webkit-scrollbar{ width: 12px; background-color: #F5F5F5;}::-webkit-scrollbar-track{ -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); background-color: #F5F5F5;}::-webkit-scrollbar-thumb{ background-color: #F90; background-image: -webkit-linear-gradient(90deg,rgba(255, 255, 255, .2) 25%,transparent 25%,transparent 50%,rgba(255, 255, 255, .2) 50%,rgba(255, 255, 255, .2) 75%,transparent 75%,transparent)}Custom Scrollbar in DivYou can create custom scrollbar for div content with Webkit. The element class or id need to be specified in webkit-scrollbar, webkit-scrollbar-track, and webkit-scrollbar-thumb. The following code snippets makes custom scrollbar for a specific div using CSS.HTML Code:div class="content"> div>CSS Code:.content::-webkit-scrollbar { width: 12px;}.content::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); border-radius: 10px;}.content::-webkit-scrollbar-thumb { border-radius: 10px; -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);}Scrollbar Selectors (Pseudo Elements)The following pseudo elements are available for customizing the browser’s scrollbar.::-webkit-scrollbar – Select the scrollbar.::-webkit-scrollbar-button – Select the buttons on the scrollbar.::-webkit-scrollbar-thumb – Select the draggable scrolling handle.::-webkit-scrollbar-track – Select the progress bar of the scrollbar.::-webkit-scrollbar-track-piece – Select the progress bar without handle.::-webkit-scrollbar-corner – Select the bottom corner of the scrollbar.::-webkit-resizer – Select the draggable resizing handle.ConclusionIn our example code snippet, only some basic styles are provided for the custom scrollbar. You can change the custom scrollbars style based on your web page UI. To customize the scrollbar, specify the CSS with ::-webkit-scrollbar, ::-webkit-scrollbar-track, and ::-webkit-scrollbar-thumb pseudo elements. CSSScrollbarWebkit Do you want to get implementation help, or enhance
2025-04-020 0 L 4 4 L 8 0 Z"/> /Grid> /ControlTemplate> !– HorizontalScrollBar Template using the previously created Templates –> ControlTemplate x:Key="HorizontalScrollBar" TargetType="{x:Type ScrollBar}"> Grid > Grid.ColumnDefinitions> ColumnDefinition MaxWidth="18″/> 0.00001*"/> ColumnDefinition MaxWidth="18″/> 3″ CornerRadius="2″ Background="#F0F0F0″ /> RepeatButton Grid.Column="0″ Style="{StaticResource ScrollBarLineButton}" Width="18″ Command="ScrollBar.LineLeftCommand" Content="M 4 0 L 4 8 L 0 4 Z" /> Track Name="PART_Track" Grid.Column="1″ IsDirectionReversed="False"> Track.DecreaseRepeatButton> RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageLeftCommand" /> /Track.DecreaseRepeatButton> Track.Thumb> Thumb Style="{StaticResource ScrollBarThumb}" Margin="0,1,0,1″ Background="{StaticResource NormalBrush}" BorderBrush="{StaticResource NormalBorderBrush}" /> /Track.Thumb> Track.IncreaseRepeatButton> RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageRightCommand" /> /Track.IncreaseRepeatButton> /Track> RepeatButton Grid.Column="3″ Style="{StaticResource ScrollBarLineButton}" Width="18″ Command="ScrollBar.LineRightCommand" Content="M 0 0 L 4 4 L 0 8 Z"/> /Grid> /ControlTemplate> !– Style for overall ScrollBar –> Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}"> Setter Property="SnapsToDevicePixels" Value="True"/> Setter Property="OverridesDefaultStyle" Value="true"/> Style.Triggers> Trigger Property="Orientation" Value="Horizontal"> Setter Property="Width" Value="Auto"/> Setter Property="Height" Value="18″ /> Template" Value="{StaticResource HorizontalScrollBar}" /> /Trigger> Trigger Property="Orientation" Value="Vertical"> Setter Property="Width" Value="18″/> Height" Value="Auto" /> Setter Property="Template" Value="{StaticResource VerticalScrollBar}" /> /Trigger> /Style.Triggers> /Style> !– Style for overall ScrollViewer –> Style x:Key="FavsScrollViewer" TargetType="{x:Type ScrollViewer}"> Setter Property="OverridesDefaultStyle" Value="True"/> Setter Property="Template"> Setter.Value> ControlTemplate TargetType="{x:Type ScrollViewer}"> Grid> Grid.ColumnDefinitions> ColumnDefinition Width="Auto"/> ColumnDefinition/> /Grid.ColumnDefinitions> Grid.RowDefinitions> RowDefinition/> RowDefinition Height="Auto"/> /Grid.RowDefinitions> ScrollContentPresenter Grid.Column="1″/> PART_VerticalScrollBar" Value="{TemplateBinding VerticalOffset}" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/> ScrollBar Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Row="1″ Grid.Column="1″ Value="{TemplateBinding HorizontalOffset}" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/> /Grid> /ControlTemplate> /Setter.Value> /Setter> /Style> /Window.Resources> Grid x:Name="LayoutRoot"> ScrollViewer RenderTransformOrigin="0.5,0.5″ HorizontalAlignment="Stretch" Margin="0,0,0,0″ Width="Auto" HorizontalScrollBarVisibility="Visible" Style="{StaticResource FavsScrollViewer}"> /ScrollViewer> /Grid>/Window>And if you want to try this for yourself, here is a VS 2008 demo project.
2025-04-10Not every page on my blog, but this particular page has a custom scrollbar. Look at the scrollbar carefully. Yes, its different from a default scrollbar. Its a custom designed scrollbar. I'll show you how to create a cool responsive custom scrollbar using pure CSS. Scrollbars are very common. You will see it in a web page, in elements like or etc. If you want to add a scrollbar to an element like a , you’ll have to use the CSS overflow property. Scrollbars can be vertical (Y-axis) or horizontal (X-axis). Implementing a custom scrollbar to elements is the same. In this example, I’ll create vertical custom scrollbar on a , which is just 5px wide. .scroll { overflow-y: scroll; height: 130px; width: 300px; background-color: #fff; margin: 0 0 10px 0; } .scroll::-webkit-scrollbar { width:5px; } .scroll::-webkit-scrollbar-track { -webkit-box-shadow:inset 0 0 6px rgba(0,0,0,0.3); border-radius:5px; } .scroll::-webkit-scrollbar-thumb { border-radius:5px; -webkit-box-shadow: inset 0 0 6px red; } We often use the !important property in CSS to ignore rules or styles applied to an element and instead apply rules that has !important property. You can further override the !important rules using ... Try it Now, let me explain all the CSS pseudo-elements that I have used inside the tag. The ::-webkit-scrollbar is used to style an element’s scrollbar.• ::-webkit-scrollbar – Here I have specified the width of scroll bar, which is 5px. You can change the pixel according to your choice. • ::-webkit-scrollbar-track – In here I have assigned some values for the track. The track is where the scroll bar moves up and down. You can change the rgba() value to, let’s say, green and see how it looks. For example, rgba(255,10,0,0.5) Note: The rgba() function defines colours using red, blue, green and alpha. The alpha specifies opacity. • ::-webkit-scrollbar-thumb – Here
2025-04-21Download VS 2008 demo projectA while ago, I was looking at the Infragistics WPF showcase, Tangerine and I was quite jealous about the scrollbars that they managed to use. I mean styling a Button is one thing, but the ScrollBar is made of lots of nasty different control parts, (Part_XXX elements). Incidentally, I wrote an article about Part_XXX elements in a WPF article over at CodeProject right here if you are interested.Anyways, to cut a long story short, I decided to try and have a go at Styling a bigger control such as ScrollViewer. And guess what I managed to do it. Hooray!This is what it looks like: My Styled ScrollViewer Original ScrollViewer This blog entry outlines the steps I went through.Step 1Look up and copy the original ScrollViewer and ScrollBar Templates from MSDN, for example: I pasted that code from MSDN into a Resources file in a WPF window.Step 2I examined the control parts required for the full ScrollViewer/Scrollbar controls. This was fairly ok actually as the MSDN default Styles and pretty easy to follow.From looking at the default styles, it became clear that I needed to look at the following Style/Templates if I wished to re-style a ScrollViewer, as all of these were used in the default Style for the ScrollViewer somewhere.Step 3I then decided which parts I want to swap out. I chose to swap out and proceeded to hack the default Style/Templates to achieve the look I was after.Anyway, the results ScrollViewer looks like the following image: RepeatButton Thumb ScrollBar ScrollViewer When you consider the following image, you can see why these are the Style/Templates that need to be altered.So basically after that, it's just a question of cutting code. So without further ado, here is the code:Window xmlns=" xmlns:x=" xmlns:mc=" x:Class="ScrollViewerTemplate.Window1″ x:Name="Window" Title="Window1″ Width="200″ Height="200″>
2025-04-12/*hides vertical scrollbar*/}Code language: CSS (css)Bonus: Hide but still ScrollNow here’s a bonus tip if you want to just hide the scroll bars but not completely get rid of the functionality that the scrollbars provide you can use the following code on your website:HTML:h2>Bonus: Scroll but hide Scrollbarsh2> div class="bonusBox"> p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsum repellendus sapiente ex, placeat dolor ut!...p> div>Code language: HTML, XML (xml)CSS:/* Hide scrollbar for IE, Edge and Firefox */.bonusBox { height: 200px; width: 400px; border: 1px solid green; overflow-y: scroll; -ms-overflow-style: none; /* IE and Edge */ scrollbar-width: none; /* Firefox */}/* Hide scrollbar for Chrome, Safari and Opera */.bonusBox::-webkit-scrollbar { display: none;}Code language: CSS (css)ConclusionIn this tutorial, we learn how we can control the overflow of content on a website, and how we can disable scroll with CSS we also got a bonus tip on implementing the scroll functionality but also hiding the scroll bars.We used codedamn playgrounds in this tutorial and how can try it out yourself by forking this playground.I hope you liked reading this article! ?You can read more on the codedamn blogP.S: I have won many hackathons and worked on many projects. You can connect with me on LinkedIn to know about hackathon ideas, internship experiences, and Development tips.
2025-04-22