How to enable Bootstrap tooltip on disabled button?

后端 未结 18 2353
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 23:18

I need to display a tooltip on a disabled button and remove it on an enabled button. Currently, it works in reverse.

What is the best way to invert this behaviour?

18条回答
  •  有刺的猬
    2020-11-29 00:03

    You can imitate the effect using CSS3.

    Simply take the disabled state off the button and the tooltip doesn't appear anymore.. this is great for validation as the code requires less logic.

    I wrote this pen to illustrate.

    CSS3 Disabled Tooltips

    [disabled] {
      &[disabled-tooltip] {
        cursor:not-allowed;
        position: relative;
        &:hover {
          &:before {
            content:'';
            border:5px solid transparent;
            border-top:5px solid black;
            position: absolute;
            left: 50%;
            transform: translate(-50%, calc(-100% + -5px));
          }
          &:after {
            content: attr(disabled-tooltip);
            position: absolute;
            left: 50%;
            transform: translate(-50%, calc(-100% + -15px));
            width:280px;
            background-color:black;
            color:white;
            border-radius:5px;
            padding:8px 12px;
            white-space:normal;
            line-height:1;
          }
        }
      }
    }
    

    
    

提交回复
热议问题