skip to Main Content

there is a bbig gap on the left for some reason which make it overflow to the right even if i set it do even

I’ve tried putting it in chat gpt many time therefore showing weird comments, but the issue persists. How can I change my code to achieve the desired layout and behavior?

body {
  margin: 0;
  padding: 0;
  display: flex;
  background-color: #f0f0f0;
}

.container-icon {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  height: 100vh;
  width: 36px;
  background-color: azure;
  border-radius: 10px;
  position: absolute;
  left: 0;
}

.container-icon button {
  margin-bottom: 10px;
  border-radius: 50px;
  border: none;
}

.heading {
  margin: 0px 0px 0;
  padding: 10px;
  height: 36px;
  width: 100%;
  background-color: azure;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  margin-left: 36px;
  display: flex;
  align-items: center;
}

.heading button {
  border-radius: 50%;
  border: none;
  margin-right: 10px;
}

/* Set the card width to 200px */
.cards {
  width: 200px;
  height: 300px;
  background-color: azure;
  border: 1px solid #ccc;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  margin: 10px;
}

.main-cards {
  display: flex;
  flex-wrap: nowrap; /* Prevent wrapping to the next line */
  justify-content: flex-start;
  gap: 10px;
  background-color: azure;
  margin-top: 80px;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <script src="index.js"></script>
    <div class="heading">
        <header>
            <button class="icon-menu"><img width="20" height="20" src="https://img.icons8.com/ios-glyphs/30/menu--v3.png" alt="menu--v3"/></button>
            <input type="text" placeholder="search">
        </header>
    </div>
    
    <aside>
        <div class="container-icon">
            <button class="home-icons"><img width="24" height="24" src="https://img.icons8.com/material-rounded/24/home.png" alt="home"/></button>
            <button class="search-icons"><img width="24" height="24" src="https://img.icons8.com/material-rounded/24/search.png" alt="search"/></button>
            <button class="cart-icons"><img width="24" height="24" src="https://img.icons8.com/material-rounded/24/shopping-cart.png" alt="cart"/></button>
            <button class="user-icons"><img width="24" height="24" src="https://img.icons8.com/material-rounded/24/user.png" alt="user"/></button>
            <button class="menu-icons"><img width="24" height="24" src="https://img.icons8.com/material-rounded/24/menu.png" alt="menu"/></button>
        </div>
    </aside>

    <main>
        <div class="main-cards">
            <div class="cards card-1"></div>
            <div class="cards card-2"></div>
        </div>
    </main>
</body>
</html>

2

Answers


  1. Is this what you want it looks like, Actually for such pages I prefer using Bootstrap, Anyway I wish this will help you.

    body {
      margin: 0;
      padding: 0;
      display: flex;
      background-color: #f0f0f0;
    }
    
    .container-icon {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
      height: 100vh;
      width: 36px;
      background-color: azure;
      border-radius: 10px;
      position: absolute;
      left: 0;
    }
    
    .container-icon button {
      margin-bottom: 10px;
      border-radius: 50px;
      border: none;
    }
    
    .heading {
      margin: 0px 0px 0;
      padding: 10px;
      height: 36px;
      width: 515px;
      background-color: azure;
      border-radius: 10px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
      margin-left: 36px;
      display: flex;
      align-items: center;
    }
    
    .heading button {
      border-radius: 50%;
      border: none;
      margin-right: 10px;
    }
    
    /* Set the card width to 200px */
    .cards {
      width: 200px;
      height: 300px;
      background-color: azure;
      border: 1px solid #ccc;
      border-radius: 10px;
      padding: 20px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
      margin: 10px;
    }
    
    .main-cards {
      display: flex;
      flex-wrap: nowrap; /* Prevent wrapping to the next line */
      justify-content: flex-start;
      gap: 10px;
      background-color: azure;
      margin-top: 80px;
    }
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <script src="index.js"></script>
        <div class="heading">
            <header>
                <button class="icon-menu"><img width="20" height="20" src="https://img.icons8.com/ios-glyphs/30/menu--v3.png" alt="menu--v3"/></button>
                <input type="text" placeholder="search">
            </header>
        </div>
        
        <aside>
            <div class="container-icon">
                <button class="home-icons"><img width="24" height="24" src="https://img.icons8.com/material-rounded/24/home.png" alt="home"/></button>
                <button class="search-icons"><img width="24" height="24" src="https://img.icons8.com/material-rounded/24/search.png" alt="search"/></button>
                <button class="cart-icons"><img width="24" height="24" src="https://img.icons8.com/material-rounded/24/shopping-cart.png" alt="cart"/></button>
                <button class="user-icons"><img width="24" height="24" src="https://img.icons8.com/material-rounded/24/user.png" alt="user"/></button>
                <button class="menu-icons"><img width="24" height="24" src="https://img.icons8.com/material-rounded/24/menu.png" alt="menu"/></button>
            </div>
        </aside>
    
        <main style="position: absolute;left: 37px;">
            <div class="main-cards">
                <div class="cards card-1"></div>
                <div class="cards card-2"></div>
            </div>
        </main>
    </body>
    </html>
    Login or Signup to reply.
  2. It’s because body has display: flex which by default positions its children horizontally.

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