Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS cursor pointer on div not working

Tags:

html

css

I want to changer the cursor type on a div but it is not working.

HTML:

<div class='upload-wrapper'>
  <label for='file-input'>
    <img src='http://i.imgur.com/MIY6LmH.png' alt='Upload File' title='Upload File' width='250' height='250'>
  </label>
  <input type='file' name='photo' id='file-input'>
</div>

CSS:

.upload-wrapper {
    width: 250px;
    height: 250px;
    margin: 0 auto;
    cursor: pointer;
}

.upload-wrapper img {
    width: 250px
    height: 280px;
}

.upload-wrapper input {
    display: none;
}

Result: https://jsfiddle.net/m7tctnvh/

Thanks in advance for solutions but I would also want to know why the CSS is not working as expected.

like image 772
Robert Rocha Avatar asked Mar 18 '16 18:03

Robert Rocha


People also ask

Why is my cursor pointer not working?

Check that the battery of the mouse is charged. Make sure that the receiver (dongle) is firmly plugged in to the computer. If your mouse and receiver can operate on different radio channels, make sure that they are both set to the same channel.

What is curser pointer in CSS?

The cursor CSS property sets the mouse cursor, if any, to show when the mouse pointer is over an element.

Why is custom cursor not working?

There could be various reasons behind the custom cursor extension not working in Chrome. First, make sure that you are not on the homepage or the Chrome Web Store since the extension is not designed to work here. Also, certain Chrome settings are known to affect the functioning of the extension and lead to issues.

How do I change my mouse pointer to CSS?

You can simply use the CSS cursor property with the value pointer to change the cursor into a hand pointer while hover over any element and not just hyperlink. In the following example when you place the cursor over the list item, it will change into a hand pointer instead of the default text selection cursor.


3 Answers

The image (or label tag) is resetting the cursor. The following works:

.upload-wrapper img {
    width: 250px
    height: 280px;
  cursor:pointer;
}

Edit: Inherited from label (user agent stylesheet):

label {
    cursor: default;
}

So this is a browser default. Maybe not in any browser. However you have to be specific.

Tipp: You may use reset CSS in your projects (http://meyerweb.com/eric/tools/css/reset/). This causes much less pain with browser defaults.

And by-the-way

label {
cursor:inherit;
}

also solves the problem and is maybe more what you want.

like image 88
Blackbam Avatar answered Oct 18 '22 21:10

Blackbam


See this fiddle

.upload-wrapper img {
    width: 250px;
    cursor:pointer; 
}

You have to put it on the img and you forget to add ";" after width property

like image 20
Vincent G Avatar answered Oct 18 '22 23:10

Vincent G


you forget to put ; in .upload-wrapper img and you need to put the cursor when hovering over the image so your code should look like this:

.upload-wrapper {
    width: 250px;   
    height: 250px;
    margin: 0 auto;
}

.upload-wrapper img {
    width: 250px;
    height: 280px;
    cursor: pointer;
}

.upload-wrapper input {
    display: none;
}

https://jsfiddle.net/84rgb45o/

like image 1
Brahim Chougrani Avatar answered Oct 18 '22 21:10

Brahim Chougrani