【问题标题】:How to fix button transforming to custom button with border when page open?页面打开时如何修复按钮转换为带边框的自定义按钮?
【发布时间】:2019-07-22 16:56:56
【问题描述】:

我的目标是,当我将鼠标悬停在按钮上时,背景颜色会淡入,但是当我的鼠标移出按钮时,我希望背景颜色会淡出。 所以我通过在 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);
}

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

【问题讨论】:

  • 请不要仅仅因为解决了问题就删除内容...这个问题不太有用,不仅因为您的编辑,还因为您删除了 cmets。

标签: html css google-chrome atom-editor


【解决方案1】:

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

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 属性

【讨论】:

  • 您在项目中使用animate.css 吗?因为我的chrome 没有任何问题,就像你提到的那样,它在加载时没有动画。
  • 也可以试试其他浏览器,其实没问题,但如果客户端想要像素完美,那似乎是个问题。无论如何做一个没有css的简单页面并在chrome中测试它
  • 再做一件事,创建一个新的index.html 文件并将您的button 代码放在那里并在chrome 中进行测试。它保持不变,那么你必须考虑铬。如果没有,那么其他一些 cssjs 库正在为您制作该动画
  • 所以您是说没有外部或内部css 引用,没有js 引用,您仍然面临同样的问题吗?那么它与浏览器有关。但是做一件事,transition : 0.5s ease-out 并再次刷新
  • 对不起,哥们,我已经尝试在 html 页面中使用一个简单的按钮,但仍然没有遇到这个问题。我的 chrome 版本是Version 75.0.3770.142 (Official Build) (64-bit)
【解决方案2】:

在您的 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);
}
&lt;button onclick="location.href='Contact.html';" type="button"&gt;Book an Appointment &lt;i class="fa fa-angle-right"&gt;&lt;/i&gt;&lt;/button&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 2015-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多