【问题标题】:Placing correctly formatted image behind a Hover Button CSS Animation在悬停按钮 CSS 动画后面放置正确格式的图像
【发布时间】:2018-02-09 00:14:46
【问题描述】:

我目前正在尝试将图像放在我想与按钮一起使用的 CSS 悬停动画后面。

成品应如下所示: Mock Up of Finished Product

任何尝试正确插入和格式化这样的背景的帮助将不胜感激,因为我一直在尝试插入图像时遇到死胡同。

到目前为止,这是我一直在使用的。

@import "bourbon";

* {
	-webkit-transition-property: all;
	-webkit-transition-duration: .2s;
  -moz-transition-timing-function: cubic-bezier(100,50,21,6);
	-moz-transition-property: all;
	-moz-transition-duration: .2s;
  -moz-transition-timing-function: cubic-bezier(100,50,21,6);
}
h1{  font-family: calibri;
  color:#FFFFFF;
  font-size: 20px;
  text-align: center;
}
body {
  background-color: #613f4d;
  padding-top: 70px;
  font-family: 'Open Sans', calibri;
  text-align: center;
  font-weight: 100;
}


.btn {
  position: relative;
  display: inline-block;
  width: 166px;
  height: 45px;
  font-size: 17px;
  line-height: 45px;
  text-align: center;
  text-transform: uppercase;
  color: #fff;
  cursor: pointer;
  overflow: hidden;
}
.btn svg {
  position: absolute;
  top: 0; left: 0;
}
.btn svg rect {
  fill: none;
  stroke: #fff;
  stroke-width: 1;
  stroke-dasharray: 422, 0;
  
  @include transition(all 1300ms $ease-out-expo);
}
.btn:hover svg rect {
  stroke-width: 5;
  stroke-dasharray: 10, 310;
  stroke-dashoffset: 33;
}

.btn:hover {
  color:#fff;
  font-size:18px;
  letter-spacing:1px;
  font-weight:bold;
}
<link href='https://fonts.googleapis.com/css?family=Oswald:300' rel='stylesheet' type='text/css'>

<h1>Find out more about our</h1>
<div class="btn">
  <svg>
    <rect x="0" y="0" fill="none" width="166" height="45"/>
  </svg>
 Company
</div>

【问题讨论】:

  • 您的要求是将上面的sn-p更改为您共享的图像。对吗?
  • @LibinCJacob 是的,我想将上面的 sn-p 放在图像顶部,如我创建的模型图像所示。

标签: html css image background hover


【解决方案1】:

我认为您期望如此处所示。请检查一下。

@import "bourbon";

* {
	-webkit-transition-property: all;
	-webkit-transition-duration: .2s;
  -moz-transition-timing-function: cubic-bezier(100,50,21,6);
	-moz-transition-property: all;
	-moz-transition-duration: .2s;
  -moz-transition-timing-function: cubic-bezier(100,50,21,6);
}
h1{  font-family: calibri;
  color:#FFFFFF;
  font-size: 20px;
  text-align: center;
}
body {
  background-color: #613f4d;
  padding-top: 70px;
  font-family: 'Open Sans', calibri;
  text-align: center;
  font-weight: 100;
}


.btn {
  position: relative;
  display: inline-block;
  width: 166px;
  height: 45px;
  font-size: 17px;
  line-height: 45px;
  text-align: center;
  text-transform: uppercase;
  color: #fff;
  cursor: pointer;
  overflow: hidden;
}
.btn svg {
  position: absolute;
  top: 0; left: 0;
}
.btn svg rect {
  fill: none;
  stroke: #fff;
  stroke-width: 1;
  stroke-dasharray: 422, 0;
  
  @include transition(all 1300ms $ease-out-expo);
}
.btn:hover svg rect {
  stroke-width: 0;
}

.btn:hover .heading {
display:none;
}

    
    .bg {
  position: fixed;
  z-index: -1;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  transition: .25s;
  pointer-events: none;
}

.btn :hover ~ .bg {
  //background: #ff6d6d;
   background-image: url("https://i.stack.imgur.com/WpFwN.png");
   background-repeat: no-repeat;
   background-size: 100% 100%;
}
<link href='https://fonts.googleapis.com/css?family=Oswald:300' rel='stylesheet' type='text/css'>

<h1 class="heading">Find out more about our</h1>
<div class="btn">
  <svg>
    <rect x="0" y="0" fill="none" width="166" height="45"/>
  </svg>
 <div class="heading"> Company</div>
 <div class="bg">
 </div>
</div>

【讨论】:

    猜你喜欢
    • 2020-04-28
    • 1970-01-01
    • 1970-01-01
    • 2019-07-15
    • 2022-09-23
    • 2012-02-09
    • 2019-09-01
    • 1970-01-01
    • 2016-12-06
    相关资源
    最近更新 更多