【问题标题】:Unexpected space between spans跨度之间的意外空间
【发布时间】:2021-05-26 19:15:02
【问题描述】:

我用变换和过渡构建了这个按钮。但是有一个小问题我无法弄清楚。当我想悬停链接时,我必须使用 span 来缩放它们。每个跨度有 25% 的链接宽度。但在 3 号和 4 号跨度之间有一个很小的空间。

codepen link

    body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: sans-serif;
    }

    a {
    font-size: 25px;
    font-weight: 700;
    display: block;
    text-decoration: none;
    border: 3px solid rgb(84, 7, 136);
    color: rgb(84, 7, 136);
    padding: 50px 80px;
    position: relative;
    overflow: hidden;
    }
    h2 {
    text-align: center;
    }
    body > div {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    }
            .effect11 a span {
    position: absolute;
    top: 0;
    left: 0;
    width: 25%;
    height: 100%;
    background-color: black;
    transform: scaleY(0);
    transform-origin: top;
    transition: all 1s;
    z-index: -1;
    }
    .effect11 a {
    transition: all 1s;
    }

    .effect11 a span:nth-child(1) {
    left: 0;
    transition-delay: 0.15s;
    }
    .effect11 a span:nth-child(2) {
    left: 25%;
    transition-delay: 0.3s;
    }
    .effect11 a span:nth-child(3) {
    left: 50%;
    transition-delay: 0.45s;
    }
    .effect11 a span:nth-child(4) {
    left: 75%;
    transition-delay: 0.6s;
    }

    .effect11 a:hover span {
    transform: scaleY(1);
    }
    .effect11 a:hover {
    color: white;
    }

This is what happening that I don't want to appear (that little space)

【问题讨论】:

  • 在 Windows 机器上的 Chrome 和 Firefox 中运行良好。你用的是什么浏览器?
  • 很确定你的问题是你的文本“悬停我”。它弄乱了 列。
  • 我在 chrome 和 firefox 上测试并得到相同的结果

标签: css css-transitions transform


【解决方案1】:

在这里添加 flex:1 应该可以解决问题

body > div {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex:1;
    }

【讨论】:

  • 有线的。这不起作用,但是当我减小浏览器的大小时,它没有任何问题! (没有 flex:1 )。我不知道为什么这会发生在最大化。顺便说一句,当我在 codepen 中给它 flex:1 时它会起作用!!!!
  • 好吧,当我可以用 codepen 检查我的代码时,它可以工作,所以我不知道是什么导致了不同浏览器中的问题。
猜你喜欢
  • 2020-02-12
  • 2011-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-06
  • 1970-01-01
  • 2011-05-18
  • 2023-03-26
相关资源
最近更新 更多