【问题标题】:How to put element over an hover CSS?如何将元素放在悬停 CSS 上?
【发布时间】:2018-06-13 10:16:51
【问题描述】:

我正在使用引导箭头面包屑。下面的图片会比我解释得更好:

带有正常/悬停/活动元素的面包屑:

面包屑问题,当活动元素和悬停元素更接近时箭头隐藏:

我想每次都保留箭头,我尝试了 z-index 但它不起作用:/

希望你能理解,谢谢帮助。

    $(document).ready(function() {
        $( ".btn-breadcrumb a" ).click(function() {
            $(".btn-breadcrumb a").removeClass("active");
            $(this).addClass("active");
        });
    });
 .btn-breadcrumb a{
    font-weight: bold;
    }

    .btn-breadcrumb a:hover {
    z-index: 1;
    }

    .btn-breadcrumb a.active {
        background-color: #95A5A6;
        color: #fff;
    }

    #breadcrumb_sauvegarde {
        background-color: #d9534f;
        color: #fff;
    }

    #breadcrumb_widget .btn-group{
        display: flex;
    }

    #breadcrumb_widget .btn-breadcrumb .btn {
        flex-grow: 1;
        text-align: center;
        position: relative;
    }

    /** Triangle Breadcrumb **/
    .btn-breadcrumb .btn:not(:last-child):after {
        content: " ";
        display: block;
        width: 0;
        height: 0;
        border-top: 22.4px solid transparent;
        border-bottom: 22.4px solid transparent;
        position: absolute;
        top: 50%;
        margin-top: -22.4px;
        left: 100%;
        z-index: 999;
    }

    /** Triangle Breadcrumb **/
    .btn-breadcrumb .btn:not(:last-child):before {
        content: " ";
        display: block;
        width: 0;
        height: 0;
        border-top: 22.4px solid transparent;
        border-bottom: 22.4px solid transparent;
        position: absolute;
        top: 50%;
        margin-left: 1px;
        margin-top: -22.4px;
        left: 100%;
        z-index: 999;
    }

    /**Spacing **/
    .btn-breadcrumb .btn {
        padding:12px 24px 12px 48px;
    }
    .btn-breadcrumb .btn:first-child {
        padding:12px 12px 12px 20px;
    }
    .btn-breadcrumb .btn:last-child {
        padding:12px 36px 12px 48px;
    }

    /** /////////////////////////// bouton triangle pour faire apparaitre le breadcrumb en flèche //////////////////////// **/

    /*couleur de fond du triangle*/
    .btn-breadcrumb .btn.btn-default:not(:last-child):after {
        border-left: 40px solid #fff;
    }
    /*couleur de fond du triangle hover*/
    .btn-breadcrumb .btn.btn-default:hover:not(:last-child):after {
        border-left: 40px solid #ecf0f1;
    }
    /*couleur de fond du triangle active*/
    .btn-breadcrumb .btn.btn-default.active:not(:last-child):after {
        border-left: 40px solid #95A5A6;
    }
    /*couleur de fond du triangle sur active hover*/
    .btn-breadcrumb .btn.btn-default.active:hover:not(:last-child):after {
        border-left: 40px solid #95A5A6;
    }
    /*couleur des bordures du triangle*/
    .btn-breadcrumb .btn.btn-default:not(:last-child):before {
        border-left: 40px solid #5e595d;
    }
    /*couleur des bordures du triangle sur hover*/
    .btn-breadcrumb .btn.btn-default:hover:not(:last-child):before {
        border-left: 40px solid #5e595d;
    }
 <!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</head>

<body>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" id="breadcrumb_widget">
        <div class="panel panel-default">
            <div class="btn-group btn-breadcrumb ">
                <a href="#" id="breadcrumb_configuration" class="btn btn-default active">1. Configuration</a>
                <a href="#" id="breadcrumb_formulaire" class="btn btn-default">2. Formulaire</a>
                <a href="#" id="breadcrumb_preview" class="btn btn-default">3. Preview</a>
                <a href="#" id="breadcrumb_sauvegarde" class="btn btn-default">4. Sauvegarder</a>
            </div>
        </div>
    </div>
</body>

</html>

【问题讨论】:

  • 看起来像一个 z-index 问题...也许尝试不使用 999 它是不必要的大。我很少使用超过 2 个
  • 您好,z-index 较低也是一样。
  • 悬停时尝试z-index:auto
  • 嗨,自动没有变化^^。 Zuber 似乎有一个很好的答案。

