css - 背景颜色的文本透明问题

标签 css

我正在制作一个按钮,我想实现一种您可以在此处看到的有趣效果。

enter image description here

问题是,当我悬停在文本 rgba(0,0,0,0.0); 上时,所有按钮都变成白色,甚至是文本。

到目前为止,这是我的代码:

.button{
    height: 40px;
    border-radius: 5px;
    border: 2px solid #fff;
    text-align: center;
    font-size: 16px;
    color: #fff;
    line-height: 2.4em;
    cursor: pointer;
}

.button:hover{
    background: #fff;
    color: rgba(0,0,0,0.0)
}

最佳答案

原因是因为你的悬停color:设置为透明,所以当然会是白色。尝试如下更简单的方法:

.button {
  color: blue;
  background: white;
  padding: 5px 10px;
  border: 3px solid blue;
  border-radius: 5px;
  text-decoration: none;
  transition: all 0.3s;
}
.button:hover {
  color: white;
  background: blue;
}
<a href="alink.html" class="button">button</a>

关于css - 背景颜色的文本透明问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27935995/

相关文章:

html - 图片隐藏文字,需要不同行

css - SASS SCSS函数生成具有动态路径的类

javascript - 使用tab键后无法滚动到顶部

css - 当呈现一个组件时,从HTML隐藏空白/HTML溢出以在Router中同级div的HTML中?

javascript - 当用户滚动位置到达它时将 javascript 加载到 div

javascript - jQuery 旋转器旋转不正确 - 太多递归

php - 使用动态框架调整图像大小

javascript - 自动单击 slider 上的元素符号以使所有幻灯片自动播放 slider

javascript - JS/jQuery 从 Wordpress 导航创建移动导航

javascript - NightWatch.js - 根据相关的 css 定位器获取子 WebElements 列表