如何在旁边创建带有2x3网格的边栏 [英] How to create a sidebar with 2x3 grid next to it

查看:58
本文介绍了如何在旁边创建带有2x3网格的边栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个边栏和一个具有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布局,首先是页眉,主文件和页脚,然后是主文件的内容(侧边栏和行).

从以下示例开始:( 可能想出的示例)

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

I want to create a sidebar and a grid that has 2 rows and 3 columns (beside the sidebar). I already have a nav bar and a footer (just a layout, links are not supposed to work)

I have no idea how to create that sidebar and main content grid with flexbox.

Oh and the superman logo: I can't center it vertically for some reason.

<!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;
}

解决方案

You should break your layout into different areas and use for each an HTML container . HTML5 brought to us a few , use them instead divs, the code will be meaningfull and easy to read.

start to build the CSS layout first , the header, main and footer, then the content of main (sidebar and rows).

example to start from : ( 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>

from there you have a template where you can insert your contents , add class or id and style each portion as you want

这篇关于如何在旁边创建带有2x3网格的边栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