skip to Main Content

My webpage
My webpage
My webpage minimized
My webpage minimized

As you can see in the pictures, when it’s full page it looks fine. but when I minimize the screen the buttons look off. How do i fix it? I want to keep my buttons from flying off here’s my entire code.

I tried using the meta viewport tag but it didn’t work.

body {
  background-color: #F0EAD6;
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
}

.header {
  display: flex;
  align-items: center;
  background-color: #00704A;
  color: white;
  height: 60px;
  padding: 0 20px;
}

.logo {
  width: 106px;
  height: 64px;
  margin-right: auto;
}

.button {
  display: inline-block;
  padding: 10px 20px;
  border-radius: 20px;
  margin-left: 10px;
  background-color: white;
  color: #00704A;
  font-weight: bold;
  text-decoration: none;
  transition: background-color 0.19s ease, color 0.19s ease;
}

.button:hover {
  background-color: #00704A;
  color: white;
}

#headright {
  margin-right: 55%;
}
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<header class="header">
  <img class="logo" src="..WP projectCentral-Perk-Emblem.png" alt="Central Perk logo">
  <div id="headright">
    <a class="button" href="#">HOME</a>
    <a class="button" href="#">MENU</a>
    <a class="button" href="#">GIFT SHOP</a>
  </div>
  <div id="headleft">
    <a class="button" href="#">Find a Store</a>
    <a class="button" href="#">Sign In</a>
    <a class="button" href="#">Join Now</a>
  </div>
</header>

3

Answers


  1. I made some changes with margins, widths, paddings, heights.

    I think the problem was happening due to lack of space.

    <!DOCTYPE html>
    <html>
    
    <head>
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <style>
        body {
          background-color: #F0EAD6;
          font-family: Arial, sans-serif;
          margin: 0;
          padding: 0;
        }
        
        .header {
          display: flex;
          justify-content: space-around;
          align-items: center;
          background-color: #00704A;
          color: white;
          height: 100px;
          padding: 0px 20px;
        }
        
        .logo {
          background: yellow;
          width: 106px;
          height: 64px;
          margin-right: 10px;
        }
        
        .button {
          min-width: 100px;
          display: inline-flex;
          padding: 5px 5px;
          border-radius: 20px;
          margin: 1px;
          background-color: white;
          color: #00704A;
          font-weight: bold;
          text-decoration: none;
          transition: background-color 0.19s ease, color 0.19s ease;
          justify-content: center;
        }
        
        .button:hover {
          background-color: #00704A;
          color: white;
        }
        /*#headright {
        margin-right: 55%; 
    }*/
      </style>
    </head>
    
    <body>
      <header class="header">
        <img class="logo" src="..WP projectCentral-Perk-Emblem.png" alt="Central Perk logo">
        <div id="headright">
          <a class="button" href="#">HOME</a>
          <a class="button" href="#">MENU</a>
          <a class="button" href="#">GIFT SHOP</a>
        </div>
        <div id="headleft">
          <a class="button" href="#">Find a Store</a>
          <a class="button" href="#">Sign In</a>
          <a class="button" href="#">Join Now</a>
        </div>
      </header>
    </body>
    
    </html>
    Login or Signup to reply.
  2. You need to give below to your headright and headleft because your container probably has some other display property due to which you cannot fit your buttons into that

    display : flex;
    flex-direction : row;
    

    This should work.

    Login or Signup to reply.
  3. nice design. So I think that your issue is probably in the fact that you are using percentages in the code. It’s not the best practice to use percentage values in the margin. I think that’s why the design keeps messing up. If you want to adjust the code to work for smaller screens you can always use media queries but never percentages. I made some adjustments to the code and also added a media query for smaller screens. You can check the code with the comments added. I’m using flex, specifically flex-end to push the buttons all the way to the end of the page(all the way to the right). I hope that helps.

    body {
      background-color: #F0EAD6;
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 0;
    }
    
    .header {
      display: flex;
      align-items: center;
      background-color: #00704A;
      color: white;
      height: 60px;
      padding: 0 20px;
    }
    
    .logo {
      width: 106px;
      height: 64px;
      margin-right: 10px; /* Updated: add some spacing to the right */
    }
    
    .button {
      display: inline-block;
      padding: 10px 20px;
      border-radius: 20px;
      margin-left: 10px;
      background-color: white;
      color: #00704A;
      font-weight: bold;
      text-decoration: none;
      transition: background-color 0.19s ease, color 0.19s ease;
    }
    
    .button:hover {
      background-color: #00704A;
      color: white;
    }
    
    #headright {
      display: flex; /* Updated: enable flexbox layout */
      align-items: center;
      justify-content: flex-end; /* Updated: push buttons to the right end */
      flex-grow: 1; /* Updated: expand to take up remaining space */
    }
    
    #headleft {
      display: flex; /* Updated: enable flexbox layout */
      align-items: center;
    }
    
    #headleft .button {
      margin-right: 10px; /* Updated: add some spacing between buttons */
    }
    
    /* Added: media query to adjust layout for smaller screens */
    @media only screen and (max-width: 768px) {
      .logo {
        margin-right: 0;
      }
      #headright {
        justify-content: flex-start;
      }
      #headleft {
        margin-right: auto;
      }
    }
    <header class="header">
      <img class="logo" src="..WP projectCentral-Perk-Emblem.png" alt="Central Perk logo">
      <div id="headleft">
        <a class="button" href="#">HOME</a>
        <a class="button" href="#">MENU</a>
        <a class="button" href="#">GIFT SHOP</a>
      </div>
      <div id="headright">
        <a class="button" href="#">Find a Store</a>
        <a class="button" href="#">Sign In</a>
        <a class="button" href="#">Join Now</a>
      </div>
    </header>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search