【问题标题】:CSS button not maintaining focus formattingCSS按钮不保持焦点格式
【发布时间】:2021-08-23 17:46:45
【问题描述】:

我正在尝试制作两个按钮,其中一个聚焦时,另一个不聚焦。到目前为止,我有以下代码。

  .btn {
    border: none;
    display: inline-block;
    background-color: inherit;
    font-size: 10px;
    cursor: pointer;
    font-weight: 100;
    text-decoration: underline;
    color: blue;
  }

  .btn:focus {
    border: none;
    background-color: inherit;
    font-size: 10px;
    color: dimgrey;
    cursor: pointer;
    display: inline-block;
    font-weight: 100;
    text-decoration: none;
  }
<button onclick="this.disabled=true;document.getElementById('down7913').disabled=false;" type="submit" class="btn positive" name="up7913" id="up7913" >Full</button>|
<button onclick="this.disabled=true;document.getElementById('up7913').disabled=false;" type="submit" class="btn negative" name="down7913" id="down7913" >Short</button>

但是,只有在主动按下按钮时才会应用焦点格式。释放按钮后,立即应用未聚焦的格式。我知道 html 做了我想做的事(找到here)。那么如何让焦点格式保持不变呢? jsfiddle

【问题讨论】:

    标签: html css focus


    【解决方案1】:

    在 CSS 中尝试,

      .btn:focus, btn:active {
        border: none;
        background-color: inherit;
        font-size: 10px;
        color: dimgrey;
        cursor: pointer;
        display: inline-block;
        font-weight: 100;
        text-decoration: none;
      }
    

    或者,试试这个:

      .btn:disabled {
        border: none;
        display: inline-block;
        background-color: inherit;
        font-size: 10px;
        color: dimgrey;
        cursor: pointer;
        display: inline-block;
        font-weight: 100;
        text-decoration: none;
      }
    

    .btn:disabled 保证可以工作。

    【讨论】:

    • 好主意。但是,这不起作用。我只是在 jsfiddle 中尝试过。
    • @NikhilMishra 不可能,兄弟,你可能在那里做错了什么。它确实适用于我的浏览器,Chrome 的最新版本。
    • 尝试在我链接的 jsfiddle 中运行它。这绝对应该有效,但事实并非如此。这就是我感到困惑的原因。
    • @NikhilMishra 好的,我会努力让它工作,然后与你分享代码。
    • @NikhilMishra JS 有空位吗?
    猜你喜欢
    • 1970-01-01
    • 2011-04-22
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多