Customize cursor using CSS

I have a div with overflow: hidden that I am making scrollable by allowing the user to click and drag the background. There are links and buttons within this space.

Here is the CSS I am using for this:

#div-grabscroll {    
    cursor: url(../img/openhand.cur), move;
}
#div-grabscroll:active {
   cursor: url(../img/closedhand.cur), n-resize;
}

Although this solution is effective, I am encountering an issue where, while dragging, if the mouse moves over a button, the cursor changes to a pointer instead of remaining a closedhand as I want it to.

The behavior I desire is for the cursor to stay as a closedhand for the entire time the div is controlled by the mouse.

Is there a way to override the cursor without having to adjust the CSS for every element the mouse might interact with? I attempted using !important on the :active style, but this did not achieve the desired effect.

Answer №1

Question: If a duplicate div is placed on top of the grabscroll div without any background or content to avoid obscuring anything behind it, and then the cursor is set to hand, what would be the outcome?

Does the z-index override the importance in this scenario?

Does this concept sound logical?

In essence, the layered order would be grabscroll - button - solid grabscroll.

Answer №2

Dealing with the issue of creating "modal" dialog boxes is quite similar to the challenge at hand. One potential solution may involve utilizing an iframe placed above the scrolling content, ensuring it has a higher z-index order to prevent interference with form controls, especially on browsers like IE. This approach is commonly used in "lightbox" style solutions.

If you're interested, you can check out this answer I provided for a similar query on SO. It showcases the fundamentals of implementing an iframe shim, albeit in a modal context.

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

A loop variable in Javascript is a function that iterates

var x = 99; while (true) { function lyrics(person) { return x + " " + "lines of code in the file " + x + " " + person + (x-1) + " lines of code" + "!"; } console.log(lyrics("John strikes one out, clears it all out ;")); x -= 1; if (x ...

Modify the button's border color upon click action

I am looking to implement a feature where the border of a button changes when clicked once and reverts back when clicked again. This should apply individually to each of the 16 buttons with the same class. Additionally, I want to enable the ability to clic ...

Application crash imminent, alert: Uncaught TypeError detected - Unable to access property 'some' of undefined within React

My application has 3 sections. The first section consists of a form where users fill in details about watches, and the data is submitted using the submitHandler function. In the second part, users can enter watches from the first section. When a user click ...

Adjust the size of the div container while ensuring that all elements are aligned horizontally

My goal is to design a page where all elements remain perfectly aligned, even when the user resizes the window. However, the code I have written does not achieve this. <div style="display:flex; justify-content: left; padding: 3px;"> <div style="m ...

React Native images failing to render at the same time

I have created a React Native app that loads images simultaneously from Supabase storage using a custom hook. The goal is to display these images in a list using SwipeListView: const fetchImages = async (recipes) => { if (!recipes) { return; ...

Display a div using Jquery when hovering over it with several classes

I want to create a hover effect where div2 fades in slowly when hovering over div1 within the same container. However, my jQuery code doesn't seem to be working as expected... $(".div").hover(function() { $(this).find(".div2").animate({ opac ...

After the form is submitted, attach a div containing the saved record

Once the form is submitted, I'd like to seamlessly add the newly saved record to my existing div that holds all the records. If there's a better method for accomplishing this, please let me know. I'm unsure of the correct approach to achiev ...

Make sure to save your data prior to using req.session.destroy() in Express

Before destroying the session in the logout route, I need to save the session value "image location" into the database. Here is the solution I have implemented: app.get('/logout',function(req,res){ Person.update({ username: req.session.use ...

Having trouble getting XSLT to work properly with the XML file

My XSL file doesn't appear to be functioning properly with my XML data. Despite the simplicity of my code, I am unable to identify the issue. Upon linking to the XSL spreadsheet and opening the document, my XML seems to transform into plain raw Data. ...

Navigating intricate JSON information using AngularJS

I am working on displaying JSON data in an HTML form using ng-repeat. I have managed to retrieve data from some objects, but I am facing challenges due to the nested structure of objects like "Obj => Obj => Obj". In the JSON object provided below, I ...

How to hide the header on a specific page using Angular

Currently, I am working on an Angular project and my requirement is to hide the header block specifically on the login page. Despite attempting to hide the header on the login page, it seems that my efforts have been unsuccessful so far. Is there anyone wh ...

Alignment problem

In my design, I have a toolbar with flex display and I am trying to center my span element within it. However, I seem to be missing something in the CSS. CSS .toolbar { position: absolute; top: 0; left: 0; right: 0; height: 60px; d ...

Transferring a header across a series of interconnected services

I have a script that calls two services, combines their results, and displays them to the user. The services are: Service 1 (hello) and Service 2 (world), resulting in "Hello world". I want to include an ID in the headers to track the route of the calls. ...

unable to disable custom field component in Angular Material

I've built a unique slide toggle feature using Angular Material. The steps I followed to create it can be found here: https://material.angular.io/guide/creating-a-custom-form-field-control While everything works smoothly, there's an issue when I ...

Using jQuery to incorporate a variable into JSON schema markup

For my current project, I am attempting to extract the meta description and incorporate it into JSON schema markup. However, I am facing difficulty in passing the variable properly into the JSON structure. My initial approach was as follows: <script&g ...

Using the onKeyUp and onKeyDown functions to detect when the spacebar key is pressed

Is there a way for my function to be triggered by either clicking a button or pressing the spacebar? I have managed to make it work partially, but it's not quite right. This is the function in question: const showText = () => { const x = Toug ...

Using Sencha Touch: What is the best method for populating an HTML panel with a JSON response?

I've exhausted all possible combinations in my attempts to load a JSON object from the server and use it to render a panel with video and other information. Despite my efforts, I haven't been able to make anything work. What could I be doing inco ...

I'm trying to determine in Stencil JS if a button has been clicked in a separate component within a different class. Can anyone assist

I've created a component named button.tsx, which contains a function that performs specific tasks when the button is clicked. The function this.saveSearch triggers the saveSearch() function. button.tsx {((this.test1) || this.selectedExistingId) && ...

How can you run a function in JavaScript or TypeScript that is stored as a string?

Is there a way to call a function that is stored as a string? For example: var dynamicFun = `function Hello(person) { return 'Hello' + person; }` In this case, the dynamicFun variable can store any function definition dynamically, such as: var ...

Exploring the world of typescript with the power of ts-check

I'm having trouble figuring out how to work with a generic function using TypeScript's new ts-check feature. /** * @type {Reducer<IPoiState, any>} */ const poi = handleActions({ [ADD_BOOKMARK_START]: (state) => { return { ...sta ...