【问题标题】:Text disappears on hover CSS悬停 CSS 时文本消失
【发布时间】:2021-05-10 14:53:11
【问题描述】:

当我将鼠标悬停在它上面时,我的文字消失了。我尝试删除隐藏并放置可见性:可见并将不透明度更改为 1,但我仍然保持不变 - 当我悬停时文本仍然消失。我试图让文本保持不变,当我悬停时什么都不做。奇怪的是我周围有一个框边框,当我悬停时,整个下半部分随之消失,所以一半的框和文本也消失了。我还缺少其他东西吗?

HTML 
<div class="col-xl-3 col-lg-4 col-md-4 col-sm-6 col-6 ">
   <div class="ps">
       <div class="thumbnail">
           <a href=" "><img src="http://placekitten.com/100/100" alt=" "></a>
            <div class="badge">10%</div>
                  </div>
 <div class="container">
         <a class="v" href="/Animal/Cat">Cat store</a>
 <div class="content">
  <a class="title" href="cat_new">kITTY</a>


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

CSS

.title {
    margin: 0;
    display: block;
    padding: 0 0 5px;
    font-size: 14px;
    line-height: 1.2em;
    color: #06c;
    --max-lines: 2;
    max-height: calc(1.2em * var(--max-lines));
    overflow: hidden;
    padding-right: 1rem;
    opacity: 1;}
    
    
    a {
    position: relative;
    color: inherit;
    text-decoration: none;
    transition: all 0.4s ease; }
    
.hover .content {
  visibility: hidden;
  opacity: 1;
  height: 0;
}

.hover {
  border-color: silver;
}

.ps-product--inner .content {
  display: block;
  visibility: visible;
  opacity: 1;
}

【问题讨论】:

    标签: html css hidden


    【解决方案1】:

    删除visibility: hidden;,然后再次运行程序,我试过了。

    【讨论】:

      【解决方案2】:

      请移除可见性:隐藏在 "ps-product:hover .ps-product__content" 中。

       .ps-product__title {
          margin: 0;
          display: block;
          padding: 0 0 5px;
          font-size: 14px;
          line-height: 1.2em;
          color: #06c;
          --max-lines: 2;
          max-height: calc(1.2em * var(--max-lines));
          overflow: hidden;
          padding-right: 1rem;
          opacity: 1;}
          
          
          a {
          position: relative;
          color: inherit;
          text-decoration: none;
          transition: all 0.4s ease; 
       }
          
      .ps-product:hover .ps-product__content {
       /*     remove  visibility: hidden;   */
        opacity: 1;
        height: 0;
      }
      
      .ps-product:hover {
        border-color: silver;
      }
      
      .ps-product:hover.ps-product--inner .ps-product__content {
        display: block;
        visibility: visible;
        opacity: 1;
      }
      

      【讨论】:

        【解决方案3】:

        删除这条规则...

        .ps-product:hover .ps-product__content {
          visibility: hidden;
          opacity: 1;
          height: 0;
        }
        

        【讨论】:

          【解决方案4】:

          visibility hidden; 使具有类ps-product__content 的元素在悬停在ps-product 上时消失。因此,如果您不希望在具有 ps-product__content 类的元素上出现这种行为,您应该像下面的示例一样将其删除:

          .ps-product__title {
              margin: 0;
              display: block;
              padding: 0 0 5px;
              font-size: 14px;
              line-height: 1.2em;
              color: #06c;
              --max-lines: 2;
              max-height: calc(1.2em * var(--max-lines));
              overflow: hidden;
              padding-right: 1rem;
              opacity: 1;}
              
              
              a {
              position: relative;
              color: inherit;
              text-decoration: none;
              transition: all 0.4s ease; }
              
          .ps-product:hover .ps-product__content {
           /* 
          makes the element with class ps-product__content hidden. 
          visibility: hidden; 
          */
            opacity: 1;
            height: 0;
          }
          
          .ps-product:hover {
            border-color: silver;
          }
          
          .ps-product:hover.ps-product--inner .ps-product__content {
            display: block;
            visibility: visible;
            opacity: 1;
          }
          <div class="col-xl-3 col-lg-4 col-md-4 col-sm-6 col-6 ">
             <div class="ps-product">
                 <div class="ps-product__thumbnail">
                     <a href=" "><img src="http://placekitten.com/100/100" alt=" "></a>
                      <div class="ps-product__badge">10%</div>
                            </div>
           <div class="ps-product__container">
                   <a class="ps-product__vendor" href="/Animal/Cat">Cat store</a>
           <div class="ps-product__content">
            <a class="ps-product__title" href="cat_new">kITTY</a>
          
          
           <p class="ps-product__price sale">50000<del>40000</del></p>
           </div>
           </div>
            </div>
           </div>

          【讨论】:

            【解决方案5】:

            默认情况下它的可见性:可见;它不会在悬停时隐藏您的文本,但您已将此属性应用为隐藏,这会导致在 ps-product:hover 类中隐藏一些内容列表。

            您可以删除代码 (visibility: hidden;),也可以将其更改为 visibility: visible; `

            【讨论】:

              猜你喜欢
              • 2023-01-12
              • 1970-01-01
              • 2017-10-25
              • 2015-11-14
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多