Css在所选元素上设置延迟:悬停

时间:2018-01-29 21:38:39

标签: html css css3 text hover

我有一个盒子和一些东西'按钮,只要有人在“一个人”的位置上盘旋。 div元素的高度增加,一些文本出现,问题是文本在将鼠标悬停在元素上后立即出现,但是当发生这种情况时它看起来很难看,因为文本基本上是无处不在的,当用户停止时也是如此悬停在元素上。我希望文本外观有一个延迟,就像div发生的那样。

HTML和CSS:



body {
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  background-color: #f2f2f2;
}

.events {
  padding: 20px 100px;
}

.textInfo {
  text-transform: uppercase;
  font-weight: 600;
  color: #085DAD;
  padding: 10px;
  background-color: white;
}

.onebyone {
  background-color: grey;
  width: 100%;
  padding-top: 100%;
  position: relative;
  background-size: cover;
}

.onebytext {
  position: absolute;
  top: 10px;
  left: 0;
  bottom: 0;
  right: 0;
  text-align: center;
  font-size: 32px;
  color: white;
  width: 90%;
  left: 5%;
}

.onebysign {
  position: absolute;
  left: 0;
  bottom: 0;
  right: 0;
  height: 60px;
  text-align: center;
  font-size: 20px;
  background-color: white;
  font-size: 24px;
  transition: height 1s;
}

.onebytext,
.onebysign {
  position: absolute;
  text-align: center;
  color: white;
}

.onebysign:hover {
  height: 300px;
}

.onebyform {
  left: 0;
  right: 0;
  bottom: 0;
  position: absolute;
}

.submitBtn {
  background-color: #0099CC;
  text-transform: uppercase;
  padding: 10px;
  border-radius: 50px;
  border: 0px;
  width: 70%;
  margin: 10px 0;
}

.onebysign:before {
  content: "";
  height: 30px;
  width: 100%;
  position: absolute;
  background: linear-gradient(to top right, white 47%, transparent 50%);
  left: 0;
  top: -30px;
}

.signText {
  display: none;
  color: black;
  font-size: 18px;
  padding: 10px 20px;
  font-weight: 600;
  text-align: center;
  max-width: 400px;
}

.onebysign:hover .signText {
  transition-delay: 1s;
  display: inline-block;
}

<div class="row events">
  <div class="onebyone">
    <div class="onebytext">
      <div class="textInfo">Test</div>
    </div>
    <div class="onebysign">
      <span class="signText">This is a sample text. It looks pretty good now, but the longer you make the text, the more ugly it looks...</span>
      <form class="onebyform" action="<?php echo get_permalink(); ?>">
        <button class="submitBtn">Something</button>
      </form>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:2)

你可以做很多事情。这是一个例子。

.onebysign {
  ...
  overflow: hidden;
}

.signText {
  opacity: 0;
  ...
}

.onebysign:hover .signText {
  ...
  opacity: 1;
}

Fiddle demo

答案 1 :(得分:1)

您似乎已在transition-delay元素上尝试了signText,这是一个正确方向的开始。

我们不会转换display属性,而是转换opacity属性。像这样:

&#13;
&#13;
body {
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  background-color: #f2f2f2;
}

.events {
  padding: 20px 100px;
}

.textInfo {
  text-transform: uppercase;
  font-weight: 600;
  color: #085DAD;
  padding: 10px;
  background-color: white;
}

.onebyone {
  background-color: grey;
  width: 100%;
  padding-top: 100%;
  position: relative;
  background-size: cover;
}

.onebytext {
  position: absolute;
  top: 10px;
  left: 0;
  bottom: 0;
  right: 0;
  text-align: center;
  font-size: 32px;
  color: white;
  width: 90%;
  left: 5%;
}

.onebysign {
  position: absolute;
  left: 0;
  bottom: 0;
  right: 0;
  height: 60px;
  color: #ffffff;
  text-align: center;
  font-size: 20px;
  background-color: white;
  font-size: 24px;
  transition: all 1s;
}

.onebytext,
.onebysign {
  position: absolute;
  text-align: center;
  color: white;
}

.onebysign:hover {
  height: 300px;
  color: #000000;
}

.onebyform {
  left: 0;
  right: 0;
  bottom: 0;
  position: absolute;
}

.submitBtn {
  background-color: #0099CC;
  text-transform: uppercase;
  padding: 10px;
  border-radius: 50px;
  border: 0px;
  width: 70%;
  margin: 10px 0;
}

.onebysign:before {
  content: "";
  height: 30px;
  width: 100%;
  position: absolute;
  background: linear-gradient(to top right, white 47%, transparent 50%);
  left: 0;
  top: -30px;
}

.signText {
  color: black;
  font-size: 18px;
  padding: 10px 20px;
  font-weight: 600;
  text-align: center;
  max-width: 400px;
  opacity: 0;
  transition: all linear 0.2s;
}

.onebysign:hover .signText {
  transition-delay: 1s;
  opacity: 1;
}
&#13;
<div class="row events">
  <div class="onebyone">
    <div class="onebytext">
      <div class="textInfo">Test</div>
    </div>
    <div class="onebysign">
      <span class="signText">This is a sample text. It looks pretty good now, but the longer you make the text, the more ugly it looks...</span>
      <form class="onebyform" action="<?php echo get_permalink(); ?>">
        <button class="submitBtn">Something</button>
      </form>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;