html - 如何创建旁边有 2x3 网格的侧边栏

标签 html css flexbox grid sidebar

我想创建一个侧边栏和一个具有 2 行和 3 列的网格(在侧边栏旁边)。我已经有一个导航栏和一个页脚(只是一个布局,链接不应该工作)

我不知道如何使用 flexbox 创建侧边栏和主要内容网格。

哦,还有超人标志:出于某种原因,我无法将它垂直居中。

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8"/>
    <title>web1</title>
    <link rel="stylesheet" href="style.css"/>
  </head>
  <body>
    <div class="menu-container">
      <div class="logo-container">
          <div class="logo"><img src="https://seeklogo.com/images/1/3-colors-superman-logo-ACD3F1907B-seeklogo.com.png"></div>
      <nav class="menu"> 
          <div class="buttonid">
            <a href="#" class="myButton">Avaleht</a>
            <a href="#" class="myButton">Tooted</a>
            <a href="#" class="myButton">Kontakt</a>
          </div>
    </div>
      </div>
      </nav>
    <div class="footer">
        <div class="footer-item">SEE TÖÖTAB VIST</div>
    </div>
  </body>
</html>

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }

  html, body {
    height: 100%;
  }

  .menu-container {
    color: #fff;
    background-image: linear-gradient( rgb(0, 0, 0), rgb(255, 0, 0));
    padding: 20px 0;

  }

  .logo-container {
    display: flex;
    border: blue solid 2px;
    height: 100px;
  }

  .menu {
    border: white solid 3px;
    width: 100%;
    text-align: center;
  }

  .myButton {
    box-shadow:inset 0px 1px 0px 0px #cf866c;
    background:linear-gradient(to bottom, #d0451b 5%, #ff0000 100%);
    background-color:#ff0000;
    border-radius:3px;
    border:1px solid #ffffff;
    display:inline-block;
    cursor:pointer;
    color:#ffffff;
    font-family:Arial;
    font-size:13px;
    padding:6px 24px;
    text-decoration:none;
    text-shadow:0px 1px 0px #854629;
}
.myButton:hover {
    background:linear-gradient(to bottom, #bc3315 5%, #d0451b 100%);
    background-color:#bc3315;
}
.myButton:active {
    position:relative;
    top:1px;
}

.logo img {
  width: 100px;
}

.footer {
  color: #fff;
  background-image: linear-gradient( rgb(0, 0, 0), rgb(255, 0, 0));
  padding: 20px 0;
  position: absolute;
  bottom: 1px;
  width: 100%;
}

.footer-item {
  text-align: center;
  font-weight: bold;
  word-spacing: 30px;
}

.buttonid {
  align-items: center;
  word-spacing: 30px;
  height: 100px;
  display: flex;
  justify-content: center;
}

最佳答案

您应该将布局分成不同的区域,并为每个区域使用一个 HTML 容器。 HTML5 给我们带来了一些,用它们代替 div,代码将有意义且易于阅读。

首先开始构建 CSS 布局,页眉、主体和页脚,然后是主体的内容(边栏和行)。

示例从 : ( possible example to come up with )

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header,
footer,
aside,
article {
  border: solid;
}

main,
section {
  flex: 1;
  display: flex;
}

section {
  flex-wrap: wrap;
}

article {
  flex: 1;
  min-width: 30%;
}

/* is sizing an issue ? */
 /* try */
 
 body:hover * { padding:0.25em;transition:0.25s;box-sizing:border-box;}
body:hover aside, body:hover article {margin:2px;}
<header>
  header</header>
<main>
  <aside>
    aside
  </aside>
  <section>
    <article> article</article>
    <article> article</article>
    <article> article</article>
    <article> article</article>
    <article> article</article>
    <article> article</article>
  </section>
</main>
<footer>footer</footer>

从那里你有一个模板,你可以在其中插入你的内容,添加类或 id 并根据需要为每个部分设置样式

关于html - 如何创建旁边有 2x3 网格的侧边栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58940911/

相关文章:

html - 如何使用 CSS 居中某些内容,使其相对于滚动条居中?

html - 隐藏 CSS 溢出

javascript - 网页 |通过 anchor 链接平滑滚动

twitter-bootstrap - 是否可以结合使用 flexbox 和 Bootstrap?

html - CSS填充父高度并保留

javascript - 以编程方式切换到网页的生产源

css - 无法加载图像使用(背景图像 :url (""))from a style sheet

css - 右对齐换行文本,否则左对齐

html - 如果 flex 子项的宽度加起来达到容器的 100%,如何在它们之间添加空间

css - 垂直居中超过窗口高度的内容