php - 为什么悬停时显示的元素没有显示在嵌套的 CSS 下拉列表中?

标签 php html css mysql html-table

我正在尝试让嵌套的 CSS 下拉菜单正常工作。菜单中的信息是使用数据库中的结果生成的。第一个下拉效果很好;只是当我将鼠标悬停在行上时,什么也没有发生。

谁能看出我哪里出错了?我的理解是,当我将鼠标悬停在类名为 test 的表行(即 <tr> )上时,它应该会在右侧显示类名为 dropcontent2 的元素的,但它不起作用 ><.

下面是我目前得到的图像 - 我试图显示在我悬停的行右侧的“测试”文本,但是它只是显示即使显示属性设置为

screenshot of current state

启动PHP:

if (!empty($result))
  {
            echo "<div class='dropdown'>";
              echo "<span class='label label-success'>Domain Found In History</span>";
                echo " <div class='dropdown-content'>";
                    $this_database->displaySearchResults($result);
                  echo "</div>";
              echo "</div>";
  }

上面调用的PHP函数:

  function displaySearchResults($idArray)
{
  $servername = $this->servername;
  $username = $this->username;
  $password = $this->password;
  $dbname = $this->dbname;
  #Opens the MYSQL Connection
  $conn = mysqli_connect($servername, $username, $password, $dbname);
    if (!$conn)
    {
      die("Connection failed: " . mysqli_connect_error());
    }
    ## Begining of formatting of drop down table
    echo "<table class='table table-condensed'>";
     echo "<tr>";
      echo "<th>Date</th>";
        echo "<th>Time</th>";
          echo "</tr>";
          ##Loops through all the matching ID's
    for ($i = 0; $i < count($idArray); $i++)
    {
        $stmt = $conn->prepare("SELECT * FROM dns WHERE id LIKE '$idArray[$i]' ");
          $stmt->bind_param($idArray[$i]);
            $stmt->execute();
              $result = $stmt->get_result();
              ## For ever matching ID it prints out the date/time into the drop down table
              while($row=$result->fetch_assoc())
              {
                echo "<tr class='test'>";
                  echo "<td>".$row["date"]."</td>";
                    echo "<td>".$row["time"]."</td>";
                        echo "</tr>";
                      echo "<div class='drop2content'>";
                        echo "<tr>";
                          echo "<td>Test </td>";
                              echo "</tr>";
                                echo "</div>";

              }
  }
              echo "</table>";
}

CSS

 /* Show History Drop down Styling */

/* The container <div> - needed to position the dropdown content */
.dropdown
{
   position: relative;
   display: inline-block;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content
{
   display: none;
   position: absolute;
   z-index: 1;
   margin-top:2%;
   background-color:white;
}

/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content
{
   display: block;
}

.drop2content
{
  display:none;
  position:absolute;
  background-color:white;
}

.test:hover .drop2content
{
  display:block;
  position:absolute;
  left:100%;
  top:0%;

}
.test > td
 {
  position:relative;
}
.test
{
  position:relative;
}

最佳答案

您需要将position:relative;应用到.test,否则.drop2content会出现在屏幕之外。

.test {
  position:relative;
}

您可能需要执行以下 CSS,具体取决于您想要的结果。

.test > td {
  position:relative;
}

关于php - 为什么悬停时显示的元素没有显示在嵌套的 CSS 下拉列表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44613489/

相关文章:

html - 将表单添加到 joomla 的前端组件 View

php - 尝试使用 laravel css3 和 bootstrap 覆盖图像

python - 使用 Python 格式化内联 CSS

css - 无法在 Windows 8 HTML5 应用程序中使用某些颜色

php - 使用php将数字转换为字母

php - 连接PHP与Android检查Mysql数据库中是否存在值

php - 当 id 在 php 中包含字符串时如何设置 DIV 样式?

php - Magento:结帐时对额外费用征税错误

javascript - 将 css 属性从一个 html 页面转移到另一页面

html - 从 primefaces 表中的一列中删除边框的问题