The Html div with cursor resize and scroll auto:
.scrollable {
cursor: ew-resize;
border-color: red;
height: 200px;
max-height: 150px;
overflow: scroll;
}
<div class="scrollable">
<h1>My First CSS Example</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</div>
The div is displaying the cursor with resize option. But when the scroll bar is visible, the resize cursor is showing inside the scroll bar. How to show the resize cursor outside border of vertical scroll bar.
I have tried using with no luck:
.scrollable {
cursor: ew-resize;
}
5
Answers
Unfortunately, it’s not possible to display the resize cursor outside the border of the vertical scroll bar as it is determined by the browser’s default behavior. You can try changing the border color to transparent or a color that matches the background to make it less noticeable, but the cursor will still be displayed within the scrollbar.
Consider the following changes.
This is really only needed for Chrome yet does work for other browsers.
The trick here is wrapping your content div and making it sort of a viewport. Now you can adjust the
width
so that when the User moves it over to the scrollbar, the cursor changes back before the very edge.The issue I saw was that when the cursor box was just a pixel before half, the graphic of the resize cursor still showed and appeared to bleed over onto the scrollbar. This is due to the border of the div element being right at the edge of the window. We can move that border by making the div a bit smaller, yet keeping the scrollbar in the same position, the cursor changes well beforehand and the graphic no longer looks like it bleeds over.
I guess, your problem is more OS or Browser related. I tried to reproduce this from iOS + Chrome and I didn’t succeed, everything works as expected for me.
However for webkit based browsers you can try:
I’m not sure if this is specifically what you’re asking for. I couldn’t tell if your goal was to allow the box to resize or not. If my understanding is correct, your goal is to allow resize, but you don’t want that to interfere with the scrollbar. Here is my best answer based on this:
I restructured the
HTML
style
attribute into separateCSS
. First of all, if you want to be able to resize using the right edge of the element, rather than using the built in resizeCSS
(with defaultCSS
, useresize: horizontal;
on the parent), then you will need to usJavaScript
.This also requires an additional element to represent the resize bar (
<div id="handle">
). This is where we apply thecursor: ew-resize;
. Make sure theposition
of the handle isabsolute
, and is placed slightly further right than the parent. It’s also important to note, the parent needs to have aposition
ofrelative
on it, so that the handle is contained to the parent.As an explanation of the
JavaScript
, we start by defining our element variables, and presetting thestartX
andstartWidth
variables to undefined, to be redefined later. Next we add an event listener to the handle, to handle the resizing onmousedown
. This will set thestartX
to theclientX
position of the handle. Then we set thestartWidth
based on the computed width of the parent, usingparseInt
to convert the string value to a number. Then we handle themousemove
andmouse
in order.On
mousemove
, we run theresize
function. This sets the width ofparent
to a pixel value based on thestartWidth
, mouse x position, and starting mouse x position.On
mouseup
we run thestopResize
function, which disables the event listeners formousemove
andmouseup
.Hopefully this is the answer you were looking for. Please let me know if you have any questions, or better explanation for what you were asking for specifically, so I can provide further insight.
Simply wrap your scrollable div with one that has
cursor: ew-resize;