html - 如何修复打开页面时按钮转换为带边框的自定义按钮?

标签 html css google-chrome atom-editor

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

我试过改变位置、过渡效果,但都不起作用。有什么想法吗?

这是我打开/刷新网页时按钮发生的情况: /image/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);
}

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

最佳答案

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

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>

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

关于html - 如何修复打开页面时按钮转换为带边框的自定义按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57054578/

相关文章:

css - 如何从我的网站 html 中删除空白区域

CSS,Chrome 和其他浏览器中的字体

javascript - 如何在 Javascript 中使用计算器在文本字段中显示值

css - 我在 phonegap 中的 HTML 按钮没有反应

javascript - 验证正在运行,但警报/消息未显示

html - 标题两侧的 Ionic 2 导航栏图标

jquery - 将动画添加到 div 中的其中一张图像

asp.net - 如何在 Chrome 中编辑 .aspx 页面

css - 平板电脑样式表中的 Google Chrome 打印

javascript - Vanilla NG2 组件未显示?