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

问题描述 投票:0回答:2

所以我想创建一个侧边栏和一个具有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 css flexbox grid sidebar
2个回答
0
投票

将您的.menu容器设置为display: grid; grid-template-column: [here goes the width of you side-nav, ex:200px] [width of your grid that has two rows ex: 1fr

并且对于其他网格显示:grid; grid-template-rows: repeat(2, 1fr); grid-template-column: repeat(3,1fr);


0
投票

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

开始构建布局,首先是header,main,footer和main的内容。

示例从开始:

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%;
}
<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并根据需要设置每个部分的样式

© www.soinside.com 2019 - 2024. All rights reserved.