html中的表没有并排排列

时间:2016-09-09 06:37:32

标签: html css html5 css3 css-float

我试图将3个表彼此相邻但是它们不遵循我的命令。我尝试将style="float:left;"添加到表格标签但不起作用

这是第一张表click to view

的屏幕截图

这是我的代码



@charset "utf-8";

/* CSS Document */

body,
ol,
h1,
h2,
h3,
h4,
h5,
h6,
p,
th,
td,
dl,
dd,
form,
fieldset,
legend,
input,
textarea,
select {
  background-color: none;
  list-style: none;
  margin: 0;
  padding: 0;
}
body {
  background: linear-gradient(#86090F 0%, #EA3C22 100%) repeat scroll 0 0 rgba(0, 0, 0, 0);
  font-family: Roboto, sans-serif;
  font-weight: 300;
}
a {
  display: block;
  text-decoration: none;
}
a:hover {
  text-decoration: none;
}
img {
  border: none;
  vertical-align: middle;
}
.clear {
  overflow: hidden;
  display: block;
  height: 0;
  font-size: 0;
  line-height: 0;
  clear: both;
}
.fl {
  float: left;
  width: 100%;
}
.fr {
  float: right;
  width: 100%;
}
.container {
  width: 90%;
  margin: 0 auto;
  font-size: 150%;
}
header {
  width: 100%;
  margin: 0 auto;
  height: 85px;
  border-bottom: 2px solid #404040;
  background-color: rgb(245, 242, 228);
}
b .img {
  width: 150px;
  border-right: 1px solid #333;
  height: 85px;
  margin-left: 2%;
}
.content1 {
  width: 50%;
  height: 20%;
  font-size: 20px;
  text-align: left;
  margin: 0 auto;
}
.content1 h3 {
  font: blone 14px Arial;
  text-align: center;
  margin-left: 5px;
}
.content1 table {
  width: 100%;
  float: left;
  border-bottom: 1px solid #999;
  border-right: 1px solid #999;
  border-left: none;
  border-top: none;
  margin-top: 10px;
  margin-left: 5px;
  background-color: rgb(245, 242, 228);
}
.content1 table td {
  width: 200px;
  text-align: left;
  border-left: 1px solid #999;
  border-top: 1px solid #999;
  border-right: none;
  border-bottom: none;
  height: 25px;
  font: 20px"Lucida Console", Monaco, monospace;
  font-weight: bold;
  line-height: 95%;
}
.content1 table tr {
  border: none;
}
.box {
  width: 1050px;
  margin: 0 auto;
  margin-top: 15px;
}
.content2 {
  width: 490px;
  float: left;
}
.content2 h3 {
  font: blone 14px Arial;
  text-align: center;
}
.lyb_box {
  width: 100%;
  margin-top: 15px;
  height: 400px;
  border: 1px solid #000;
  margin-left: 1px;
  background-color: rgb(245, 242, 228);
}
.lyb_box_nr {
  float: left;
  width: 90%;
  margin-top: 20px;
}
.lyb_box_nr p {
  font: normal 14px Arial;
  float: left;
  width: 100%;
  margin-left: 7px;
}
.lyb_box_nr input {
  width: 100%;
  float: left;
  margin-left: 10px;
  height: 30px;
  border: 1px solid #CCC;
}
.lyb_box_nr select {
  width: 100%;
  float: left;
  margin-left: 20px;
  height: 30px;
  border: 1px solid #CCC;
}
article {
  width: 40%;
  border: 2px solid #404040;
  float: right;
}
.search {
  float: left;
  width: 150px;
  border-radius: 3px;
  margin-top: 20px;
  color: #000;
  text-align: center;
  height: 25px;
  margin-left: 330px;
}
.content3 {
  float: right;
  width: 500px;
  height: 400px;
  border: 1px solid #404040;
  margin-top: 31px;
}
.content4 {
  float: center;
  width: 500px;
  height: 400px;
  border: 1px solid #404040;
  margin-left: 700px;
}
#nav {
  color: red;
  text-align: center;
  font-weight: bold;
  text-transform: uppercase;
  line-height: 2.8;
  word-spacing: 10px;
  width: 80%;
  margin: -50px auto;
  height: 46px;
  border-radius: 8px;
  border: 1px solid #cbcbcb;
  border-bottom: 4px solid #adadad;
  margin-right: 0px;
}
#nav a {
  display: block;
  width: 30%;
  height: 46px;
  line-height: 40px;
  float: left;
  border-bottom: 4px solid #adadad;
  text-align: center;
  text-decoration: none;
  color: black;
}
#nav a:active {
  color: green;
  background-color: white;
}
#nav a:hover {
  border-bottom: 4px solid red;
  color: red;
}
footer {
  clear: both;
  font-weight: bold;
  font-size: 30px;
  color: #86090F;
  margin: 0 px auto;
  position: absolute;
  bottom: 0px;
  width: 100%;
  background-color: rgb(245, 242, 228);
}
#footer a:hover {
  text-decoration: underline;
  background-color: withe;
}
#footer a,
#footer a:visited {
  color: #fff;
  text-decoration: none;
}
#legal {
  background-color: white;
  clear: both;
  list-style-type: none;
  overflow: hidden;
  padding: 20px 120px 20px 24px;
}
li.first {
  padding-left: 45%;
}
li:not(#flag) {
  float: left;
  padding-right: 25px;
  list-style-type: none;
}
#k {
  padding-left: 40%;
  width: 500px;
  height: 400px;
  border: 0 px solid #404040;
  margin-top: -10px;
}
.blink_text {
  text-align: center;
  animation: 1s blinker linear infinite;
  -webkit-animation: 1s blinker linear infinite;
  -moz-animation: 1s blinker linear infinite;
  color: red;
}
@-moz-keyframes blinker {
  0% {
    opacity: 1.0;
  }
  50% {
    opacity: 0.0;
  }
  100% {
    opacity: 1.0;
  }
}
@-webkit-keyframes blinker {
  0% {
    opacity: 1.0;
  }
  50% {
    opacity: 0.0;
  }
  100% {
    opacity: 1.0;
  }
}
@keyframes blinker {
  0% {
    opacity: 1.0;
  }
  50% {
    opacity: 0.0;
  }
  100% {
    opacity: 1.0;
  }
}
.normalmessage {
  text-align: center;
}
/*!
Pure v0.6.0
Copyright 2014 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
https://github.com/yahoo/pure/blob/master/LICENSE.md
*/

