【问题标题】:How to make text appear on hover within a div?如何使文本出现在div内的悬停上?
【发布时间】:2021-02-27 02:09:54
【问题描述】:

我试图在悬停时显示文本(带有一些样式)。我尝试使用 display:none;然后悬停显示:块;但这没有用。

<div class="container-fluid sub-head">
      <div class="row">
        <div class="col-md left">
          <div class="title">Title</div>
          <div class="overlay">
            <div class="overlay-content">
              <p>
                some text
              </p>
              <p>more text.</p>
            </div>
          </div>
        </div>
        <div class="col-md right">
          <div class="title">other title</div>
        </div>
      </div>
    </div>

.row {
  background: #f8f9fa;
  margin-top: 20px;
}

.col-md {
  border: solid 1px #6c757d;
  height: 100px;
}

.overlay {
  height: 100%;
  display:none;
}

.overlay:hover {
  display: block;
}

小提琴在这里; http://jsfiddle.net/2dyvLf5o/14/

【问题讨论】:

    标签: html css hover


    【解决方案1】:

    如果你想查看p元素的内容(更多文字),你应该为这个元素定义一个类名,并将悬停样式设置为它的父div,我也把title放在overlay div里面

    enter code here

    .row {
      background: #f8f9fa;
      margin-top: 20px;
    }
    
    .col-md {
      border: solid 1px #6c757d;
    }
    .overlay{
       height:150px
    }
    
    .hidden-content {
      display: none;
    }
    
    .overlay:hover .hidden-content{
      display: block;
    }
    <div class="container-fluid sub-head">
      <div class="row">
        <div class="col-md left">
          <div class="overlay">
            <h1 class="title">Title</h1>
            <div class="overlay-content">
              <p>
                some text
              </p>
              <p class="hidden-content">more text.</p>
            </div>
          </div>
        </div>
        <div class="col-md right">
          <h1 class="title">other title</h1>
        </div>
      </div>
    </div>

    【讨论】:

      【解决方案2】:

      在父元素上使用:hover,如下所示:

      .row {
        background: #f8f9fa;
        margin-top: 20px;
      }
      
      .col-md {
        border: solid 1px #6c757d;
        height: 100px;
      }
      
      .overlay {
        height: 100%;
        display: none;
      }
      
      .row:hover .overlay {
        display: block;
      }
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
      
      <div class="container-fluid sub-head">
        <div class="row">
          <div class="col-md left">
            <div class="title">Title</div>
            <div class="overlay">
              <div class="overlay-content">
                <p>
                  some text
                </p>
                <p>more text.</p>
              </div>
            </div>
          </div>
          <div class="col-md right">
            <div class="title">Other title</div>
          </div>
        </div>
      </div>

      【讨论】:

      猜你喜欢
      • 2017-08-06
      • 2015-08-04
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 2021-02-03
      相关资源
      最近更新 更多