skip to Main Content

When I set the screen size to be small in Chrome dev tools or when I check my project on my phone, a blue square temporarily appears around the button when I click it. I have tried to set outline: none or outline: 0 to button, button:hover, button:focus and button:active to prevent this, but there was no visible change. I checked the styling in Chrome dev tools, but I can’t figure out where this blue square comes from and how to remove it or make it invisible. Any help is welcome.

This is my HTML:

<button>
    <span class="dice-wrapper">
        <img src="./src/assets/icon-dice.svg" alt="Dice icon">
    </span>
</button>

This is my CSS:

button {
  width: 64px;
  aspect-ratio: 1 / 1;
  display: flex;
  justify-content: center;
  align-items: center;
  border: none;
  border-radius: 50%;
  background-color: var(--neon-green);
}

button:hover {
  cursor: pointer;
  box-shadow: 0 0 40px 3px var(--neon-green);
}

button:focus, button:active {
  box-shadow: none;
}

Full code on GitHub: https://github.com/Marjolein-Kasman-de-Jong/advice-generator-app

Project on GitHub Pages: https://marjolein-kasman-de-jong.github.io/advice-generator-app/

2

Answers


  1. button {
      -webkit-tap-highlight-color: transparent;
    }
    
    Login or Signup to reply.
  2. See this Mozilla site for information about the :focus-visible pseudo class.

    To save you a few clicks, try:

    button:focus {
        outline: none;
    }
    

    or

    button:focus {
        outline: 0;
    }
    

    Also try removing a box shadow (box-shadow: none;).

    Please note that

    This isn’t good practice

    as screen reader users will not be able to see their pointer. Check here for more info.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search