.pure-table {
  /* Remove spacing between table cells (from Normalize.css) */
  float: left;
  border-collapse: collapse;
  border-spacing: 0;
  empty-cells: show;
  border: 1px solid #cbcbcb;
}
.pure-table caption {
  color: #000;
  font: italic 85%/1 arial, sans-serif;
  padding: 1em 0;
  text-align: center;
}
.pure-table td,
.pure-table th {
  border-left: 1px solid #cbcbcb;
  /*  inner column border */
  border-width: 0 0 0 1px;
  font-size: inherit;
  margin: 0;
  overflow: visible;
  /*to make ths where the title is really long work*/
  padding: 0.5em 1em;
  /* cell padding */
}
/* Consider removing this next declaration block, as it causes problems when
there's a rowspan on the first cell. Case added to the tests. issue#432 */

.pure-table td:first-child,
.pure-table th:first-child {
  border-left-width: 0;
}
.pure-table thead {
  background-color: #e0e0e0;
  color: #000;
  font-weight: bold;
  text-align: left;
  vertical-align: bottom;
}
/*
striping:
   even - #fff (white)
   odd  - #f2f2f2 (light gray)
*/

.pure-table td {
  background-color: transparent;
}
.pure-table-odd td {
  background-color: #f2f2f2;
}
/* nth-child selector for modern browsers */

.pure-table-striped tr:nth-child(2n-1) td {
  background-color: #f2f2f2;
}
/* BORDERED TABLES */

.pure-table-bordered td {
  border-bottom: 1px solid black;
  background-color: rgb(245, 242, 228);
}
.pure-table-bordered tbody > tr:last-child > td {
  border-bottom-width: 1px;
}
/* HORIZONTAL BORDERED TABLES */

.pure-table-horizontal td,
.pure-table-horizontal th {
  border-width: 0 0 1px 0;
  border-bottom: 1px solid #cbcbcb;
}
.pure-table-horizontal tbody > tr:last-child > td {
  border-bottom-width: 0;
}

<html>
<link href="style/style.css" rel="stylesheet" type="text/css">
<header>
  <div class="img">
    <img src="images/logo.png">
  </div>
  <div class="container" id="nav">
    <p id="time"></p>
  </div>
</header>

<head>
  <title>LT</title>
  <script>
    var date = new Date();
    setTimeout(function() {
      window.location.reload(1);
    }, (60 - date.getSeconds()) * 1000)
  </script>
  <script src="data.js"></script>
  <script src="sprintf.js"></script>
  <script type="text/javascript" src="2.0.0-crypto-sha1.js"></script>
  <script type="text/javascript" src="2.0.0-hmac-min.js"></script>
</head>

<body>




  <table class="pure-table pure-table-bordered" id="depart" style="float:left;">
    <thead>
      <tr>

        <th width="38%">Bus Route</th>
        <th width="15%">Time</th>
        <th width="50%">Remaining</th>
      </tr>
    </thead>

    <tbody>

    </tbody>
  </table>


  <div style="clear: both"></div>
  <table class="pure-table pure-table-bordered" style="float:left;">
    <thead>
      <tr>
        <th>#</th>
        <th>Make</th>
        <th>Model</th>
        <th>Year</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>1</td>
        <td>Honda</td>
        <td>Accord</td>
        <td>2009</td>
      </tr>

      <tr>
        <td>2</td>
        <td>Toyota</td>
        <td>Camry</td>
        <td>2012</td>
      </tr>

      <tr>
        <td>3</td>
        <td>Hyundai</td>
        <td>Elantra</td>
        <td>2010</td>
      </tr>
    </tbody>
  </table>



  <table class="pure-table pure-table-bordered" style="float:left;">
    <thead>
      <tr>
        <th>#</th>
        <th>Make</th>
        <th>Model</th>
        <th>Year</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>1</td>
        <td>Honda</td>
        <td>Accord</td>
        <td>2009</td>
      </tr>

      <tr>
        <td>2</td>
        <td>Toyota</td>
        <td>Camry</td>
        <td>2012</td>
      </tr>

      <tr>
        <td>3</td>
        <td>Hyundai</td>
        <td>Elantra</td>
        <td>2010</td>
      </tr>
    </tbody>
  </table>


  <footer id="footer">





  </footer>

</body>

</html>
&#13;
&#13;
&#13;

这是第一张表中的单一项目,我将显示有关出发的公共汽车的信息,第二个有关火车的信息,第三个有关电车的信息。 所以这三个表应该彼此相邻显示。 此页面也将是静态的,这意味着用户不会与此页面进行交互。此页面用于在屏幕上向用户显示离开的传输,该屏幕将放置在uni中。请帮忙。

2 个答案:

答案 0 :(得分:2)

从您的HTML中删除<div style="clear: both"></div>

答案 1 :(得分:1)

不需要使用float:left;你应该使用display:inline; 其次在你的html代码中你已经清除了第一个表<div style="clear: both"></div>

之后的浮动

只需执行这两项更改,您的代码即可运行