Is there a way to apply border-radius to an element with a scrollbar?

https://i.sstatic.net/aJsL8.png

I attempted the following approach:

element::-webkit-scrollbar-corner {
    border-bottom-right-radius: 20px !important;
}

however, it did not yield the desired result.

Answer №1

An alternative approach is to enclose the scroll-view within a view and apply a border-radius to the outer view as shown below.

<div class="view">
  <div class="scroll-view">
    Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nulla sed
    commodi pariatur minima cumque autem, tenetur sit sapiente natus
    facilis. Consequatur reiciendis omnis voluptates earum obcaecati quia
    alias nulla fugiat! Lorem ipsum dolor sit, amet consectetur adipisicing
    elit. Nulla sed commodi pariatur minima cumque autem, tenetur sit
    sapiente natus facilis. Consequatur reiciendis omnis voluptates earum
    obcaecati quia alias nulla fugiat! Lorem ipsum dolor sit, amet
    consectetur adipisicing elit. Nulla sed commodi pariatur minima cumque
    autem, tenetur sit sapiente natus facilis. Consequatur reiciendis omnis
    voluptates earum obcaecati quia alias nulla fugiat! Lorem ipsum dolor
    sit, amet consectetur adipisicing elit. Nulla sed commodi pariatur
    minima cumque autem, tenetur sit sapiente natus facilis. Consequatur
    reiciendis omnis voluptates earum obcaecati quia alias nulla fugiat!
    Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nulla sed
    commodi pariatur minima cumque autem, tenetur sit sapiente natus
    facilis. Consequatur reiciendis omnis voluptates earum obcaecati quia
    alias nulla fugiat! Lorem ipsum dolor sit, amet consectetur adipisicing
    elit. Nulla sed commodi pariatur minima cumque autem, tenetur sit
    sapiente natus facilis. Consequatur reiciendis omnis voluptates earum
    obcaecati quia alias nulla fugiat!
  </div>
</div>
<style>
.view {
  height: 200px;
  width: 200px;
  border-radius: 20px;
  border: 1px solid red;
  padding: 10px;
}
.scroll-view {
  width: 100%;
  height: 100%;
  overflow-y: scroll;
}

.scroll-view::-webkit-scrollbar {
  width: 20px;
}
.scroll-view::-webkit-scrollbar-thumb {
  background-color: red;
  border: 4px solid transparent;
  border-radius: 20px;
  background-clip: padding-box;
}
  </style>
 

This modification would result in an appearance similar to this. screenshot of output

Answer №2

To create a simple solution for adding a scrollbar to an element, one option is to nest the element within another container and apply styles like "overflow: hidden" and "border-radius: 20px" to the outer container:

/* To enhance visibility */
body {
  background-color: #444;
}

/* Ensuring scrollbar appears within inner element */
.internal {
  height: 100%;
  overflow-y: scroll;
}

/* Styling outer container borders */
.wrapper {
  width: 200px;
  height: 100px;
  border-radius: 15px;
  overflow:hidden;
  background-color: #fff;
}
<div class="wrapper">
  <div class="internal">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed luctus quis sapien quis ultrices. Nullam et nibh in odio lacinia feugiat et et ipsum. Praesent condimentum consequat aliquam. Ut ac dignissim arcu, in pulvinar odio. Nunc posuere mi id orci tristique blandit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus non rutrum lorem. Aliquam non urna at nulla elementum tincidunt quis vitae erat. Suspendisse vel erat nunc. Nunc ac cursus urna. Nunc cursus vestibulum lectus vel mollis. Sed elementum eget felis ut facilisis. Vivamus at mattis felis.
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dynamic text input and selection menu with AJAX (PHP and JavaScript)

As a student who is new to Javascript and PHP, I am trying to create a login page for my website that can verify user input in the database using AJAX. For example, when a user enters their username and password, the system should automatically check if t ...

Child component being used within a parent component in VueJS

Currently, I am in the process of transforming an existing theme into reusable components. One of the components I have created is a button component structured as follows: <template> <a :href="link" class="button" :class="styling"><sl ...

The disappearance of IE7 floats is observed when their parent element is styled with position:relative

The issue I'm encountering in IE7 is related to the CSS properties position:relative;, float: right;, and float: left;. While this problem doesn't seem to occur in newer browsers, it's puzzling why position:relative; impacts the behavior of ...

The Angular Material Nav Sidebar is specifically designed to appear only when resizing the screen to

