首页 > 解决方案 > 我的折叠下拉菜单在打开时会跳转

问题描述

我有这张折叠卡片,当我点击卡片时,它会在最后跳跃。我希望它打开顺畅

问题出在tooltip-cus类上,当我删除position: relative;它时,它会顺利打开,但产品名称悬停时工具提示位置错位

我还想为产品数量和产品价格添加标题,并在它们下方对齐数量和价格

h5 {
  font-size: 20px;
}

.group-card {
  background-color: #3B506C;
  border-radius: 10px;
}

.product-item {
  border-top: 1px solid #183150;
}

.product-item:first-child {
  margin-top: 30px;
}

.tooltip-cus:hover .tooltiptext-cus {
  visibility: visible;
}

.tooltip-cus .tooltiptext-cus {
  visibility: hidden;
  width: 280px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  /* Position the tooltip */
  position: absolute;
  z-index: 1;
}

.tooltip-cus {
  position: relative;
  display: inline-block;
  font-weight: 500;
}

.tooltiptext-cus {
  top: 10px;
  left: 100px;
  font-size: 16px;
  font-weight: 400;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
  <link rel="stylesheet" href="assets/style.css">
</head>

<body>
  <div class="container">
    <div class="row">

      <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
        <div style="" class="mb-4 ml-3 p-4 group-card">
          <div class="row align-items-center">
            <div class="col-sm-12 ">
              <div class="media">

                <div class="media-body align-self-center">
                  <h5 class="m-0">
                    My products
                  </h5>
                </div>
              </div>
              <a href="#" data-toggle="collapse" data-target="#stretched-content" class="stretched-link collapsed" aria-expanded="false"></a>
            </div>
          </div>
          <div class="collapse" id="stretched-content">
            <div class="product-item py-3">
              <div class="tooltip-cus">
                <p class="mb-0">Product 1</p>
                <span class="tooltiptext-cus">
                                    This is product 1 description
                                </span>
              </div>
              <span class="badge badge-primary float-right">$2.99</span>
              <span class="badge badge-primary float-right mr-2">20</span>
            </div>
            <div class="product-item py-3">
              <div class="tooltip-cus">
                <p class="mb-0">Product 2</p>
                <span class="tooltiptext-cus">
                                    This is product 2 description
                                </span>
              </div>
              <span class="badge badge-primary float-right">$32.99</span>
              <span class="badge badge-primary float-right mr-2">20</span>
            </div>

          </div>
        </div>
      </div>

    </div>
  </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>

标签: htmlcssbootstrap-4

解决方案


我希望它顺利打开:为此,您可以使用 Transition CSS 属性

transition: all 1s ease 0s;

1和2问题已解决:-

*{
  padding:0;
  margin:0;
  box-sizing: border-box;
}

h5 {
  font-size: 20px;
}

.group-card {
  background-color: #3B506C;
  border-radius: 10px;
 
}

.product-item {
  border-top: 1px solid #183150;
}

.product-item:first-child {
  margin-top: 30px;
}

.tooltip-cus:hover .tooltiptext-cus {
  visibility: visible;
}


.tooltip-cus:hover .tooltiptext-cuss {
  visibility: visible;
}

/* new class added */
.tooltip-cus .tooltiptext-cuss {
  visibility: hidden;
  width: 280px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  top: 63%;
  left: 22%;
}

.tooltip-cus .tooltiptext-cus {
  visibility: hidden;
  width: 280px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  top: 37%;
  left: 22%;
}


.tooltip-cus {
  display: inline-block;
  font-weight: 500;

}
.tooltiptext-cus {
  top: 10px;
  left: 100px;
  font-size: 16px;
  font-weight: 400;
}

/* for smoothing */
div#stretched-content {
  transition: all 1s ease 0s;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div class="container">
    <div class="row">

      <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
        <div  class="mb-4 ml-3 p-4 group-card">
          <div class="row align-items-center">
            <div class="col-sm-12 ">
              <div class="media">

                <div class="media-body align-self-center">
                  <h5 class="m-0">
                    My products
                  </h5>
                </div>
              </div>
              <a href="#" data-toggle="collapse" data-target="#stretched-content" class="stretched-link collapsed" aria-expanded="false"></a>
            </div>
          </div>
          <div class="collapse" id="stretched-content">
            <div class="product-item py-3">
              <div class="tooltip-cus">
                <p class="mb-0">Product 1</p>
                <span class="tooltiptext-cus">
                                    This is product 1 description
                                </span>
              </div>
              <span class="badge badge-primary float-right">$2.99</span>
              <span class="badge badge-primary float-right mr-2">20</span>
            </div>
            <div class="product-item py-3">
              <div class="tooltip-cus">
                <p class="mb-0">Product 2</p>
                <span class="tooltiptext-cuss">
                                    This is product 2 description
                                </span>
              </div>
              <span class="badge badge-primary float-right">$32.99</span>
              <span class="badge badge-primary float-right mr-2">20</span>
            </div>

          </div>
        </div>
      </div>

    </div>
  </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>


推荐阅读