CSS outline 移除默认

CSS outline1 个文件更新于 2026-04-06
html公开前 25 行,完整代码需登录
<html>
  <head>
    <meta charset="utf-8">
    <title>移除默认 outline</title>
    <style>
      /* 移除所有元素的默认 outline */
      * {
        outline: none;
      }
      
      /* 更好的做法:只在非焦点状态移除,焦点时保留 */
      .custom-button {
        padding: 10px 20px;
        background-color: #0066ff;
        color: white;
        border: none;
        border-radius: 4px;
        cursor: pointer;
      }
      
      /* 移除默认 outline */
      .custom-button:focus {
        outline: none;
        /* 使用其他方式表示焦点,如阴影 */
        box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.3);

登录后可以查看完整源码、在线编辑并实时预览运行效果。