Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overflow: hidden with border radius not working on Safari

Tags:

html

css

I have to make a button with a ::before hidden which shows on :hover. This animation is working great on Chrome, IE and Firefox, but i have a weird issue on Safari.

Overflow:hidden is working but without the border radius.

You should run the fiddle in safari to see this issue.

Thanks !

.btn{    border-radius: 3rem;    cursor: pointer;    display: inline-block;    font-size: 15px;    font-weight: 400;    font-family: arial;    overflow: hidden;    position: relative;    padding: 0.8rem 2.5rem;    text-decoration: none;    }    .btn-primary{    background-color: blue;    border-color: blue;    color: white;  }    .btn-primary::before{    background-color: deeppink;    border-radius: 50%;    content: '';    color: white;    height: 100%;    left: 100%;    margin: 0;    position: absolute;    top: 0;    transform-origin: 100% 50%;    transform: scale3d(1, 1.4, 1);    transition: all 300ms cubic-bezier(0.7,0,0.9,1);    width: 20%;  }    .btn-primary:hover::before{    transform: scale3d(1, 5, 1);    width: 110%;    left: -2%;    z-index: 0;  }    .btn-primary span{    position: relative;    z-index: 1;  }
<a href="#" class="btn btn-primary">    <span>Button primary</span>  </a>
like image 624
Victor Allegret Avatar asked Mar 02 '18 09:03

Victor Allegret


People also ask

Why does overflow hidden not work?

It is because you are using position absolute. You cannot use position absolute with overflow hidden, because position absolute moves the targeted element out of context with the document structure.

Why border-radius is not working?

If there are contents within the div that has the curved corners, you have to set overflow: hidden because otherwise the child div's overflow can give the impression that the border-radius isn't working. This answer worked for me.

Can I use CSS border-radius?

You can give any element “rounded corners” by applying a border-radius through CSS. You'll only notice if there is a color change involved. For instance, if the element has a background-color or border that is different than the element it's above.

What is WebKit border-radius in CSS?

The border-radius property in WebKit accepts one or two values and uses them to style all four corners making a nice symmetric shape. The new Firefox syntax allows you to define four different round or elliptical corners. A slash has been introduced to separate the horizontal and vertical length settings.


1 Answers

The accepted answer works, but indeed it removes the box shadow. A comment I saw in this github post says that it can be also fixed by creating a new stacking context (kind of moving an element into a new painting layer). That can be achieved with a small hack like

transform: translateZ(0)

In my case both overflow and box-shadow are working with this solution. I hope it helps somebody else too.

like image 177
Blind Despair Avatar answered Sep 21 '22 12:09

Blind Despair