Cursor pointer not working with position absolute

Almost all the websites are changing the cursors for better user experience or just for fun. Customizing cursors is an easy way to add an extra flourish to your site when needed.

To specify the cursor appearance, use the CSS cursor property, which is used to change the mouse cursor type on elements. It can be useful in websites where different actions should be done rather than just clicking.

We will cover the following ways for managing cursor usability:

  • How to Make the Cursor a Hand when the User Hovers over a List Item
  • How to Change the Cursor of Hyperlink while Hovering
  • How to Have Custom Cursor Image Effect on the Element
  • All Cursor Types Example

If you want to change a mouse pointer into a hand pointer when hovering over a list item, you can set a class for your list item (

  • ) and define the style only for that one. But if you want to have a hand pointer for all of your list items, just set the style for the
  • element.

    Now let’s see an example of changing a mouse pointer into a hand pointer by using the "pointer" value of the cursor property. We set that cursor type only on the "pointer" class.

    Example of changing a mouse pointer into a hand pointer:

    html>
    <html>
      <head>
        <title>Title of the documenttitle>
        <style>
          li {
            margin-bottom: 15px;
          }
          li.pointer {
            cursor: pointer;
          }
          li:hover {
            background-color: #ccc;
          }
        style>
      head>
      <body>
        <h4>Hover over the list items to see how the default cursor changes into a pointer:h4>
        <ul>
          <li>List item 1 with the default cursor.li>
          <li class="pointer">List item 2 with the pointer cursor.li>
          <li>Another list item with the default mouse cursor.li>
        ul>
      body>
    html>

    Result

    Hover over the list items to see how the default cursor changes into a pointer:

    • List item 1 with the default cursor.
    • List item 2 with the pointer cursor.
    • Another list item with the default mouse cursor.

    In the next example, the :nth-child selector is used. Here, we use nth-child(odd) for cursor: progress; and nth-child(even) for cursor: pointer; to have separate cursor types on different list items.

    Example of using the pointer and progress cursors:

    html>
    <html>
      <head>
        <title>Title of the documenttitle>
        <style>
          li:nth-child(odd) {
            background: #1c87c9;
            cursor: progress;
            width: 50%;
            padding: 5px;
          }
          li:nth-child(even) {
            background: #ccc;
            cursor: pointer;
            width: 50%;
            padding: 5px;
          }
        style>
      head>
      <body>
        <p>Hover over the list items to see how the cursor changes:p>
        <ul>
          <li>List item 1li>
          <li>List item 2li>
          <li>List item 3li>
          <li>List item 4li>
          <li>List item 5li>
          <li>List item 6li>
          <li>List item 7li>
        ul>
      body>
    html>

    The default cursor for a hyperlink is "pointer". To change it, you need to specify the cursor type for your element with the CSS :hover selector. In our example, we style only the "link" class.

    Example of changing the “pointer” to “default”:

    html>
    <html>
      <head>
        <title>Title of the documenttitle>
        <style>
          .link:hover {
            cursor: default;
          }
        style>
      head>
      <body>
        <h4>
          Hover over the hyperlink to see how the "pointer" changes to "default":
        h4>
        <p>
          <a href="https://www.w3docs.com">W3docsa> 
          link with the initial "pointer" type.
        p>
        <p>
          <a class="link" href="https://www.w3docs.com">W3docsa> 
          link with the changed "default" cursor type.
        p>
      body>
    html>

    As links have a blue color and underline by default, we suggest to change link colors and go further with hyperlinks.

    html>
    <html>
      <head>
        <title>Title of the documenttitle>
        <style>
          a {
            cursor: grab;
          }
        style>
      head>
      <body>
        <a href="https://www.w3docs.com/" aria-label="w3docs homepage">
          <img src="/uploads/media/default/0001/01/0710cad7a1017902166203def268a0df2a5fd545.png" width="190" height="45" alt="logo" />
        a>
      body>
    html>

    Let’s do more fun with cursors! It’s possible to add an image as a cursor on your webpage. You just need to add your image by specifying its URL as a value of the cursor property.

    Remember to set the cursor type to show when the browser can’t use the provided image. Otherwise, your code will not work.

    This is a funny trick to add to your website when users don’t expect to see such things. Imagine you have a form where the answer corresponds to a specific emotion, here is the ideal place to use emoji images.

    Example of adding an image as a cursor:

    html>
    <html>
      <head>
        <title>Title of the documenttitle>
        <style>
          body {
            background: #eee;
            text-align: center;
          }
          button {
            display: inline-block;
            background-color: #1c87c9;
            color: #eee;
            margin: 25px;
            position: relative;
            width: 140px;
            height: 45px;
            border-radius: 3px;
            border: none;
            font-size: 1.5em;
            text-align: center;
            text-decoration: none;
            box-shadow: 0 2px 8px 0 #999;
          }
          button:hover {
            background-color: #999;
            color: #ffcc00;
          }
          #happy {
            cursor: url("/uploads/media/default/0001/02/ee4486d1b3fc998e444c3b0100c73db282760eb5.png"), auto;
          }
          #sad {
            cursor: url("/uploads/media/default/0001/02/38cb87a27305100311d9c96e5a5ebb88f04d8034.png"), auto;
          }
          #love {
            cursor: url("/uploads/media/default/0001/02/4be757cf6e9ffc865861649ca423654484ad3dc1.png"), auto;
          }
        style>
      head>
      <body>
        <h2>What is your impression of our website?h2>
        <button id="happy">Happybutton>
        <button id="sad">Sadbutton>
        <button id="love">Lovebutton>
      body>
    html>

    Example of using icons as a cursor:

    html>
    <html>
      <head>
        <title>Title of the documenttitle>
        <style>
          body {
            width: 600px;
            margin: 0.5em auto;
          }
          img {
            width: 280px;
            height: 186px;
            margin: 5px;
            display: inline-block;
            background-position: 50% 50%;
          }
          .dog {
            cursor: url("/uploads/media/default/0001/02/53f34c2d574ce31a424df7855ef3e8f2ece589d6.png"), auto;
          }
          .cactus {
            cursor: url("/uploads/media/default/0001/02/ea8020fd3fdb96affa77c8164f80d88f8c419e0f.png"), auto;
          }
          .nature {
            cursor: url("/uploads/media/default/0001/02/edcafd9e202ae5f2ae6ae839d21d1d642b2ace00.png"), auto;
          }
          .house {
            cursor: url("/uploads/media/default/0001/02/bb6f118f3b06838624b4297992457093f40fd92b.png"), auto;
          }
        style>
      head>
      <body>
        <img class="cactus" src="/uploads/media/default/0001/02/fc16e475b5cefcbe57924b1a4a3b3e38e936b77c.png" alt="cactus">
        <img class="nature" src="/uploads/media/default/0001/02/2a85e41725d19aeae7066836accaababd42e638d.png" alt="nature">
        <img class="dog" src="/uploads/media/default/0001/02/23df99002f94be0d1ca915058e2216c756be155e.png" alt="dog">
        <img class="house" src="/uploads/media/default/0001/02/1492763b186dabd60c4fbad49ce6d4ba3925b712.png" alt="house">
      body>
    html>

    You can also use icons from websites where the Base64 code is provided just pasting the Base64 code in the cursor’s URL value. Or download the icon to your website and use the URL for setting the cursor.

    Here see an example, which contains all the possible types that a cursor can have.

    For "zoom-in", "zoom-out", "grab" and "grabbing" values, the -webkit- property extension is added.

    Example of using all cursor types:

    html>
    <html>
      <head>
        <title>Title of the documenttitle>
        <style>
          body {
            text-align: center;
            font-family: Roboto, Helvetica, Arial, sans-serif;
          }
          .cursor {
            display: flex;
            flex-wrap: wrap;
          }
          .cursor > div {
            flex: 120px;
            padding: 10px 2px;
            white-space: nowrap;
            border: 1px solid #666;
            border-radius: 5px;
            margin: 0 5px 5px 0;
          }
          .cursor > div:hover {
            background: #1c87c9;
          }
          .auto {
            cursor: auto;
          }
          .default {
            cursor: default;
          }
          .none {
            cursor: none;
          }
          .context-menu {
            cursor: context-menu;
          }
          .help {
            cursor: help;
          }
          .pointer {
            cursor: pointer;
          }
          .progress {
            cursor: progress;
          }
          .wait {
            cursor: wait;
          }
          .cell {
            cursor: cell;
          }
          .crosshair {
            cursor: crosshair;
          }
          .text {
            cursor: text;
          }
          .vertical-text {
            cursor: vertical-text;
          }
          .alias {
            cursor: alias;
          }
          .copy {
            cursor: copy;
          }
          .move {
            cursor: move;
          }
          .no-drop {
            cursor: no-drop;
          }
          .not-allowed {
            cursor: not-allowed;
          }
          .all-scroll {
            cursor: all-scroll;
          }
          .col-resize {
            cursor: col-resize;
          }
          .row-resize {
            cursor: row-resize;
          }
          .n-resize {
            cursor: n-resize;
          }
          .e-resize {
            cursor: e-resize;
          }
          .s-resize {
            cursor: s-resize;
          }
          .w-resize {
            cursor: w-resize;
          }
          .ns-resize {
            cursor: ns-resize;
          }
          .ew-resize {
            cursor: ew-resize;
          }
          .ne-resize {
            cursor: ne-resize;
          }
          .nw-resize {
            cursor: nw-resize;
          }
          .se-resize {
            cursor: se-resize;
          }
          .sw-resize {
            cursor: sw-resize;
          }
          .nesw-resize {
            cursor: nesw-resize;
          }
          .nwse-resize {
            cursor: nwse-resize;
          }
          .grab {
            cursor: -webkit-grab;
            cursor: grab;
          }
          .grabbing {
            cursor: -webkit-grabbing;
            cursor: grabbing;
          }
          .zoom-in {
            cursor: -webkit-zoom-in;
            cursor: zoom-in;
          }
          .zoom-out {
            cursor: -webkit-zoom-out;
            cursor: zoom-out;
          }
        style>
      head>
      <body>
        <h2>Cursor property exampleh2>
        <p> Hover the mouse cursor over the element to see the changes:p>
        <div class="cursor">
          <div class="auto">autodiv>
          <div class="default">defaultdiv>
          <div class="none">nonediv>
          <div class="context-menu">context-menudiv>
          <div class="help">helpdiv>
          <div class="pointer">pointerdiv>
          <div class="progress">progressdiv>
          <div class="wait">waitdiv>
          <div class="cell">celldiv>
          <div class="crosshair">crosshairdiv>
          <div class="text">textdiv>
          <div class="vertical-text">vertical-textdiv>
          <div class="alias">aliasdiv>
          <div class="copy">copydiv>
          <div class="move">movediv>
          <div class="no-drop">no-dropdiv>
          <div class="not-allowed">not-alloweddiv>
          <div class="all-scroll">all-scrolldiv>
          <div class="col-resize">col-resizediv>
          <div class="row-resize">row-resizediv>
          <div class="n-resize">n-resizediv>
          <div class="s-resize">s-resizediv>
          <div class="e-resize">e-resizediv>
          <div class="w-resize">w-resizediv>
          <div class="ns-resize">ns-resizediv>
          <div class="ew-resize">ew-resizediv>
          <div class="ne-resize">ne-resizediv>
          <div class="nw-resize">nw-resizediv>
          <div class="se-resize">se-resizediv>
          <div class="sw-resize">sw-resizediv>
          <div class="nesw-resize">nesw-resizediv>
          <div class="nwse-resize">nwse-resizediv>
          <div class="grab">grabdiv>
          <div class="grabbing">grabbingdiv>
          <div class="zoom-in">zoom-indiv>
          <div class="zoom-out">zoom-outdiv>
        div>
      body>
    html>

    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.

    Does Z Index work with position absolute?

    Note: z-index only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky) and flex items (elements that are direct children of display:flex elements).

    What is CSS cursor?

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

    How to customize cursor CSS?

    Answer: Use the CSS cursor property You can define a custom cursor using the CSS cursor property. The cursor property takes the comma-separated list of user-defined cursors value followed by the generic cursor. First of all create cursor image and save it with the extension .