打开页面时如何解决将按钮转换为带有边框的自定义按钮的问题?

时间:2019-07-16 09:53:27

标签: html css google-chrome atom-editor

我的目标是,当我将鼠标悬停在按钮上时,背景色会逐渐淡入,但是当鼠标移出按钮时,我希望背景色会逐渐消失。 因此,我通过在CSS中为button和button:hover插入过渡属性来使其淡入和淡出来实现这一点。我的下拉菜单上也有相同的按钮,可以产生相同的效果。顺便说一下,我是在Atom上执行的,在Atom的预览浏览器包中似乎没有问题。

我尝试更改位置,过渡效果,但均无效果。有什么想法吗?

这是我打开/刷新网页时按钮发生的情况: https://i.stack.imgur.com/uYTvB.gif

HTML:

<button onclick="location.href='Contact.html';" type="button">Book an Appointment <i class="fa fa-angle-right"></i></button>

CSS:

button {
    cursor: pointer;
    background:none;
    color: white;
    border: 1px solid orange;
    border-radius: 20px;
    padding: 10px 24px;
    font-size: 13px;
    text-transform: uppercase;
    position: absolute;
    top: 52%;
    left: 42%;
    text-align: center;
    font-family: "Gotham";
    font-weight: bold;
    letter-spacing: 1px;
    transition: all 1s ease-out;
}

button:hover {
  transition: all .5s ease-in;
  background: rgba(204, 204, 204, 0.5);
}

我希望当第一次打开或刷新网页时鼠标悬停而没有任何动画时,按钮的背景色会淡入和淡出。

2 个答案:

答案 0 :(得分:0)

在CSS中添加了一些更改

<button onclick="location.href='Contact.html';" type="button">Book an Appointment <i class="fa fa-angle-right"></i></button>

button {
    cursor: pointer;
    background:none;
    color: white;
    border: 1px solid orange;
    border-radius: 20px;
    padding: 10px 24px;
    font-size: 13px;
    text-transform: uppercase;
    position: absolute;
    text-align: center;
    font-family: "Gotham";
    font-weight: bold;
    letter-spacing: 1px;
    transition: all 1s;
}

button:hover {
  transition: all .5s ease-in;
  background: rgba(204, 204, 204, 0.5);
}

button {
    cursor: pointer;
    background:none;
    color: white;
    border: 1px solid orange;
    border-radius: 20px;
    padding: 10px 24px;
    font-size: 13px;
    text-transform: uppercase;
    position: absolute;
    text-align: center;
    font-family: "Gotham";
    font-weight: bold;
    letter-spacing: 1px;
    transition: all 1s;
}

button:hover {
  transition: all .5s ease-in;
  background: rgba(204, 204, 204, 0.5);
}
<button onclick="location.href='Contact.html';" type="button">Book an Appointment <i class="fa fa-angle-right"></i></button>

答案 1 :(得分:0)

它工作正常,您的代码没有任何问题

button {
    cursor: pointer;
    background:none;
    color: black;
    border: 1px solid orange;
    border-radius: 20px;
    padding: 10px 24px;
    font-size: 13px;
    text-transform: uppercase;
    text-align: center;
    font-family: "Gotham";
    font-weight: bold;
    letter-spacing: 1px;
}

.with{  
    transition: all 0.5s ease-out;
}

.with:hover {
  transition: all .5s ease-in;
  background: rgba(110, 120, 90, 0.5);
}


.without:hover {
  background: rgba(110, 120, 90, 0.5);
}
<button class="with" onclick="location.href='Contact.html';" type="button" >With Animation<i class="fa fa-angle-right"></i></button>

<button class="without" onclick="location.href='Contact.html';" type="button" >Without Animation<i class="fa fa-angle-right"></i></button>

如果您不需要动画,只需从transition删除css属性