twitter-bootstrap 将鼠标悬停在引导按钮上时不要更改 CSS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14948984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 16:25:10  来源:igfitidea点击:

Do not change CSS when hover over bootstrap button

jquerycsstwitter-bootstrap

提问by Zaki Aziz

I am using a btn-grouplike this: http://jsfiddle.net/dy9uH/34/

我正在使用btn-group这样的:http: //jsfiddle.net/dy9uH/34/

I don't want my users to think the button to the left is click-able but don't like how the button looks when I add the disabledclass. How can I make sure nothing happens when a user hovers over the left button? I'd prefer not to edit bootstrap.css because I have other buttons that utilize the .btn-groupclass that I need functioning as usual.

我不希望我的用户认为左侧的按钮是可点击的,但不喜欢我添加disabled类时按钮的外观。当用户将鼠标悬停在左按钮上时,如何确保没有任何反应?我不想编辑 bootstrap.css 因为我有其他按钮使用.btn-group我需要像往常一样运行的类。

采纳答案by Arun P Johny

I think the only solution is to over ride the bootstrap styles with your custom changes.

我认为唯一的解决方案是使用您的自定义更改来覆盖引导程序样式。

  1. Add a custom class to the btnex: special
  2. Define the override style as follows in a custom css file
  3. Include the custom file in your page
  1. 将自定义类添加到btnex:special
  2. 在自定义css文件中定义覆盖样式如下
  3. 在您的页面中包含自定义文件

Css:

css:

.btn.special {
    background-color: #F5F5F5;
    color: #333333;
    background-image: linear-gradient(to bottom, #FFFFFF, #E6E6E6);
    text-decoration: none;
    background-position: 0;
    transition: none;
}

Demo: Fiddle

演示:小提琴

回答by Jon P

I'm going to assume you want to use disabled as well so the button is actually disabled. You will need to override some bootstrap

我将假设您也想使用 disabled ,因此该按钮实际上已禁用。您将需要覆盖一些引导程序

I would do the following

我会做以下

HTML

HTML

<div class="btn-group">
  <button class="btn special" disabled>I'm Special</button>
  <button class="btn dropdown-toggle" data-toggle="dropdown">
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu">
    <!-- dropdown menu links -->
  </ul>
</div>

CSS

CSS

.special,
.special.disabled,
.special[disabled] 
.special.disabled:hover,
.special[disabled]:hover,
.special.disabled:focus,
.special[disabled]:focus {
  display: inline-block;
  *display: inline;
  padding: 4px 12px;
  margin-bottom: 0;
  *margin-left: .3em;
  font-size: 14px;
  line-height: 20px;
  color: #333333;
  text-align: center;
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
  vertical-align: middle;
  cursor: pointer;
  background-color: #f5f5f5;
  *background-color: #e6e6e6;
  background-image: -moz-linear-gradient(top, #ffffff, #e6e6e6) !important;
  background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#e6e6e6)) !important;
  background-image: -webkit-linear-gradient(top, #ffffff, #e6e6e6) !important;
  background-image: -o-linear-gradient(top, #ffffff, #e6e6e6) !important;
  background-image: linear-gradient(to bottom, #ffffff, #e6e6e6) !important;
  background-repeat: repeat-x !important;
  opacity: 1 !important;
  filter: alpha(opacity=100) !important;
     background-position: 0 0;
  -webkit-transition:none;
     -moz-transition:none;
       -o-transition: none;
          transition: none;
  border: 1px solid #cccccc;
  *border: 0;
  border-color: #e6e6e6 #e6e6e6 #bfbfbf;
  border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
  border-bottom-color: #b3b3b3;
  -webkit-border-radius: 4px;
     -moz-border-radius: 4px;
          border-radius: 4px;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffe6e6e6', GradientType=0);
  filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
  *zoom: 1;
  -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
     -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
          box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
}

Note the disabledselectors.

注意disabled选择器。

HOWEVERit should come as a surprise to no one that this is only partially supported in IE!

然而,IE 仅部分支持这对任何人来说都应该不足为奇!

Fiddle

小提琴

回答by Sebastian Uriel Murawczik

Well, you can add a class to that particular button, so that it doesn't crash with others, and rewrite the disabled class, that would be the easiest way.

好吧,您可以向该特定按钮添加一个类,这样它就不会与其他按钮崩溃,并重写禁用的类,这将是最简单的方法。