【问题标题】:Add line transition above and below text在文本上方和下方添加行过渡
【发布时间】:2015-06-21 03:20:49
【问题描述】:

这个问题是my previous question 的后续问题。
我有一些来自this website 的样式,用于创建带下划线效果的幻灯片,请参阅此jsfiddle 上的示例。 我之前的问题是询问如何调整这一点,以便该行从右到左进入,并在文本顶部,请参阅此 jsfiddle 上的示例。

我的下一步是将这两个都添加到一个元素中,因此一条线在底部从左到右滑入,另一条在顶部从右到左滑入。

当我尝试将这两个加在一起时,它似乎只显示最上面的一个,请看这个jsfiddle

我的问题是如何将顶部幻灯片和底部幻灯片添加到元素中?

.cmn-t-underline {
  position: relative;
  color: #ff3296;
}
.cmn-t-underline:after {
  display: block;
  position: absolute;
  left: 0;
  bottom: -10px;
  width: 0;
  height: 10px;
  background-color: #2E9AFE;
  content: "";
  -webkit-transition: all 0.3s;
  -moz-transition: all 0.3s;
  -o-transition: all 0.3s;
  transition: all 0.3s;
  height:2px;
}
.cmn-t-underline:hover {
  color: #98004a;
}
.cmn-t-underline:hover:after {
  width: 100%;
	height:2px;
}

.cmn-t-overline {
  position: relative;
  color: #ff3296;
}
.cmn-t-overline:after {
  display: block;
  position: absolute;
  right: 0;
  top: -10px;
  width: 0;
  height: 10px;
  background-color: #2E9AFE;
  content: "";
  -webkit-transition: all 0.3s;
  -moz-transition: all 0.3s;
  -o-transition: all 0.3s;
  transition: all 0.3s;
  height:2px;
}
.cmn-t-overline:hover {
  color: #98004a;
}
.cmn-t-overline:hover:after {
  width: 100%;
	height:2px;
}
<h1 class="cmn-t-underline cmn-t-overline">Test</h1>

【问题讨论】:

    标签: html css css-transitions


    【解决方案1】:

    您必须使用:before 作为您的顶线,并使用:after 作为您的底线。 你这样做的方式第二个“:after”覆盖了第一个,所以你最终只有一行。

    我已经编辑了你的 jsFiddle : http://jsfiddle.net/7k4rLdno/

    我只用:before 更改了第二个:after,一切正常。

    您不能有两个 :after 或两个 :before 完全相同的元素。

    【讨论】:

      【解决方案2】:

      使用

      :before - 顶行

      :after - 底线

      h1{
          position: relative;
          color: #ff3296;
      }
      h1:before, 
      h1:after {
          display: block;
          position: absolute;
          width: 0;
          height: 10px;
          background-color: #2E9AFE;
          content:"";
          -webkit-transition: all 0.3s;
          -moz-transition: all 0.3s;
          -o-transition: all 0.3s;
          transition: all 0.3s;
          height:2px;
      }
      h1:before {
          left: 0;
          top: -10px;
      }
      h1:after {
          right: 0;
          bottom: -10px;
      }
      h1:hover {
          color: #98004a;
      }
      h1:hover:after, 
      h1:hover:before {
          width: 100%;
          height:2px;
      }
      <h1>Test</h1>

      Fiddle

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-16
        • 1970-01-01
        • 2021-12-10
        • 2019-01-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多