【问题标题】:How to disable Bootstraps button checkbox hover and focus effect?如何禁用 Bootstrap 按钮复选框悬停和焦点效果?
【发布时间】:2020-03-24 18:00:20
【问题描述】:

我正在使用 Bootstraps 按钮复选框:

https://getbootstrap.com/docs/4.1/components/buttons/#checkbox-and-radio-buttons

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
 <div class="btn-group btn-group-toggle" data-toggle="buttons">
      <label class="btn btn-outline-secondary active">
        <input type="checkbox" name="a" value="0"> SomeText1 </label>
      <label class="btn btn-outline-secondary active">
        <input type="checkbox" name="a" value="1"> SomeText2 </label>
    </div>	

但我正在努力禁用悬停和聚焦效果。我想这样做是因为悬停和焦点效果您无法分辨按钮/复选框的当前状态:https://jsfiddle.net/r2m1vzxo/1/

提前感谢您的帮助!

【问题讨论】:

  • 为什么不从label 中删除btn-outline-secondary 属性?
  • 因为那是我希望按钮具有的样式。删除后,我将失去检查/未检查功能。 link

标签: javascript html css twitter-bootstrap bootstrap-4


【解决方案1】:

如果我的理解是正确的,这是你需要的吗?

label.btn.btn-outline-secondary {
  color: #6c757d;
  background-color: transparent;
  outline: none !important;
  box-shadow: none !important;
}

label.btn.btn-outline-secondary.active {
  color: #fff;
  background-color: #6c757d;
}
<!doctype html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

  <title>Hello, world!</title>
</head>

<body>
  <h1>Hello, world!</h1>



  <div class="btn-group btn-group-toggle" data-toggle="buttons">
    <label class="btn btn-outline-secondary active">
        <input type="checkbox" name="a" value="0"> SomeText1 </label>
    <label class="btn btn-outline-secondary active">
        <input type="checkbox" name="a" value="1"> SomeText2 </label>
  </div>



  <!-- Optional JavaScript -->
  <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>

</html>

【讨论】:

  • 关闭,感谢您指出正确的方向!这就是我要找的东西:jsfiddle.net/v3c8o719
  • 很高兴我能给你2美分,干杯!我会为将来的目的更新答案:)
猜你喜欢
  • 2017-12-26
  • 2013-09-01
  • 2014-07-03
  • 2016-08-31
  • 1970-01-01
  • 1970-01-01
  • 2019-01-20
  • 2022-01-21
  • 2018-11-08
相关资源
最近更新 更多