javascript - 如何避免图标按钮保持选中状态?
问题描述
我想学习如何在没有任何外部库(只是纯 css/html/js)帮助的情况下创建图标按钮,下面你会发现我的第一次失败尝试:
@font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url("fonts/icons.woff2");
}
.icons {
font-family: 'Material Icons';
font-size: 24px;
}
.icon-button {
border-radius: 5px;
border: 0;
color: #555;
cursor: pointer;
padding: 0;
text-decoration: none;
transition:
box-shadow .25s ease,
background .25s ease,
transform .25s ease;
background: #ffffffdd;
}
.icon-button:hover {
color: #e92e73ff;
box-shadow: 0px 0px 2px 0px rgba(0, 0, 0, 0.35);
}
.icon-button:active {
background: #ffffffaa;
box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.35);
transform: scale(0.9);
}
<!DOCTYPE html>
<html lang="en">
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="test.css">
</head>
<body>
<button class="icons icon-button">info</button>
</body>
</html>
如您所见,此尝试的问题在于单击后,该按钮将保持选中状态,并且周围有边界线,我想阻止这种情况。
例如,如果我决定使用 materializecss 来实现我想要的效果,就像这样做一样简单:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</head>
<body>
<a class="btn-floating btn-large waves-effect waves-light red"><i class="material-icons">add</i></a>
</body>
</html>
所以是的,我的问题......我怎样才能在不使用任何外部库的情况下达到类似的效果?
解决方案
您需要添加outline: none;
到button
.
通常, s 具有您需要覆盖的预定义样式,button
例如border
、和。background
font-family
outline
推荐阅读
- mongodb - mongo 中的 Match 和 Average 不断产生 null
- c# - .Net 核心 HttpClient 错误?SocketException:一个现有的连接被远程主机强行关闭
- sql-server - MS SQL Server,如何修复 table.column 跨所有应用程序的变化
- winapi - 如果电源重置,如何保护带有 Win32 API 的文件不被损坏?
- string - 将 pandas 列中的列表转换为字符串
- javascript - 基于 JSON 间隔更改页面内容
- c# - 由于 App.config 文件中的错误,SQLite 无法加载数据
- excel - 需要excel公式进行多行列查找
- python - Python kivy(kivymd)如何从MD存储和加载数据
- c# - WPF 打开文件并更新窗口