1

reset-button.css

 11 months ago
source link: https://gist.github.com/MoOx/9137295
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

reset-button.css · GitHub

Instantly share code, notes, and snippets.

I think this is missing.

text-align: inherit;

Nice gist!

I think this is missing:

outline: none;

@ArtemFitiskin
That's not good for accessibility :)

Consider adding border-radius: 0; for iOS – in case someone uses

<input type="button" value="Button" />
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />

If you stumbled upon this ancient(in web timeline) gist and want to remove outlines consider using:

  :focus:not(:focus-visible) {
    outline: none;
  }
  :focus:not(:-moz-focusring) {
    outline: none;
  }

This removes them only for mouse clicks in modern browsers.
moz-focusring selector removed it in older Firefox browsers. Just be sure to know witch browsers you need to support as legacy potato browsers will still display outlines.

@povilasbaranovas This was quite interesting, thanks. The MDN article on :focus-visible does note that Safari support is lacking, though there's a polyfill using Javascript.

This gist is indeed ancient and incomplete.

I think nowadays you just need this:

button {
  all: unset;
}

It starts inheriting all the values like you'd expect, with the exception that:

  • it still behaves like inline-block
  • the text is still vertically centered

I think nowadays you just need this:

button {
  all: unset;
}

Lol. Never seen a more powerful one-liner in my entire career. Thanks, @fregante

I think nowadays you just need this:

button {
  all: unset;
}

It starts inheriting all the values like you'd expect, with the exception that:

  • it still behaves like inline-block
  • the text is still vertically centered

This also removes the default outline from the button when it's focused which makes it completely inaccessible when using keyboard navigation. Be sure to style a custom outline. I tried using outline: revert at it seems to work OK in Chrome, Edge, Firefox and Safari, so for modern browsers I suggest keeping these 2 rules always together and use a mixin for that, so no one forgets.

@mixin u-button-reset() {
  all: unset;
  outline: revert;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK