html - 如何防止这些表重叠?

标签 html css

有什么方法可以防止左侧 table 在悬停在 table 上时与右侧 table 碰撞吗?

.rightdrop {
  margin: 0;
  padding: 0;
}

.leftdrop {
  margin-top: -50px;
  margin-right: 61px;
  margin-left: -1px;
  margin-bottom: -2px;
  padding: 0;
  float: right;
  position: relative;
}

a {
  display: block;
  border: 1px solid black;
  text-decoration-line: none;
  text-align: center;
}

a:visited {
  color: blue;
}

tr {
  border-collapse: collapse;
}

.cell {
  display: none;
  border: 1px solid black;
}

.cell p {
  text-align: center;
}

.submitButton {
  text-align: center;
}

input {
  margin-left: .5em;
}

.rightdrop a:focus+.cell,
.rightdrop a:hover+.cell,
.leftdrop a:focus+.cell,
.leftdrop a:hover+.cell {
  display: block;
}

.cell:focus,
.cell:hover {
  display: block;
}
<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title>INTI Reservation System</title>

  <link rel="stylesheet" href="style.css">
</head>

<body>

  <table width="300" class="rightdrop">

    <tr>
      <td>
        <a href="#">C1</a>
        <div class="cell">
          <p><b>Name: </b> </p>
          <p><b>Student ID: </b></p>
        </div>
      </td>
    </tr>

    <tr>
      <td>
        <a href="#">C2</a>
        <div class="cell">
          <p><b>Name :</b><input type="text" maxlength="10" placeholder="Enter you name"> </p>
          <p><b>Password :</b><input type="password" maxlength="8" placeholder="Enter you password"></p>
          <div class="submitButton">

            <input type="submit">
          </div>
        </div>
      </td>
    </tr>

  </table>

  <table width="300" class="leftdrop">

    <tr>
      <td>
        <a href="#">C1</a>
        <div class="cell">
          <p><b>Name: </b> </p>
          <p><b>Student ID: </b></p>
        </div>
      </td>
    </tr>

    <tr>
      <td>
        <a href="#">C2</a>
        <div class="cell">
          <p><b>Name :</b><input type="text" maxlength="10" placeholder="Enter you name"> </p>
          <p><b>Password :</b><input type="password" maxlength="8" placeholder="Enter you password"></p>
          <div class="submitButton">

            <input type="submit">
          </div>
        </div>
      </td>
    </tr>



  </table>


</body>

</html>

还有当我将浏览器最小化时如何防止表格相互冲突。

最佳答案

我刚刚更改了 .rightdrop.leftdrop CSS 类。

.rightdrop {
  float: left;
}

.leftdrop {
  float: right;
}

a {
  display: block;
  border: 1px solid black;
  text-decoration-line: none;
  text-align: center;
}

a:visited {
  color: blue;
}

tr {
  border-collapse: collapse;
}

.cell {
  display: none;
  border: 1px solid black;
}

.cell p {
  text-align: center;
}

.submitButton {
  text-align: center;
}

input {
  margin-left: .5em;
}

.rightdrop a:focus+.cell,
.rightdrop a:hover+.cell,
.leftdrop a:focus+.cell,
.leftdrop a:hover+.cell {
  display: block;
}

.cell:focus,
.cell:hover {
  display: block;
}
<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title>INTI Reservation System</title>

  <link rel="stylesheet" href="style.css">
</head>

<body>

  <table width="300" class="rightdrop">

    <tr>
      <td>
        <a href="#">C1</a>
        <div class="cell">
          <p><b>Name: </b> </p>
          <p><b>Student ID: </b></p>
        </div>
      </td>
    </tr>

    <tr>
      <td>
        <a href="#">C2</a>
        <div class="cell">
          <p><b>Name :</b><input type="text" maxlength="10" placeholder="Enter you name"> </p>
          <p><b>Password :</b><input type="password" maxlength="8" placeholder="Enter you password"></p>
          <div class="submitButton">

            <input type="submit">
          </div>
        </div>
      </td>
    </tr>

  </table>

  <table width="300" class="leftdrop">

    <tr>
      <td>
        <a href="#">C1</a>
        <div class="cell">
          <p><b>Name: </b> </p>
          <p><b>Student ID: </b></p>
        </div>
      </td>
    </tr>

    <tr>
      <td>
        <a href="#">C2</a>
        <div class="cell">
          <p><b>Name :</b><input type="text" maxlength="10" placeholder="Enter you name"> </p>
          <p><b>Password :</b><input type="password" maxlength="8" placeholder="Enter you password"></p>
          <div class="submitButton">

            <input type="submit">
          </div>
        </div>
      </td>
    </tr>



  </table>


</body>

</html>

关于html - 如何防止这些表重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45935877/

相关文章:

javascript - 使用 Javascript 从链接文本中删除前缀

javascript - jQuery选择点击的div

css - PrimeFaces panelGrid 中的透明背景色

javascript - 向上/向下键盘箭头自动滚动

css - 响应式网页设计和固定边距

javascript - 如何为任意 HTML 代码片段生成 "computed"CSS

HTML 表格文本对齐(tbody 适配 thead)

javascript - 在我的 Javascript 中未捕获的 TypeError - 从 JavaScript 调用 HTML

html - CSS 向上丝带

html - 获取链接以将页面加载到一半