悬停时有角度的背景(三角形)按钮

时间:2017-08-18 14:34:15

标签: html css

我有以下css / html,它会使'回到顶部'窗口右下角的按钮。当盘旋过来时,背景会在背后动画。

代码工作正常,但我试图用三角形代替它。它将位于右下角,背景将以动画的形式呈现,但是在一个角度而不是直线上升。



#top-btn {
  position: fixed;
  margin: 0;
  padding: 0;
  display: block;
  bottom: 0;
  right: 0;
  z-index: 900;
}

#top-btn a,
#top-btn-BG {
  position: absolute;
  right: 0;
  margin: 0;
}

#top-btn a {
  z-index: 999;
  padding: 34px 35px;
  color: #707070;
  bottom: 0;
}

#top-btn-BG {
  z-index: 950;
  height: 75px;
  width: 75px;
  background-color: #333;
  bottom: -75px;
  -webkit-transition: bottom 0.35s ease;
  -moz-transition: bottom 0.35s ease;
  -ms-transition: bottom 0.35s ease;
  -o-transition: bottom 0.35s ease;
  transition: bottom 0.35s ease;
}

#top-btn a:hover {
  color: #fff;
}

#top-btn a:hover+#top-btn-BG {
  bottom: 0px;
}

<div id="top-btn" class="flex">
  <a href="javascript:void(0);" onclick="scrolltop();"> button </a>
  <div id="top-btn-BG"></div>
</div>
&#13;
&#13;
&#13;

我希望在悬停在

上时,右下角三角形看起来像这样

enter image description here

3 个答案:

答案 0 :(得分:0)

只需使用简单的css三角形生成器即可。 http://apps.eky.hk/css-triangle-generator/

答案 1 :(得分:0)

您可以将几个border属性用于几何形状。

这是一个例子的小提琴:

https://jsfiddle.net/gsep39po/

答案 2 :(得分:0)

您可以使用pseudo selector ::before在顶部设置新三角形的样式

#top-btn-BG:before {
  content: "";
  position: absolute;
  border: 40px solid #333;
  border-top: 40px solid transparent;
  border-bottom: 40px solid #333;
  border-left: 40px solid transparent;
  border-right: 40px solid transparent;
  bottom: 100%;
  right: -4px;
}

&#13;
&#13;
#top-btn {
  position: fixed;
  margin: 0;
  padding: 0;
  display: block;
  bottom: 0;
  right: 0;
  z-index: 900;
}

#top-btn a,
#top-btn-BG {
  position: absolute;
  right: 0;
  margin: 0;
}

#top-btn a {
  z-index: 999;
  padding: 34px 35px;
  color: #707070;
  bottom: 0;
}

#top-btn-BG {
  z-index: 950;
  height: 75px;
  width: 75px;
  background-color: #333;
  bottom: -130px;
  -webkit-transition: bottom 0.35s ease;
  -moz-transition: bottom 0.35s ease;
  -ms-transition: bottom 0.35s ease;
  -o-transition: bottom 0.35s ease;
  transition: bottom 0.35s ease;
  right: 0px;
}

#top-btn-BG:before {
  content: "";
  position: absolute;
  border: 40px solid #333;
  border-top: 40px solid transparent;
  border-bottom: 40px solid #333;
  border-left: 40px solid transparent;
  border-right: 40px solid transparent;
  bottom: 100%;
  right: -4px;
}

#top-btn a:hover {
  color: #fff;
}

#top-btn a:hover + #top-btn-BG {
  bottom: 0px;
}
&#13;
<div id="top-btn" class="flex">
  <a href="javascript:void(0);" onclick="scrolltop();"> button </a>

  <div id="top-btn-BG"></div>
</div>
&#13;
&#13;
&#13;