skip to Main Content

give the css of that please

I have tried using div but no good

4

Answers


  1. This is something you should be using grid for, but it is possible to make this with flex, you just need a lot of extra containter divs.

    .main {
      width: 100vw;
      height: 100vh;
      background: lightgray;
      display: flex;
    }
    
    .dividerbox-vertical {
      width: 70%;
      display: flex;
      flex-direction: column;
    }
    
    .dividerbox-horizontal {
      width: 100%;
      height: 50%;
      display: flex;
      flex-direction: row;
    }
    
    .one {
      width: 30%;
      height: 100%;
      background: red;
    }
    
    .two {
      width: 100%;
      height: 50%;
      background: green;
    }
    
    .three {
      width: 50%;
      height: 100%;
      background: pink;
    }
    
    .four-a {
      width: 100%;
      height: 50%;
      background: lightblue;
    }
    
    .four-b {
      width: 100%;
      height: 50%;
      background: blue;
    }
    <div class="main">
      <div class="one"></div>
      <div class="dividerbox-vertical">
        <div class="two"></div>
        <div class="dividerbox-horizontal">
          <div class="three"></div>
          <div class="dividerbox-vertical">
            <div class="four-a"></div>
            <div class="four-b"></div>
          </div>
        </div>
      </div>
    </div>
    Login or Signup to reply.
  2. You can’t do that with flex unless you have a lot of container div’s. Here is an example of what you can do:

    .outer {
        width: calc(100% - 30px);
        height: 200px;
        background-color: #d6d6d6;
        padding: 15px;
    }
    .gap {
        gap: 10px;
    }
    .flex {
        display: flex;
    }
    .column {
        flex-direction: column;
    }
    .box-1 {
        background-color: #ff7676;
        height: 100%;
        width: 33%;
    }
    .box-2 {
        width: 66%;
    }
    .box-4 > div,
    .box-2 > div {
        width: 100%;
        height: 50%;
    }
    .box-3 > div {
        width: 50%;
        height: 100%;
    }
    .box-4 > div {
        background-color: #9ba4ff;
    }
    .box-3 > div:first-child {
        background-color: pink;
    }
    .box-2 > div:first-child {
        background-color: #c2ff76;
    }
    <div class="outer flex gap">
      <div class="box-1"></div>
      <div class="flex column box-2 gap">
        <div></div>
        <div class="flex box-3 gap">
          <div></div>
          <div class="flex column box-4 gap">
             <div></div>
             <div></div> 
          </div>
        </div>
      </div>
    </div>

    But the best option in your case is to use grid. Here is a nice online tool.

    Login or Signup to reply.
  3. Tip: you can nest flexboxes.

    *{margin:0;padding:0;box-sizing:border-box;}
    
    .main, .main * {border: 1px solid gray;}
    
    .main {
      display: flex;
      width: 200px;
      height: 100px;
    }
    
    .red {
      background: red;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 50%;
      height: 100%;
    }
    
    .flex1 {
      display: flex;
      flex-direction: column;
      width: 50%;
      height: 100%;
    }
    
    .green {
      background: green;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 50%;
    }
    
    .flex2 {
      display: flex;
      width: 100%;
      height: 50%;
    }
    
    .pink {
      background: pink;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 50%;
      height: 100%;
    }
    
    .flex3 {
      display: flex;
      flex-direction: column;
      width: 50%;
      height: 100%;
    }
    
    .blue {
      background: blue;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 50%;
    }
    <div class=main>
      <div class=red>1</div>
      <div class=flex1>
        <div class=green>2</div>
        <div class=flex2>
          <div class=pink>3</div>
          <div class=flex3>
            <div class=blue>4a</div>
            <div class=blue>4b</div>
          </div>
        </div>
      </div>
    </div>
    Login or Signup to reply.
  4. If you want the pure flexbox style,

       body{
                padding: 0;
                margin: 0;
                color: white;
                font-size: 50px;
                text-align: center;
                font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
            }
            .container{
                background-color: #9b9b9b;
                height: 60vh;
                padding: 15px;
                display: flex;
                flex-direction: row;
                width: 60vw;
                position: absolute;
                top: 50%;
                left: 50%;
                transform:translate(-50%, -50%)
            }
            .box1{
                background-color: #ff7676;
                padding: 10px;
                margin: 10px;
                width: 30vw;
            }
            .box2{
                display: flex;
                flex-direction: column;
                
            }
            .upper1{
                background-color: #c2ff76;
                width: 30vw;
                margin: 10px;
                height: 30vh;
    
            }
            .upper2{
                display: flex;
                flex-direction: row;
                margin: 10px;
            }
            .box3{
                background-color: #ff69b4;
                height: 35vh;
                width: 15vw;
            }
            .box4{
                display: flex;
                flex-direction: column;
    
            }
            .box4a{
                background-color: #9ba4ff;
                height: 15.5vh;
                width: 14.25vw;
                margin: 10px;
            }
            .box4b{
                background-color: #9ba4ff;
                height: 15.5vh;
                width: 14.25vw;
                margin: 10px;
            }
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="style.css">
        <title>Flexbox</title>
    </head>
    <body>
        <div class="container">
            <div class="box1"></div>
            <div class="box2">
                <div class="upper1"></div>
                <div class="upper2">
                    <div class="inside">
                        <div class="box3"></div>
                    </div>
                    <div class="box4">
                        <div class="box4a"></div>
                        <div class="box4b"></div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    </html>

    Hope you understand this..

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search