0

My first question is : The difference between Flex vs Grid when creating a website. Is it when you do display:flex that your body for example shrinks automated and makes it smaller and smaller when with grid area template for example and when you make your screen smaller the information dissapears / does not go automated with your new widths.

Second question : In this example here with Flex. When i make my browser smaller and width smaller then articles get under my aside so the main content starts to expand under the aside/main. Which i want when i make screen smaller that articles stay in this grey area and get below eachother in this same light grey area.

body {
  width: 70%;
  margin: 0 auto;
  font-family: sans-serif;
  color: #2a2a2a;
  background-color: grey;
}

    header{
        grid-area:header;

    }
    header ul{
        display:flex;
    }
    header li{
        list-style:none;
        flex:1;
    }
    main {
  display: flex;
  flex-wrap: wrap;/*maakt da je inhoud in je div blijft er niet buiten als je width aanpast*/
  align-content: flex-start;
  background-color: lightgrey;
}
aside {
  flex: 1; /*is zelfde als 1fr in display:grid*/
  margin-right: 10px;
  background-color: #ff80ff;
}
#artikel1 {
  
  flex:2;
  
}
#artikel2 {
    flex:2;
    
}

#artikel3 {
    flex:2;
}
#artikel4 {
    flex:2;
}



aside li {
  padding-bottom: 10px;
}

footer {
  margin-top: 10px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>SCSS</title>
  <link rel="stylesheet" href="training.css">
  <style>


  </style>
</head>

<body>
    <div class="container">


        <header>
            <nav>
                <ul><li>Home</li><li>Contact</li><li>Nog informatie</li><li>content</li></ul>
            </nav>

        </header>
        <main>
                        <!-- the aside content can also be nested within the main content -->
                        <aside>
                            <h2>Related</h2>
                            <ul>
                              <li><a href="#">Oh I do like to be beside the seaside</a></li>
                              <li><a href="#">Oh I do like to be beside the sea</a></li>
                              <li><a href="#">Although in the North of England</a></li>
                              <li><a href="#">It never stops raining</a></li>
                              <li><a href="#">Oh well...</a></li>
                            </ul>
                          </aside>
            <!-- It contains an article -->
            <article id="artikel1">
              <h2>Article heading</h2>
              <p>
                tekst artikel 1
              </p>
      
              <h3>titel2</h3>
              <p>
                artikel2
              </p>
            </article>
            <article id="artikel2">
                <h2>Article heading</h2>
                <p>
                  tekst artikel 1
                </p>
        
                <h3>titel2</h3>
                <p>
                  artikel2
                </p>
              </article>
              <div class="break"></div>
              <article id="artikel3">
                <h2>Article heading</h2>
                <p>
                  tekst artikel 1
                </p>
        
                <h3>titel2</h3>
                <p>
                  artikel2
                </p>
              </article>
              <article id="artikel4">
                <h2>Article heading</h2>
                <p>
                  tekst artikel 1
                </p>
        
                <h3>titel2</h3>
                <p>
                  artikel2
                </p>
              </article>

          </main>
        <footer>




        </footer>
    </div>


</body>

</html>

I tried many possibilities.

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
JJJ
  • 1
  • 1
  • Your first Q is little opinion based + very general. Please read this article: https://stackoverflow.com/help/how-to-ask The second one not related exactly to flexbox VS Grid. – Ezra Siton Jan 02 '23 at 16:40

2 Answers2

1

Grid:CSS Grid Layout, is a two-dimensional grid-based layout system with rows and columns, making it easier to design web pages without having to use floats and positioning. Like tables, grid layout allow us to align elements into columns and rows. Flexbox: The CSS Flexbox offers a one-dimensional layout. It is helpful in allocating and aligning the space among items in a container (made of grids). It works with all kinds of display devices and screen sizes

  • 1
    Hello,can you run please the code and check when the width is small/smaller then the articles get under the aside and creates a new bar. How can i keep them into this grey zone aside the aside ? And just make the aside column bigger? – JJJ Jan 02 '23 at 11:23
0

When comparing the two, the main difference is that CSS Grid is better suited for creating two-dimensional layouts, while CSS Flexbox is better for one-dimensional designs. Moreover, using CSS Grid, elements are positioned using numerical coordinates, whereas Flexbox uses relative positioning and margins.