One place for hosting & domains

      Property

      Change the Mouse Cursor in CSS With the cursor Property


      While this tutorial has content that we believe is of great benefit to our community, we have not yet tested or
      edited it to ensure you have an error-free learning experience. It’s on our list, and we’re working on it!
      You can help us out by using the “report an issue” button at the bottom of the tutorial.

      cursor is used to change the mouse cursor on specific elements. This is especially useful in web apps where different tasks can be done other than clicking. This obviously only works when there’s a pointing device:

      .in-progress {
        cursor: progress;
      }
      

      Available Cursors

      Hover over the following to see the different cursors available if you’re on a desktop/laptop computer:

      General/Default Cursors

      Scroll Cursor

      Status Cursors

      context-menu

      help

      wait

      progress

      Selection Cursors

      crosshair

      cell

      text

      vertical-text

      Drag & Drop Cursors

      alias

      copy

      move

      no-drop

      not-allowed

      Zoom Cursors

      Grab Cursors

      Resizing Cursors

      e-resize

      n-resize

      ne-resize

      nw-resize

      s-resize

      se-resize

      sw-resize

      w-resize

      ew-resize

      ns-resize

      nesw-resize

      nwse-resize

      col-resize

      row-resize

      Custom Cursors

      You can define custom cursors. Note that not all browsers support svg files for cursors, and .cur files are supported across the board, so it can be a good idea to provide a .cur fallback if you want to use an svg cursor. You can also provide a fallback to one of the non-custom cursors.

      You can define a custom position for the cursor hotspot by adding x & y coordinates for where the hotspot should be in the provided custom image.

      Note that, when using svg cursors, it’s important that your svg has width & height values on the root svg element, or else your cursor won’t show. In the following example, our svg file (droplet.svg) starts like this:

      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 42 42" width="42" height="42">...
      
      .custom-cur {
        cursor: url('/images/droplet.svg');
      }
      
      /* With a .cur fallback */
      .custom-cur {
        cursor: url('/images/droplet.svg'),
        url('/images/droplet.cur');
      }
      
      /* With a custom hotspot */
      .custom-cur {
        cursor: url('/images/droplet.svg') 10 12;
      }
      
      /* With a non-custom fallback: */
      .custom-cur {
        cursor: url('/images/droplet.svg'),
        move;
      }
      

      Here’s an example with a custom cursor:

      Dino Sammy Cursor

      Browser Support:
      As of 2020, only 80% of browsers worldwide support custom cursors according to Can I Use css3-cursors?. But this isn’t surprising, many of the browsers that don’t support it are mobile-only browsers that have no use for cursors.

      Conclusion:

      Custom cursors are most commonly used to indicate that an HTML element that’s not already a link <a href="https://www.digitalocean.com/community/tutorials/..."> is clickable. But it provides a diverse set of additional configurability that could be useful to developers building rich web apps. Keep the following caveats in mind when using custom cursors:

      1. Your users spend most of their time on other sites, so use custom cursors in a way that is consistent with other sites.
      2. Touchscreen users (mobile and tablet) won’t see custom cursors.



      Source link

      CSS vertical-align Property


      While this tutorial has content that we believe is of great benefit to our community, we have not yet tested or
      edited it to ensure you have an error-free learning experience. It’s on our list, and we’re working on it!
      You can help us out by using the “report an issue” button at the bottom of the tutorial.

      Introduction

      vertical-align defines the vertical alignment for the content of a table cell or for an inline element against the rest of the inline flow.

      vertical-align can take a % or length value, or it can take one of the following 8 keywords:

      • baseline: The default. Baseline of the element aligned to the baseline of the parent.
      • bottom: Bottom of the element aligned to the complete bottom of the line.
      • middle: Middle of the element aligned to half the x-height of the parent. The x-height is the height of the text without the character ascenders or descenders.
      • sub: Baseline of the element aligned to the subscript baseline of the parent.
      • super: Baseline of the element aligned to the superscript baseline of the parent.
      • text-bottom: Bottom of the element aligned to the bottom of the text.
      • text-top: Top of the element aligned to the top of the text.
      • top: Top of the element aligned to the top of the line.

      If a length value is provided, the element is aligned at the specified length above the baseline of the parent.

      If a % value is provided, the element is aligned at the specified % above the baseline of the parent, with the % being a reference to the line-height.

      Here’s an example using vertical-align:

      .avatar {
        vertical-align: middle;
      }
      

      Examples

      It can be hard to visualize the effects of the different keyword values for vertical-align, so here are examples with an inline seashell emoji (🐚) placed with different values:

      vertical-align: baseline

      Sammy sells seashells 🐚 by the seashore.

      vertical-align: bottom

      Sammy sells seashells 🐚 by the seashore.

      vertical-align: middle

      Sammy sells seashells 🐚 by the seashore.

      vertical-align: sub

      Sammy sells seashells 🐚 by the seashore.

      vertical-align: super

      Sammy sells seashells 🐚 by the seashore.

      vertical-align: text-bottom

      Sammy sells seashells 🐚 by the seashore.

      vertical-align: text-top

      Sammy sells seashells 🐚 by the seashore.

      vertical-align: top

      Sammy sells seashells 🐚 by the seashore.



      Source link

      CSS white-space Property


      While this tutorial has content that we believe is of great benefit to our community, we have not yet tested or
      edited it to ensure you have an error-free learning experience. It’s on our list, and we’re working on it!
      You can help us out by using the “report an issue” button at the bottom of the tutorial.

      white-space is a CSS property that helps control how whitespace and line breaks within an element’s text are treated.

      The white-space property can take these values:

      • normal: The default value. Multiple whitespaces are collapsed into one. The text wraps to the next line when needed.
      • nowrap: Multiple whitespaces are collapsed into one, but the text doesn’t wrap to the next line. We’ve already discussed how to use the nowrap value to prevent line breaks.
      • pre: Same results as using the <pre> where all the whitespaces will be kept as is and the text only wraps when line breaks are in the content.
      • pre-line: Multiple whitespaces are collapsed into one, the text breaks to the next line when needed or with line breaks in the content.
      • pre-wrap: Similar to pre, but the text also wraps when needed.

      white-space: normal

      Medusafish banded killifish convict blenny saury threadsail beluga sturgeon. Indian mul mora cisco masu salmon, roosterfish requiem shark longnose lancetfish bluefish red snapper Sacramento splittail giant danio.

      white-space: nowrap

      Medusafish banded killifish convict blenny saury threadsail beluga sturgeon. Indian mul mora cisco masu salmon, roosterfish requiem shark longnose lancetfish bluefish red snapper Sacramento splittail giant danio.

      white-space: pre

      Here I manually included line breaks and extra spaces. Notice the extra line break at the beginning. That’s because in the markup the text start on the line after the <p> element.

      Medusafish banded killifish convict blenny saury threadsail beluga sturgeon. Indian mul mora cisco masu salmon, roosterfish requiem shark longnose lancetfish bluefish red

      snapper Sacramento splittail giant danio.

      pre-line

      Here the text breaks when needed, but I also manually broke the last few words. I included the same extra whitespaces, but they are now collapsed.

      Medusafish banded killifish convict blenny saury threadsail beluga sturgeon. Indian mul mora cisco masu salmon, roosterfish requiem shark longnose lancetfish bluefish red snapper Sacramento splittail giant danio.

      pre-wrap

      Now the extra whitespaces aren’t collapsed.

      Medusafish banded killifish convict blenny saury threadsail beluga sturgeon. Indian mul mora cisco masu salmon, roosterfish requiem shark longnose lancetfish bluefish red snapper Sacramento splittail giant danio.



      Source link