【问题标题】:CSS: safari animation issueCSS:野生动物园动画问题
【发布时间】:2020-08-29 10:43:42
【问题描述】:

发帖前,我已阅读:

好的,我正在构建一个 css 按钮,一些问题只在 Safari 中出现。

  • 如果你在 Chrome 中运行 sn-ps,它会完全符合我的预期。

  • 如果你在 Safari 中运行这个,span 效果就不好用了。

body{
  margin: 0;
  padding: 0;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(-30deg,#1ec4e9 0%,#673ab7 50%,#262626 50%,#607d8b 100%);
}

a{
  position: relative;
  padding: 25px 50px;
  text-decoration: none;
  color: #fff;
  font-size: 2em;
  text-transform: uppercase;
  font-family: sans-serif;
  letter-spacing: 4px;
  overflow: hidden;
  background: rgba(255,255,255,.1);
  box-shadow: 0 5px 5px rgba(0,0,0,.2);
}

a::before{
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  background: rgba(255,255,255,.1);
}

a::after{
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg,transparent,rgba(255,255,255,.4),transparent);
  transition: 0.5s;
}

a:hover::after{
  left: 100%;
}

a span{
  position: absolute;
  display: block;
  transition: 0.5s ease;
}

a span:nth-child(1){
  top: 0;
  left: 0;
  width: 0;
  height: 1px;
  background: #fff;
}

a:hover span:nth-child(1){
  width: 100%;
  transform: translateX(100%);
}

a span:nth-child(3){
  bottom: 0;
  right: 0;
  width: 0;
  height: 1px;
  background: #fff;
}

a:hover span:nth-child(3){
  width: 100%;
  transform: translateX(-100%);
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <a href='#'>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    Button
  </a>

</body>
</html>

我已尝试添加浏览器支持,例如:

    -webkit-transform: translateX(-100%);
    -o-transform: translateX(-100%);
    -ms-transform: translateX(-100%);
    -moz-transform: translateX(-100%);

但它仍然不起作用。有人可以提供一些建议,我希望 Safari 给出与 chrome 相同的结果。


更新

自从我尝试以来,这一定是一个优先问题:

body{
  margin: 0;
  padding: 0;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(-30deg,#1ec4e9 0%,#673ab7 50%,#262626 50%,#607d8b 100%);
}

a{
  position: relative;
  padding: 25px 50px;
  text-decoration: none;
  color: #fff;
  font-size: 2em;
  text-transform: uppercase;
  font-family: sans-serif;
  letter-spacing: 4px;
  overflow: hidden;
  background: rgba(255,255,255,.1);
  box-shadow: 0 5px 5px rgba(0,0,0,.2);
}

a::before{
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  background: rgba(255,255,255,.1);
}

a::after{
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg,transparent,rgba(255,255,255,.4),transparent);
  -webkit-transition: 2s;
}

a:hover::after{
  left: 100%;
}

a span{
  position: absolute;
  display: block;
  -webkit-transition: 2s ease;
}

a span:nth-child(1){
  position: relative;
  top: 0;
  left: 0;
  width: 0;
  height: 1px;
  background: #fff;
}

a:hover span:nth-child(1){
  width: 100%;
  -webkit-transform: translateX(100%);
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <a href='#'>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    Button
  </a>

</body>
</html>

【问题讨论】:

标签: css button webkit transform


【解决方案1】:

按照你为你的影子制作的方式(在::after中),使用leftright

a:hover span:nth-child(1){
  width: 100%;
  /*-webkit-transform: translateX(100%);*/
  left:100%;
}

a:hover span:nth-child(3){
  width: 100%;
  /*transform: translateX(-100%);*/
  right: 100%;
}

演示(一):

body{
  margin: 0;
  padding: 0;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(-30deg,#1ec4e9 0%,#673ab7 50%,#262626 50%,#607d8b 100%);
}

a{
  position: relative;
  padding: 25px 50px;
  text-decoration: none;
  color: #fff;
  font-size: 2em;
  text-transform: uppercase;
  font-family: sans-serif;
  letter-spacing: 4px;
  overflow: hidden;
  background: rgba(255,255,255,.1);
  box-shadow: 0 5px 5px rgba(0,0,0,.2);
}

a::before{
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  background: rgba(255,255,255,.1);
}

a::after{
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg,transparent,rgba(255,255,255,.4),transparent);
  transition: 0.5s;
}

a:hover::after{
  left: 100%;
}

a span{
  position: absolute;
  display: block;
  transition: 0.5s ease;
}

a span:nth-child(1){
  top: 0;
  left: 0;
  width: 0;
  height: 1px;
  background: #fff;
}

a:hover span:nth-child(1){
  width: 100%;
  /*transform: translateX(100%);*/
  left: 100%;
}

a span:nth-child(3){
  bottom: 0;
  right: 0;
  width: 0;
  height: 1px;
  background: #fff;
}

a:hover span:nth-child(3){
  width: 100%;
  /*transform: translateX(-100%);*/
  right: 100%;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <a href='#'>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    Button
  </a>

</body>
</html>

演示(更新):

body{
  margin: 0;
  padding: 0;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(-30deg,#1ec4e9 0%,#673ab7 50%,#262626 50%,#607d8b 100%);
}

a{
  position: relative;
  padding: 25px 50px;
  text-decoration: none;
  color: #fff;
  font-size: 2em;
  text-transform: uppercase;
  font-family: sans-serif;
  letter-spacing: 4px;
  overflow: hidden;
  background: rgba(255,255,255,.1);
  box-shadow: 0 5px 5px rgba(0,0,0,.2);
}

a::before{
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  background: rgba(255,255,255,.1);
}

a::after{
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg,transparent,rgba(255,255,255,.4),transparent);
  -webkit-transition: 2s;
}

a:hover::after{
  left: 100%;
}

a span{
  position: absolute;
  display: block;
  -webkit-transition: 2s ease;
}

a span:nth-child(1){
  position: relative;
  top: 0;
  left: 0;
  width: 0;
  height: 1px;
  background: #fff;
}

a:hover span:nth-child(1){
  width: 100%;
  /*-webkit-transform: translateX(100%);*/
  left:100%;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <a href='#'>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    Button
  </a>

</body>
</html>

【讨论】:

    猜你喜欢
    • 2012-07-20
    • 2018-06-18
    • 1970-01-01
    • 2018-11-27
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    • 1970-01-01
    相关资源
    最近更新 更多