标签: css twitter-bootstrap-3 breadcrumbs


【解决方案1】:
  • 您需要为active 按钮设置z-index。检查添加的 CSScss的底部
  • z-index: unset; 设置为.btn。检查更新 css

$(document).ready(function() {
        $( ".btn-breadcrumb a" ).click(function() {
            $(".btn-breadcrumb a").removeClass("active");
            $(this).addClass("active");
        });
    });
.btn-breadcrumb a{
font-weight: bold;
}

.btn-breadcrumb a:hover {
z-index: 1;
}

.btn-breadcrumb a.active {
    background-color: #95A5A6;
    color: #fff;
}

#breadcrumb_sauvegarde {
    background-color: #d9534f;
    color: #fff;
}

#breadcrumb_widget .btn-group{
    display: flex;
}

#breadcrumb_widget .btn-breadcrumb .btn {
    flex-grow: 1;
    text-align: center;
    position: relative;
    z-index: unset; /* Update */
}

/** Triangle Breadcrumb **/
.btn-breadcrumb .btn:not(:last-child):after {
    content: " ";
    display: block;
    width: 0;
    height: 0;
    border-top: 22.4px solid transparent;
    border-bottom: 22.4px solid transparent;
    position: absolute;
    top: 50%;
    margin-top: -22.4px;
    left: 100%;
    z-index: 999;
}

/** Triangle Breadcrumb **/
.btn-breadcrumb .btn:not(:last-child):before {
    content: " ";
    display: block;
    width: 0;
    height: 0;
    border-top: 22.4px solid transparent;
    border-bottom: 22.4px solid transparent;
    position: absolute;
    top: 50%;
    margin-left: 1px;
    margin-top: -22.4px;
    left: 100%;
    z-index: 999;
}

/**Spacing **/
.btn-breadcrumb .btn {
    padding:12px 24px 12px 48px;
}
.btn-breadcrumb .btn:first-child {
    padding:12px 12px 12px 20px;
}
.btn-breadcrumb .btn:last-child {
    padding:12px 36px 12px 48px;
}

/** /////////////////////////// bouton triangle pour faire apparaitre le breadcrumb en flèche //////////////////////// **/

/*couleur de fond du triangle*/
.btn-breadcrumb .btn.btn-default:not(:last-child):after {
    border-left: 40px solid #fff;
}
/*couleur de fond du triangle hover*/
.btn-breadcrumb .btn.btn-default:hover:not(:last-child):after {
    border-left: 40px solid #ecf0f1;
}
/*couleur de fond du triangle active*/
.btn-breadcrumb .btn.btn-default.active:not(:last-child):after {
    border-left: 40px solid #95A5A6;
}
/*couleur de fond du triangle sur active hover*/
.btn-breadcrumb .btn.btn-default.active:hover:not(:last-child):after {
    border-left: 40px solid #95A5A6;
}
/*couleur des bordures du triangle*/
.btn-breadcrumb .btn.btn-default:not(:last-child):before {
    border-left: 40px solid #5e595d;
}
/*couleur des bordures du triangle sur hover*/
.btn-breadcrumb .btn.btn-default:hover:not(:last-child):before {
    border-left: 40px solid #5e595d;
}
/*** Added CSS ***/
.btn-breadcrumb .btn.btn-default.active {
  z-index: 3;
}
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    </head>
    <body>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"  id="breadcrumb_widget" >
            <div class="panel panel-default" >
                <div class="btn-group btn-breadcrumb " >
                    <a href="#" id="breadcrumb_configuration" class="btn btn-default active" >1. Configuration</a>
                    <a href="#" id="breadcrumb_formulaire" class="btn btn-default">2. Formulaire</a>
                    <a href="#" id="breadcrumb_preview" class="btn btn-default">3. Preview</a>
                    <a href="#" id="breadcrumb_sauvegarde" class="btn btn-default">4. Sauvegarder</a>
                </div>
            </div>
        </div>
    </body>
</html>

【讨论】:

  • 嗨 Zuber,我用我自己的代码测试了你的答案,有些东西不起作用。我稍后再回复你。谢谢。
  • 可能您的某些代码被覆盖,请仔细检查
  • 是的,它的工作,谢谢。我为另一边添加了这个 .btn-breadcrumb .btn.btn-default:hover { z-index: 4; }
  • 是的,伙计,我会的,只是重新向人们开放,看到问题还没有结束。这个问题仍然可用,因为我在另一边也有同样的问题,我想知道如何解决它。您可以测试自己的代码,也有同样的问题。谢谢
  • @vincent 请查看我更新的答案,希望它能解决您的问题
