我制作了一个全屏表格,但它干扰了导航栏

我对 HTML 和 CSS 还很陌生,我尝试制作一个响应式的全屏表格,但由于它我无法使用导航栏。这可能是因为位置:绝对属性,但我不知道如何在不破坏它的情况下更改它。


如果我更改position:absolute属性或删除它,则表将完全损坏。


var table = document.getElementById("table");


var w = window.innerWidth;

var h = window.innerHeight;


var wsquare = 30, hsquare = 30;

var m = w / wsquare, n = h / hsquare;


for(var i = 0; i < n - 1; i++) {

  var row = table.insertRow(i);

  for(var j = 0; j < m - 1; j++) {

    var cell1 = row.insertCell(j);

  }

}

th, table, td{

  border: 1px solid black;

  border-collapse: collapse;

}


table {

  position: absolute;

  left: 0;

  top: 0;

  right: 0;

  bottom: 0;

  width: 100%;

  height: 100%;

}

<!DOCTYPE html>

<html dir="ltr">

  <head>

    <meta charset="utf-8">

    <title>PathFinding</title>

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

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

  </head>

  <body>

    <nav class="navbar navbar-inverse">

      <div class="container-fluid">

        <div class="navbar-header">

          <a class="navbar-brand" href="#">Name</a>

        </div>

        <ul class="nav navbar-nav">

          <li class="active"><a href="#">Home</a></li>

          <li><a href="#">Page 1</a></li>

          <li><a href="#">Page 2</a></li>

          <li><a href="#">Page 3</a></li>

        </ul>

      </div>

    </nav>

    <div class="table">

      <table id= "table">

      </table>

    </div>

    <script type="text/javascript" src="script.js"></script>

  </body>

</html>


拉丁的传说
浏览 90回答 1
1回答

明月笑刀无情

我做了一些编辑,现在你的导航栏工作正常:如果你想使用绝对定位,只需添加position:relative; 导航栏和更高的 **z-index*var table = document.getElementById("table");var w = window.innerWidth;var h = window.innerHeight;var wsquare = 30, hsquare = 30;var m = w / wsquare, n = h / hsquare;for(var i = 0; i < n - 1; i++) {&nbsp; var row = table.insertRow(i);&nbsp; for(var j = 0; j < m - 1; j++) {&nbsp; &nbsp; var cell1 = row.insertCell(j);&nbsp; }}nav {position:relative;z-index: 2;}table {&nbsp; position: absolute;&nbsp; left: 0;&nbsp; top: 0;&nbsp; right: 0;&nbsp; bottom: 0;&nbsp; width: 100%;&nbsp; height: 100%;}th, table, td{&nbsp; border: 1px solid black;&nbsp; border-collapse: collapse;}<!DOCTYPE html><html dir="ltr">&nbsp; <head>&nbsp; &nbsp; <meta charset="utf-8">&nbsp; &nbsp; <title>PathFinding</title>&nbsp; &nbsp; <link rel="stylesheet" type="text/css" href="style.css">&nbsp; &nbsp; <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">&nbsp; </head>&nbsp; <body>&nbsp; &nbsp; <nav class="navbar navbar-inverse">&nbsp; &nbsp; &nbsp; <div class="container-fluid">&nbsp; &nbsp; &nbsp; &nbsp; <div class="navbar-header">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a class="navbar-brand" href="#">Name</a>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <ul class="nav navbar-nav">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li class="active"><a href="#">Home</a></li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li><a href="#">Page 1</a></li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li><a href="#">Page 2</a></li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li><a href="#">Page 3</a></li>&nbsp; &nbsp; &nbsp; &nbsp; </ul>&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </nav>&nbsp; &nbsp; &nbsp; <table id= "table">&nbsp; &nbsp; &nbsp; </table>&nbsp; &nbsp; <script type="text/javascript" src="script.js"></script>&nbsp; </body></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5