【问题标题】:Layout in HTML web pageHTML 网页中的布局
【发布时间】:2020-05-14 16:56:46
【问题描述】:

我是 HTML 网页设计和所有涉及它的语言(php、JavaScript、CSS 等)的新手 我需要一些帮助来使我的 HTML 布局如下所示:

我有以下代码,但我不知道如何修改它以使其看起来像我想要的那样。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}
body {
  width: 100%;
  float: left;
}

.class1{
  width: 100%;
  float: left;
  height: 100%;
}
.class2{
  width: 100%;
  float: right;
  height: 100%;
}
.class3 {
  width: 100%;
  float: right;
  height: 100%;
}

p {
  padding-top: 25px;
  text-align: center;
}
</style>
</head>
<body>
  <div class="class1" style="background-color:#9BCB3B;">
    <p>left</p>
  </div>
  <div class="class2" style="background-color:#1AB99E;">
    <p>Top right</p>
  </div>
  <div class="class3" style="background-color:#F36F25;">
    <p>Buttom right</p>
  </div>
</body>
</html>

非常感谢您的帮助。

【问题讨论】:

    标签: html css


    【解决方案1】:

    有关更改的详细信息,请参阅代码 sn-p。基本上,所有 3 个&lt;div&gt; 都在使用float: leftwidth: 50%。在&lt;body&gt;范围内,添加height: 100vh;设置body的高度。

    <!DOCTYPE html>
    <html>
    
    <head>
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <style>
        * {
          box-sizing: border-box;
        }
        
        body {
          width: 100%;
          height: 100vh;
        }
        
        .class1 {
          width: 50%;
          float: left;
          height: 100%;
        }
        
        .class2,
        .class3 {
          width: 50%;
          float: left;
          height: 50%;
        }
           
        p {
          padding-top: 25px;
          text-align: center;
        }
      </style>
    </head>
    
    <body>
      <div class="class1" style="background-color:#9BCB3B;">
        <p>left</p>
      </div>
      <div class="class2" style="background-color:#1AB99E;">
        <p>Top right</p>
      </div>
      <div class="class3" style="background-color:#F36F25;">
        <p>Buttom right</p>
      </div>
    </body>
    
    </html>

    【讨论】:

    • 谢谢,这实际上非常有用且易于实施。
    【解决方案2】:

    我建议使用gridflex 进行这样的布局,它比基于浮动的布局更好,但请记住检查browser compatibility

    * {
      box-sizing: border-box;
    }
    
    body {
      display: grid;
      grid-template-areas: 
        "left top"
        "left bottom";
      height: 100vh;
      width: 100%;
    }
    
    .class1{
      grid-area: left;
    }
    .class2{
      grid-area: top;
    }
    .class3 {
      grid-area: bottom;
    }
    
    p {
      padding-top: 25px;
      text-align: center;
    }
    <!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
      <div class="class1" style="background-color:#9BCB3B;">
        <p>left</p>
      </div>
      <div class="class2" style="background-color:#1AB99E;">
        <p>Top right</p>
      </div>
      <div class="class3" style="background-color:#F36F25;">
        <p>Buttom right</p>
      </div>
    </body>
    </html>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-28
      • 1970-01-01
      • 2013-04-21
      • 1970-01-01
      • 2015-12-08
      • 1970-01-01
      相关资源
      最近更新 更多