Kilian
Kilian

Reputation: 133

How to get a round outline on a round <button> with css in Safari

I'm trying to get a round button which has a an outline in the same color but that doesn't seem to be possible. The outline always ends up squared. Is there a method to achieve that with a or does it maybe only work with a ?

button {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 40px;
  cursor: pointer;
  background-color: black;
  display: inherit;
  outline: 5px solid black;
  outline-offset: 5px;
}
<button></button>

I have added a picture since this only seems to happen on Safari...Screenshot from Safari snippet

I need it to work in all browsers especially on mobile though.

Upvotes: 12

Views: 13307

Answers (5)

Orkhan Jafarov
Orkhan Jafarov

Reputation: 255

Workaround is no longer needed.

They finally added it in Safari 16.4:

  • Added support for outline following the curve of border-radius.

https://developer.apple.com/documentation/safari-release-notes/safari-16_4-release-notes

Upvotes: 5

mikep
mikep

Reputation: 7448

For example instead of outline: 2px solid gray can be used box-shadow: 0 0 0 2px gray. Box-shadow + border-radius works OK in silly Safari. Fixing with ::after is too complicated with in about 10 additional CSS properties.

Upvotes: 8

watson
watson

Reputation: 65

Safari fixed this bug on Safari Technology Preview 157. Source: https://webkit.org/blog/13575/release-notes-for-safari-technology-preview-157/

Upvotes: 5

bZezzz
bZezzz

Reputation: 1002

You can use this "hack".

INFO: In Brave Browser we got a square too with your snippet;

enter image description here

button {
  position: relative;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 40px;
  cursor: pointer;
  background-color: black;
  display: inherit;
  margin:10px 2px;
}

button::after {
  position: absolute;
  top: -10px;
  content: '';
  left: -10px;
  width: 50px;
  height: 50px;
  border: 5px solid black;
  border-radius: 40px;
  background-color: transparent;
  display: inherit;
}
<button></button>

Upvotes: 5

Moinul Robin
Moinul Robin

Reputation: 36

According to your question and code snippet that you have provided. From my browser when I ran both the button and the outline was Circle.

I would suggest you to clear your cache and run the code again OR try changing the browser.

Or please update your question with a screenshot as well, so that we can understand better.

Upvotes: -3

Related Questions