【解决方案2】:

问题是您自己的样式被引导程序覆盖

只需添加`!important

.btn-breadcrumb a {
  font-weight: bold;
}

.btn-breadcrumb a:hover {
  z-index: 1 !important;
}

.btn-breadcrumb a.active {
  background-color: #95A5A6;
  color: #fff;
}

#breadcrumb_sauvegarde {
  background-color: #d9534f;
  color: #fff;
}

#breadcrumb_widget .btn-group {
  display: flex;
}

#breadcrumb_widget .btn-breadcrumb .btn {
  flex-grow: 1;
  text-align: center;
  position: relative;
}


/** Triangle Breadcrumb **/

.btn-breadcrumb .btn:not(:last-child):after {
  content: " ";
  display: block;
  width: 0;
  height: 0;
  border-top: 22.4px solid transparent;
  border-bottom: 22.4px solid transparent;
  position: absolute;
  top: 50%;
  margin-top: -22.4px;
  left: 100%;
  z-index: 999;
}


/** Triangle Breadcrumb **/

.btn-breadcrumb .btn:not(:last-child):before {
  content: " ";
  display: block;
  width: 0;
  height: 0;
  border-top: 22.4px solid transparent;
  border-bottom: 22.4px solid transparent;
  position: absolute;
  top: 50%;
  margin-left: 1px;
  margin-top: -22.4px;
  left: 100%;
  z-index: 999;
}


/**Spacing **/

.btn-breadcrumb .btn {
  padding: 12px 24px 12px 48px;
}

.btn-breadcrumb .btn:first-child {
  padding: 12px 12px 12px 20px;
}

.btn-breadcrumb .btn:last-child {
  padding: 12px 36px 12px 48px;
}


/** /////////////////////////// bouton triangle pour faire apparaitre le breadcrumb en flèche //////////////////////// **/


/*couleur de fond du triangle*/

.btn-breadcrumb .btn.btn-default:not(:last-child):after {
  border-left: 40px solid #fff;
}


/*couleur de fond du triangle hover*/

.btn-breadcrumb .btn.btn-default:hover:not(:last-child):after {
  border-left: 40px solid #ecf0f1;
}


/*couleur de fond du triangle active*/

.btn-breadcrumb .btn.btn-default.active:not(:last-child):after {
  border-left: 40px solid #95A5A6;
}


/*couleur de fond du triangle sur active hover*/

.btn-breadcrumb .btn.btn-default.active:hover:not(:last-child):after {
  border-left: 40px solid #95A5A6;
}


/*couleur des bordures du triangle*/

.btn-breadcrumb .btn.btn-default:not(:last-child):before {
  border-left: 40px solid #5e595d;
}


/*couleur des bordures du triangle sur hover*/

.btn-breadcrumb .btn.btn-default:hover:not(:last-child):before {
  border-left: 40px solid #5e595d;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" id="breadcrumb_widget">
  <div class="panel panel-default">
    <div class="btn-group btn-breadcrumb ">
      <a href="#" id="breadcrumb_configuration" class="btn btn-default active">1. Configuration</a>
      <a href="#" id="breadcrumb_formulaire" class="btn btn-default">2. Formulaire</a>
      <a href="#" id="breadcrumb_preview" class="btn btn-default">3. Preview</a>
      <a href="#" id="breadcrumb_sauvegarde" class="btn btn-default">4. Sauvegarder</a>
    </div>
  </div>
</div>

【讨论】:

    【解决方案3】:

        $(document).ready(function() {
            $( ".btn-breadcrumb a" ).click(function() {
                $(".btn-breadcrumb a").removeClass("active");
                $(this).addClass("active");
            });
        });
    .btn-breadcrumb a{
    font-weight: bold;
    }
    
    .btn-breadcrumb a:hover {
    z-index: 1;
    }
    
    .btn-breadcrumb a.active {
        background-color: #95A5A6;
        color: #fff;
    }
    
    #breadcrumb_sauvegarde {
        background-color: #d9534f;
        color: #fff;
    }
    
    #breadcrumb_widget .btn-group{
        display: flex;
    }
    
    #breadcrumb_widget .btn-breadcrumb .btn {
        flex-grow: 1;
        text-align: center;
        position: relative;
    }
    
    /** Triangle Breadcrumb **/
    .btn-breadcrumb .btn:not(:last-child):after {
        content: " ";
        display: block;
        width: 0;
        height: 0;
        border-top: 22.4px solid transparent;
        border-bottom: 22.4px solid transparent;
        position: absolute;
        top: 50%;
        margin-top: -22.4px;
        left: 100%;
        z-index: 999;
    }
    
    /** Triangle Breadcrumb **/
    .btn-breadcrumb .btn:not(:last-child):before {
        content: " ";
        display: block;
        width: 0;
        height: 0;
        border-top: 22.4px solid transparent;
        border-bottom: 22.4px solid transparent;
        position: absolute;
        top: 50%;
        margin-left: 1px;
        margin-top: -22.4px;
        left: 100%;
        z-index: 999;
    }
    
    /**Spacing **/
    .btn-breadcrumb .btn {
        padding:12px 24px 12px 48px;
    }
    .btn-breadcrumb .btn:first-child {
        padding:12px 12px 12px 20px;
    }
    .btn-breadcrumb .btn:last-child {
        padding:12px 36px 12px 48px;
    }
    
    /** /////////////////////////// bouton triangle pour faire apparaitre le breadcrumb en flèche //////////////////////// **/
    
    /*couleur de fond du triangle*/
    .btn-breadcrumb .btn.btn-default:not(:last-child):after {
        border-left: 40px solid #fff;
    }
    /*couleur de fond du triangle hover*/
    .btn-breadcrumb .btn.btn-default:hover:not(:last-child):after {
        border-left: 40px solid #ecf0f1;
    }
    /*couleur de fond du triangle active*/
    .btn-breadcrumb .btn.btn-default.active:not(:last-child):after {
        border-left: 40px solid #95A5A6;
    }
    /*couleur de fond du triangle sur active hover*/
    .btn-breadcrumb .btn.btn-default.active:hover:not(:last-child):after {
        border-left: 40px solid #95A5A6;
    }
    /*couleur des bordures du triangle*/
    .btn-breadcrumb .btn.btn-default:not(:last-child):before {
        border-left: 40px solid #5e595d;
    }
    /*couleur des bordures du triangle sur hover*/
    .btn-breadcrumb .btn.btn-default:hover:not(:last-child):before {
        border-left: 40px solid #5e595d;
    }
    <!DOCTYPE html>
    <html>
        <head>
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
            <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
        </head>
        <body>
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"  id="breadcrumb_widget" >
                <div class="panel panel-default" >
                    <div class="btn-group btn-breadcrumb " >
                        <a href="#" id="breadcrumb_configuration" class="btn btn-default active" >1. Configuration</a>
                        <a href="#" id="breadcrumb_formulaire" class="btn btn-default">2. Formulaire</a>
                        <a href="#" id="breadcrumb_preview" class="btn btn-default">3. Preview</a>
                        <a href="#" id="breadcrumb_sauvegarde" class="btn btn-default">4. Sauvegarder</a>
                    </div>
                </div>
            </div>
        </body>
    </html>

    【讨论】:

      【解决方案4】:

      您需要为 .btn 降序设置 z-index。

      $(document).ready(function() {
              $( ".btn-breadcrumb a" ).click(function() {
                  $(".btn-breadcrumb a").removeClass("active");
                  $(this).addClass("active");
              });
          });
          .btn-breadcrumb a.btn {
        font-weight: bold;
        padding: 12px 24px 12px 48px;
      }
      .btn-breadcrumb a.btn.active {
        background-color: #95a5a6;
        color: #fff;
      }
      .btn-breadcrumb a.btn:not(:last-child):after {
        content: " ";
        display: block;
        width: 0;
        height: 0;
        border-top: 22.4px solid transparent;
        border-bottom: 22.4px solid transparent;
        position: absolute;
        top: 50%;
        margin-top: -22.4px;
        left: 100%;
      }
      .btn-breadcrumb a.btn:not(:last-child):before {
        content: " ";
        display: block;
        width: 0;
        height: 0;
        border-top: 22.4px solid transparent;
        border-bottom: 22.4px solid transparent;
        position: absolute;
        top: 50%;
        margin-left: 1px;
        margin-top: -22.4px;
        left: 100%;
      }
      .btn-breadcrumb a.btn:first-child {
        padding: 12px 12px 12px 20px;
      }
      .btn-breadcrumb a.btn:last-child {
        padding: 12px 36px 12px 48px;
      }
      .btn-breadcrumb a.btn.btn-default:not(:last-child):after {
        border-left: 40px solid #fff;
      }
      .btn-breadcrumb a.btn.btn-default:hover:not(:last-child):after {
        border-left: 40px solid #e6e6e6;
      }
      .btn-breadcrumb a.btn.btn-default.active:not(:last-child):after, .btn-breadcrumb a.btn.btn-default.active:hover:not(:last-child):after {
        border-left: 40px solid #95a5a6;
      }
      .btn-breadcrumb a.btn.btn-default:not(:last-child):before, .btn-breadcrumb a.btn.btn-default:hover:not(:last-child):before {
        border-left: 40px solid #5e595d;
      }
      .btn-breadcrumb a:nth-child(n + 1) {
        z-index: 4;
      }
      .btn-breadcrumb a:nth-child(n + 1):after, .btn-breadcrumb a:nth-child(n + 1):before {
        z-index: 998;
      }
      .btn-breadcrumb a:nth-child(n + 1).active {
        z-index: 4;
      }
      .btn-breadcrumb a:nth-child(n + 1):hover {
        z-index: 4;
      }
      .btn-breadcrumb a:nth-child(n + 2) {
        z-index: 3;
      }
      .btn-breadcrumb a:nth-child(n + 2):after, .btn-breadcrumb a:nth-child(n + 2):before {
        z-index: 997;
      }
      .btn-breadcrumb a:nth-child(n + 2).active {
        z-index: 3;
      }
      .btn-breadcrumb a:nth-child(n + 2):hover {
        z-index: 3;
      }
      .btn-breadcrumb a:nth-child(n + 3) {
        z-index: 2;
      }
      .btn-breadcrumb a:nth-child(n + 3):after, .btn-breadcrumb a:nth-child(n + 3):before {
        z-index: 996;
      }
      .btn-breadcrumb a:nth-child(n + 3).active {
        z-index: 2;
      }
      .btn-breadcrumb a:nth-child(n + 3):hover {
        z-index: 2;
      }
      .btn-breadcrumb a:nth-child(n + 4) {
        z-index: 1;
      }
      .btn-breadcrumb a:nth-child(n + 4):after, .btn-breadcrumb a:nth-child(n + 4):before {
        z-index: 995;
      }
      .btn-breadcrumb a:nth-child(n + 4).active {
        z-index: 1;
      }
      .btn-breadcrumb a:nth-child(n + 4):hover {
        z-index: 1;
      }
      .btn-breadcrumb a:nth-child(n + 5) {
        z-index: 0;
      }
      .btn-breadcrumb a:nth-child(n + 5):after, .btn-breadcrumb a:nth-child(n + 5):before {
        z-index: 994;
      }
      .btn-breadcrumb a:nth-child(n + 5).active {
        z-index: 0;
      }
      .btn-breadcrumb a:nth-child(n + 5):hover {
        z-index: 0;
      }
      #breadcrumb_sauvegarde {
        background-color: #d9534f;
        color: #fff;
      }
      #breadcrumb_widget .btn-group {
        display: flex;
      }
      #breadcrumb_widget .btn-breadcrumb .btn {
      flex-grow: 1;
      text-align: center;
      position: relative;
      }
      <html>
          <head>
              <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
              <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
              <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
          </head>
          <body>
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"  id="breadcrumb_widget" >
                  <div class="panel panel-default" >
                      <div class="btn-group btn-breadcrumb " >
                          <a href="#" id="breadcrumb_configuration" class="btn btn-default active" >1. Configuration</a>
                          <a href="#" id="breadcrumb_formulaire" class="btn btn-default">2. Formulaire</a>
                          <a href="#" id="breadcrumb_preview" class="btn btn-default">3. Preview</a>
                          <a href="#" id="breadcrumb_sauvegarde" class="btn btn-default">4. Sauvegarder</a>
                      </div>
                  </div>
              </div>
          </body>
      </html>

      【讨论】:

        猜你喜欢
        • 2017-04-19
        • 2012-07-15
        • 2021-09-26
        • 2015-02-02
        • 2018-05-03
        • 2021-08-22
        • 1970-01-01
        • 1970-01-01
        • 2011-10-10
        相关资源
        最近更新 更多