首页 > 解决方案 > 页面打开时如何修复按钮转换为带边框的自定义按钮?

问题描述

我的目标是,当我将鼠标悬停在按钮上时,背景颜色会淡入,但是当我的鼠标移出按钮时,我希望背景颜色会淡出。所以我通过在 CSS 中为 button 和 button:hover 插入 transition 属性来做到这一点,以便它淡入淡出。我的下拉菜单上也有相同的按钮,可以产生相同的效果。顺便说一句,我在 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);
}

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

标签: htmlcssgoogle-chromeatom-editor

解决方案


在您的 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>


推荐阅读