html 如何将页面垂直分成三个部分?

kse8i1jr  于 2022-12-09  发布在  其他
关注(0)|答案(4)|浏览(159)

I want to convert my web page into four section, one horizontal and three vertical. The horizontal section is okay, but there are two issues with vertical sections:

  1. They are not filling the complete screen height.
  2. The third section is overlapping with second section by nearly 10 or 20 pixels.
    Here is my CSS:
body{
    width: available;
    height: available;
}

.container{
    width: available;
    height: available;
}

.leftpane{
    width: 25%;
    min-width: 350px;
    height: available;
    min-height: 400px;
    float: left;
    background-color: rosybrown;
    border-collapse: collapse;
}

.middlepane{
   width: 50%;
   min-width: 800px;
   height: available;
   min-height: 650px;
   float: left;
   background-color: royalblue;
   border-collapse: collapse;
}

.rightpane{
    width: available;
    height: available;
    position: relative;
    margin-left: 75%;
    background-color: yellow;
    border-collapse: collapse;
}

.toppane{
    width: available;
    height: 100px;
    border-collapse: collapse;
    background-color: #4da6ff;
}

And this is the HTML page:

<div class="container">
            <div class="toppane">Test Page</div>
            <div class="leftpane"><h1>Test Page</h1></div>
            <div class="middlepane">Test Page</div>
            <div class="rightpane"><h1>Test Page</h1></div>
</div>

My output is this:

And I want it to be like this:

Here is a jsfiddle .

nvbavucw

nvbavucw1#

  • 首先,width: available不是有效属性。如果要使用所有可用空间,则应设置width: 100%。无论如何,为解决问题,您还应将height: 100%用于bodyhtml。请参阅以下示例:*

第一个

备注:
**1.**我删除了所有的min-widthmin-height,在这种情况下,您不需要这些。
**2.**将height: 100%用于您的元素,您还应该在bodyhtml标签上设置此选项。
**3.**左侧窗格应为float: left,右侧窗格应为float: right,中间窗格应为float: leftfloat: right,右侧窗格应为width: 50%

  • 仅此而已 *

2022更新!

以下是通过Flex更新的版本:
第一次

qyswt5oh

qyswt5oh2#

检查here,您将获得将屏幕划分为三列的最简单代码。
HTML档案

<body>
  <div class="class1" style="background-color:#9BCB3B;">
    <p>Hi</p>
  </div>
  <div class="class2" style="background-color:#1AB99E;">
    <p>Aditya</p>
  </div>
  <div class="class3" style="background-color:#F36F25;">
    <p>This is Working!</p>
  </div>
</body>

CSS档案

body {
  width: 100%;
  float: left;
}

.class1,
.class2,
.class3 {
  width: 33.33%;
  float: left;
  height: 100px;
}

p {
  padding-top: 25px;
  text-align: center;
}
l3zydbqr

l3zydbqr3#

使用具有网格系统的Twitter Bootstrap框架。
EXAMPLE

<html>
    <head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" type="text/css" media="screen"/>
    </head>

    <body>
        <div class="container">
          <div class="row">
            <div class="col-xs-12 text-center bg-primary" style="height:40px;">Top </div>
          </div>
          <div class="row">
            <div class="col-xs-3 bg-warning" style="height:200px;">left</div>
            <div class="col-xs-6 bg-info" style="height:200px;">Center</div>
            <div class="col-xs-3 bg-danger" style="height:200px;">Right </div>
          </div>
        </div>
    </body>
</html>
iqjalb3h

iqjalb3h4#

<html> <head>   <title>Divide Tab </title> <style> body, html {  
width: 100%;   height: 100%;   margin: 0; }

.container {   width: 100%;   height: 100%; } .leftpane {
    width: 25%;
    height: 100%;
    float: left;
    background-color: rosybrown;
    border-collapse: collapse;
     text-align: center; }

.middlepane {
    width: 50%;
    height: 100%;
    float: left;
    background-color: royalblue;
    border-collapse: collapse;
     text-align: center; }

.rightpane {   width: 25%;   height: 100%;   position: relative;  
float: right;   background-color: yellow;   border-collapse:
collapse;    text-align: center; }

.toppane {   width: 100%;   height: 100px;   border-collapse:
collapse;   background-color: #4da6ff;   text-align: center; }

</style>

</head> <body>  <div class="container">   <div
class="toppane"><h2>Top View</h2></div>   <div class="leftpane">
    <h1>Left View</h1></div>   <div class="middlepane"><h2>Middle View</h2></div>   <div class="rightpane">
    <h1>Right View</h1></div> </div> </body> </html>

相关问题