Firefox-CSS: border-radius issue for pseudo-element “before”

家住魔仙堡 提交于 2021-02-17 04:46:16

问题


I have a card-element (bootstrap-4) with a front and back, on hover the back side is shown. In order to create a "folded corner effect" I am using a pseudo-element(:before) on the front card, which works fine for all browsers except of firefox.

The bottom-left corner of the pseudo-element should also be rounded, so I set a border-radius. Unfortunately in Firefox the corner is not rounded, instead there is a strange box shown in the pseudo-element.

Any ideas what is causing this issue in Firefox? I already played around with positioning, z-index, overflow etc. but I cannot find the root cause.

Thanks a lot in advance!!

https://jsfiddle.net/rbv5ob20/

HTML:

.card {
  color: white;
  border: transparent;
  border-radius: 10px;
  -webkit-box-shadow: -4px 4px 5px 0px rgba(50, 50, 50, 0.2);
  box-shadow: -4px 4px 5px 0px rgba(50, 50, 50, 0.2);
}

.front,
.back {
  width: 100%;
  height: 150px;
  background: #99d0e9;
  opacity: 1;
  backface-visibility: hidden;
  overflow: hidden;
  border-radius: 10px 0px 10px 10px;
}

.front {
  position: absolute;
  left: 0;
  z-index: 1;
  opacity: 1;
  text-align: left;
  display: -webkit-inline-box;
  display: -ms-inline-flexbox;
  display: inline-flex;
}

.front::before {
  content: "";
  position: absolute;
  top: 0px;
  right: 0px;
  border-width: 0px 25px 25px 0px;
  border-style: solid;
  border-color: transparent #f6f6f6 #32a2d4 transparent;
  border-bottom-left-radius: 10px;
}

.back {
  background: #32a2d4;
  opacity: 1;
  -webkit-transform: rotateY(-180deg);
  -ms-transform: rotateY(-180deg);
  transform: rotateY(-180deg);
  text-align: right;
  border-top-right-radius: 10px;
  display: block;
}

.card:hover .back {
  -webkit-transform: rotateY(0);
  -ms-transform: rotateY(0);
  transform: rotateY(0);
}

.card:hover .front {
  -webkit-transform: rotateY(180deg);
  -ms-transform: rotateY(180deg);
  transform: rotateY(180deg);
}
<section id="offering" style="background-color:#f6f6f6;">
  <div class="container">

    <div class="col-4 text-center">

      <div class="card">
        <div class="front">
          this is front...
        </div>
        <div class="back">
          this is back
        </div>
      </div>

    </div>
  </div>
</section>

回答1:


In Firefox border-radius doesn't seem to get properly applied to elements with a width and height of 0. A possible workaround to this would be to make a wrapper with overflow: hidden and a border-radius on its own:

.roundArrow {
  border-radius: 0 0 0 10px;
  width: 50px;
  height: 50px;
  overflow: hidden;
}

.roundArrow:after {
  content: "";
  display: block;
  top: 0px;
  right: 0px;
  border-width: 0px 50px 50px 0px;
  border-style: solid;
  border-color: transparent #f6f6f6 #32a2d4 transparent;
}
<div class="roundArrow"></div>



回答2:


<!DOCTYPE html>
<html lang="en">
<head>
  
  <style>
      .card {
color: white;
border: transparent;
border-radius: 10px ;
-webkit-box-shadow: -4px 4px 5px 0px rgba(50, 50, 50, 0.2);
box-shadow: -4px 4px 5px 0px rgba(50, 50, 50, 0.2);
}

.front, .back {
width: 100%;
height:150px;
background: #99d0e9;
opacity: 1;
backface-visibility: hidden;
overflow: hidden;
border-radius: 10px 0px 10px 10px;
}

.front {
position: absolute;
left: 0;
z-index: 1;
opacity:1;
text-align:left;
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex;
}

.front::before {
      content: "";
      position: absolute;
      top: 0px;
      right: 0px;
      border-bottom-left-radius: 10px;
      height: 25px;
      width: 25px;
      background: #32a2d4;
}

.front::after {
    content: "";
    position: absolute;
    top: -11px;
    right: -17px;
    height: 28px;
    width: 35px;
    background: white;
    transform: rotate(45deg);
}

.back {
background: #32a2d4;
opacity: 1;
-webkit-transform: rotateY(-180deg);
-ms-transform: rotateY(-180deg);
transform: rotateY(-180deg);
text-align:right;
border-top-right-radius: 10px;
display: block;
}

.card:hover .back {
-webkit-transform: rotateY(0);
-ms-transform: rotateY(0);
transform: rotateY(0);
}

.card:hover .front {
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
}
  </style>
</head>
<body>
      <section id="offering" style="background-color:#f6f6f6;">
            <div class="container">
        
                    <div class="col-4 text-center"> 
        
                        <div class="card">
                            <div class="front">
                                this is front...
                            </div>
                            <div class="back">
                                this is back
                            </div>                      
                        </div>
        
                    </div>      
            </div>
        </section>
</body>
</html>

Following changes of ::before pseudo-element may work for you and you also have to add ::after pseudo-element for this solution.

.front::before {
      content: "";
      position: absolute;
      top: 0px;
      right: 0px;
      border-bottom-left-radius: 10px;
      height: 25px;
      width: 25px;
      background: #32a2d4;
}

.front::after {
    content: "";
    position: absolute;
    top: -11px;
    right: -15px;
    height: 25px;
    width: 35px;
    background: white;
    transform: rotate(40deg);
}


来源:https://stackoverflow.com/questions/50641793/firefox-css-border-radius-issue-for-pseudo-element-before

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!