使用div标签和CSS创建布局

时间:2015-10-06 20:07:06

标签: html css web

我正在尝试为网站创建布局。我使用三个div标签,容器和左右。我希望左边是一个固定的宽度,因为它将是导航。右侧将显示内容。右侧将从数据库加载,因此内容宽度需要根据加载的内容而变化。目前,宽度仅显示窗口的宽度,如果最小化窗口,内容将被切断,而不是显示滚动条,并允许用户滚动查看其余数据。我也不能让左右div显示在一起。有一次,我把它们放在一边,但中间有一个巨大的缝隙,这不是我想要达到的。我只是希望得到一些关于如何实现布局的帮助。欢呼声,

<style> body {
  background-color: #E0E0E0;
  color: #000000;
}
input[type="text"] {
  width: 75px;
}
#wrapper {
  padding: 10px;
  background-color: #9FF;
  /*margin: 0 auto;*/
  min-width: 500px;
  overflow: auto;
  border-radius: 25px;
  box-shadow: 10px 10px 5px grey;
  border-style: solid;
  border-width: 5px;
}
.left {
  /*margin:0 auto;*/
  padding: 15px;
  float: left;
  color: #000000;
  width: 150px;
  border-style: solid;
  border-width: 5px;
}
.right {
  /*margin:0 auto;*/
  padding: 15px;
  float: right;
  color: #000000;
  min-width: 400px;
  border-style: solid;
  border-width: 5px;
}
</style>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Schedule Design</title>
</head>

<body bgcolor="">

  <div id="wrapper">
    <div class="left">
      <p>This is some text</p>
      <p>Here is some more</p>
      <p>this is another one</p>
      <p>this on is for good measure</p>
    </div>
    <div class="right">
      <form>
        <table align="center" cellpadding="5px">
          <tr>
            <th>Employee</th>
            <th>Sunday</th>
            <th>Monday</th>
            <th>Tuesday</th>
            <th>Wednesday</th>
            <th>Thursday</th>
            <th>Friday</th>
            <th>Saturday</th>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>

        </table>
      </form>
    </div>

  </div>
</body>

</html>

2 个答案:

答案 0 :(得分:1)

如果从float: right;课程中删除min-width: 400px;.right,则应该让右侧窗格显示在左侧窗格中。此外,overflow: auto;将允许右侧窗格滚动其宽度。

<style> body {
  background-color: #E0E0E0;
  color: #000000;
}
input[type="text"] {
  width: 75px;
}
#wrapper {
  padding: 10px;
  background-color: #9FF;
  /*margin: 0 auto;*/
  min-width: 500px;
  overflow: auto;
  border-radius: 25px;
  box-shadow: 10px 10px 5px grey;
  border-style: solid;
  border-width: 5px;
}
.left {
  /*margin:0 auto;*/
  padding: 15px;
  float: left;
  color: #000000;
  width: 150px;
  border-style: solid;
  border-width: 5px;
}
.right {
  /*margin:0 auto;*/
  padding: 15px;
  overflow: auto;
  color: #000000;
  border-style: solid;
  border-width: 5px;
}
</style>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Schedule Design</title>
</head>

<body bgcolor="">

  <div id="wrapper">
    <div class="left">
      <p>This is some text</p>
      <p>Here is some more</p>
      <p>this is another one</p>
      <p>this on is for good measure</p>
    </div>
    <div class="right">
      <form>
        <table align="center" cellpadding="5px">
          <tr>
            <th>Employee</th>
            <th>Sunday</th>
            <th>Monday</th>
            <th>Tuesday</th>
            <th>Wednesday</th>
            <th>Thursday</th>
            <th>Friday</th>
            <th>Saturday</th>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>
          <tr>
            <td>Tyler Foraie</td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
            <td>
              <input type="text" placeholder="Start Time" />
            </td>
          </tr>

        </table>
      </form>
    </div>

  </div>
</body>

</html>

答案 1 :(得分:0)

.left{ display:inline-block;}

   /* or */

 .right{ display:inline-block; }

两个类将被内联