I am currently following a tutorial on setting up Angular Material Sidenav with a toolbar from this video (https://www.youtube.com/watch?v=Q6qhzG7mObU). However, I am encountering an issue where the layout only takes effect after resizing the page. I am no ...

Centering headings and form elements in Bootstrap

I have a bootstrap row with a heading and an input field. Here is my code: <div class="row mb-5"> <div class="col h1 text-white text-start text-center text-md-start text-lg-start">Welcome<input class="for ...

The hover animation is not functioning properly in Icomoon

I have implemented a menu with a CSS3 hover animation called toTopFromBottom. Now, I want to replace the Font Awesome icons with Icomoon icons and apply the same animation effect: HTML: <div id="top-bar" class="top-bar"> <div class="container" ...

Unexpected behavior observed with field alignment

I've been attempting to align the field in an Angular HTML page, but it's not working out as I expected. Here's how the HTML file looks: <div id="report-prj-search"> <div class="dx-fieldset flex-column"> <div class="fle ...

Calculating the total number of records in a MySQL database using PHP can be achieved by

I need help with counting all rows in a dataset and displaying the number as part of a small statistic later on. Currently, I'm facing an issue where my PHP code is not returning the correct number of rows. The HTML echo works fine when displaying te ...

How do I use CSS to organize data by row and column within a table?

I'm looking to format the table data in a column-row layout for mobile devices. Can anyone provide an example or guidance on how to achieve this? I've browsed through some discussions but haven't found a solution that works with tables. The ...

Struggling to superimpose my navigation bar onto the title page background

I'm currently learning HTML and CSS on my own while I am in university. My current project involves creating a one-page website, but I am having difficulty positioning the navigation bar over the title page. My goal is for the navigation bar to remai ...

Unable to find and load the specified css-font formats (svg, eot, woff, woff2, and ttf) using webpack

Looking to incorporate a unique font into my project: @font-face { font-family: 'bikeshop'; src: url('/src/styles/bikeFont/font/bikeshop.eot?37006833'); src: url('/src/styles/bikeFont/font/bikeshop.eot?37006833#iefix') ...

The $watch() function seems to be failing to properly refresh the $scope

Within my controller, I have a function $scope.remove() that triggers a request to the usercart, which then calls an API. The JSON response from the API includes an object with an array of cart items. Despite using an ng-repeat in the HTML to iterate thro ...

How can I position a vertically centered image to the left of a block paragraph using inline styles?

I am faced with the challenge of aligning a 100x100 vertically-centered image to the left of a text block that extends beyond its height. It is important that the text does not wrap underneath the image but stays in a single block on the right side. I must ...

Arranging information within the Ngb-Accordion

Welcome to the code snippet showcasing how to create an accordion in Angular: <ngb-accordion [closeOthers]="false" activeIds="0"> <ng-container class="card" *ngFor="let post of Posts"> <ngb-panel title="{{post.title}} - ...

How can text be extracted from BeautifulSoup without displaying the opening tag and before the <br> tag?

I have recently started learning Python and Beautiful Soup, and I've spent a significant amount of time trying to solve this particular issue. I am looking to extract three specific text elements from a <div> that does not have a class attribu ...

Issue with Angular 6: Jquery unable to detect element when using *ngIf directive

I'm currently developing an app using Angular 6, and I am facing an issue while trying to add a class using the jquery hover() method. In my navigation menu, I have 5 links, and although they all appear the same, 2 of them have an added *ngIf directiv ...

Creating a dynamic website with user-friendly editing capabilities

Having a good understanding of html5 and css3, I am currently exploring ways to create a website that enables visitors to edit content in real time for all other users to see. While aware of the contenteditable attribute, I have found that it does not reta ...

Adding a close button to an iframe in Angular: A step-by-step guide

I am struggling with an iframe that pops up when a button is clicked. However, the only way to close or collapse it is by clicking outside the window. I would like to have a close button in the top left corner of the popup so that users can easily close th ...

How to Create Indentation Without Adding a New Line in Handlebars Mustache Syntax?

Trying to format mustache code for readability, I encountered an issue: {{this.$.Name}} {{this.$.Name}} although the desired output is: namename Is it possible to achieve this format without losing indentation in the .hbs file? ...

Issue encountered when toggling flip switch in Jquery Mobile

I am trying to create a calculator for my app using Jquery Mobile, but I am facing an issue with the flip toggle switch. Here is my script: <script type="text/javascript"> function dosis() { $peso = $('#peso').get(0).value $dosis = ...