【问题标题】:Need Bootstrap's " table table-hover" to allow for highlighting white all row text需要 Bootstrap 的“table table-hover”来突出显示所有行的白色文本
【发布时间】:2015-05-11 02:15:30
【问题描述】:

我有一个使用 Bootstrap 的“table”和“table-hover”类的简单表格

在每个相同的表格行内如下:

  • 缩略图
  • 标题 (H5) 必须是黑色文本
  • 3 段文本(span)元素,从标题缩进,必须是灰色文本
  • 一个下载按钮拉到右边(实际上是一个很棒的字体图标)。还必须是灰色图标和灰色文本

期望的结果是,当悬停在行(行内的任何位置)时,所有文本(标题、跨度、字体真棒图标和下载链接)将文本颜色变为白色,将行背景变为蓝色。

到目前为止,我已经设法将背景蓝色全部变成白色,除了标题。

我真的希望 CSS :not() 选择器能解决问题,但没有这样的运气。

我是新手,所以可能走错路了。

非常感谢任何帮助。提前致谢!

你可以看到我对这个JS Fiddle采取的方法

HTML:

    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<body cz-shortcut-listen="true">

    <div class="col-sm-10" id="Table">
        <table class="table table-hover">
            <!-- <thead>
                <tr>
                    <th></th>
                </tr>
            </thead> -->

            <tbody>
                <tr>
                    <td>
                        <div>
                            <img class="pull-left" id="thumbnail" src="http://velocityagency.com/wp-content/uploads/2013/08/go.jpg" style="height:100px; width:100px;>
                            <div id="searchResultHeading">                          
                                <h5>Heading Black then white on row hover</h5>
                            </div>                      
                                <span>some info grey then white on hover</span> &nbsp; &nbsp; 
                                <span>some info grey then white on hover</span> <br>
                                <span>some info grey then white on hover</span> &nbsp;  &nbsp; 
                            <div class="pull-right table-hover" id="downloadButton">
                                <a href="#"> 
                                    <i class="fa fa-cloud-download"></i> Download
                                </a>
                            </div>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>



</body>

CSS

    body, html {
    height: 100%;
    min-height: 100%;
}
a {
    color: #22c7fa;
}
.table.table-hover > tbody > tr > td:hover {
    background-color: #22c7fa;
    color: #fff;
}
.table.table-hover > tbody > tr > td > i {
    color: #inherit;
}
.table.table-hover > tbody > tr > td > div > a {
    color: inherit;
}

#table > table {
    margin-left: 97px;
    margin-right: 60px;
    overflow: auto;
    overflow-y: auto; 
}
/*Make all text in the search results grey*/
#Table > table > tbody > tr > td {
    padding-left: 0px !important;
    color: #919191;
}
/*Make the headings in the search results black*/
#Table > table > tbody > tr > td > div > h5{
    color:#323333;
}
/*Make all text in the search results turn white on hover*/
#Table > table > tbody > tr > td:hover {
    padding-left: 0px !important;
    color: #fff;
}
/* Indent the search results details */
#Table > table > tbody > tr > td > span {
    padding-left: 6px;
    font-weight: 200;
}

【问题讨论】:

    标签: html css twitter-bootstrap


    【解决方案1】:

    您当前的 :hover 选择器不够具体,无法覆盖 h5 样式:

    #Table > table > tbody > tr > td > div > h5{
        color:#323333;
    }
    

    将此添加到您的 CSS:

    #Table > table > tbody > tr > td:hover h5 {
        color: #fff;
    }
    

    Updated Fiddle

    【讨论】:

      【解决方案2】:

      您忘记了图像标签上的结束引号:

      <img class="pull-left" id="thumbnail" src="http://velocityagency.com/wp-content/uploads/2013/08/go.jpg" style="height:100px; width:100px;>
      

      如果你把它加进去,它就可以正常工作了。

          body,
          html {
            height: 100%;
            min-height: 100%;
          }
          a {
            color: #22c7fa;
          }
          .table.table-hover > tbody > tr > td:hover {
            background-color: #22c7fa;
            color: #fff;
          }
          .table.table-hover > tbody > tr > td > div > a {
            color: inherit;
          }
          #table > table {
            margin-left: 97px;
            margin-right: 60px;
            overflow: auto;
            overflow-y: auto;
          }
          /*Make all text in the search results grey*/
          #Table > table > tbody > tr > td {
            padding-left: 0px;
            color: #919191;
          }
          /*Make the headings in the search results black*/
          #Table > table > tbody > tr > td > div > h5 {
            color: #323333;
          }
          /*Make all text in the search results turn white on hover*/
          #Table > table > tbody > tr > td:hover {
            padding-left: 0px;
            color: #fff;
          }
          /* Indent the search results details */
          #Table > table > tbody > tr > td > span {
            padding-left: 6px;
            font-weight: 200;
          }
      <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
      
      <body cz-shortcut-listen="true">
      
        <div class="col-sm-10" id="Table">
          <table class="table table-hover">
           <tbody>
              <tr>
                <td>
                  <div>
                    <img class="pull-left" id="thumbnail" src="http://velocityagency.com/wp-content/uploads/2013/08/go.jpg" style="height:100px; width:100px;">
                    <div id="searchResultHeading">
                      <h5>Heading Black then white on row hover</h5>
                    </div>
                    <span>some info grey then white on hover</span> &nbsp; &nbsp;
                    <span>some info grey then white on hover</span> 
                    <br>
                    <span>some info grey then white on hover</span> &nbsp; &nbsp;
                    <div class="pull-right table-hover" id="downloadButton">
                      <a href="#">
                        <i class="fa fa-cloud-download"></i> Download
                      </a>
                    </div>
                  </div>
                </td>
              </tr>
             <tr>
                <td>
                  <div>
                    <img class="pull-left" id="thumbnail" src="http://velocityagency.com/wp-content/uploads/2013/08/go.jpg" style="height:100px; width:100px;">
                    <div id="searchResultHeading">
                      <h5>Heading Black then white on row hover</h5>
                    </div>
                    <span>some info grey then white on hover</span> &nbsp; &nbsp;
                    <span>some info grey then white on hover</span> 
                    <br>
                    <span>some info grey then white on hover</span> &nbsp; &nbsp;
                    <div class="pull-right table-hover" id="downloadButton">
                      <a href="#">
                        <i class="fa fa-cloud-download"></i> Download
                      </a>
                    </div>
                  </div>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      
      
      
      </body>

      【讨论】:

      • 感谢您如此迅速地取得联系并发现我的错字。这确实让我接近了我需要去的地方。对此,我真的非常感激。最终,uʍopǝpısdn 提供的 CSS 产生了我正在寻找的行为。再次感谢!
      最近更新 更多