7

I built a sample HTML webpage recently, and when I hover the mouse pointer over a <div> element that makes a drop down menu come down on click, the pointer changes to a cursor, allowing me to highlight the text in the <div>.

The thing is, I don't want the mouse pointer to change to a cursor.(I don't want to be able to highlight the text either.) I want it to either remain the way it is or change to the 'clickable hand' pointer that comes up when the mouse pointer hovers over a link.

How can I achieve this?

Aswin G
  • 361
  • 3
  • 9
  • 18

5 Answers5

22

The cursor can be changed using CSS cursor property.

cursor:pointer;

https://css-tricks.com/almanac/properties/c/cursor/


You can also prevent highlighting using the user-select property:

-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;

How to disable text selection highlighting using CSS?


For example:

div{
   cursor:pointer;
   -webkit-touch-callout: none;
   -webkit-user-select: none;
   -khtml-user-select: none;
   -moz-user-select: none;
   -ms-user-select: none;
   user-select: none;
}
Community
  • 1
  • 1
Curtis
  • 101,612
  • 66
  • 270
  • 352
5

Set

cursor:pointer

on the div

like

div{
cursor:pointer;
}

and as kurt suggested you can use

-webkit-user-select:none;
-moz-user-select:none;
-o-user-select:none;
 user-select:none;

to remove the highlight

Akshay
  • 14,138
  • 5
  • 46
  • 70
0

In CSS:

#div-id {
    cursor: pointer;
}
ByteHamster
  • 4,884
  • 9
  • 38
  • 53
Alok Pathak
  • 875
  • 1
  • 8
  • 20
0

cursor:pointer; in your css.

check here http://www.w3schools.com/cssref/pr_class_cursor.asp for al possibilities for the cursor property

Nils O
  • 1,321
  • 9
  • 19
0

Set the role attribute to button:

<div role="button"></div>

https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/button_role

xuxu
  • 6,374
  • 1
  • 17
  • 11