skip to Main Content
* {
  margin: 0 auto;
  padding: 0;
  box-sizing: border-box;
}

#header {
  width: 100vw;
  height: 50px;
  background-color: grey;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#left,
#right {
  background-color: red;
  width: 40px;
  height: 100%;
  text-align: center;
}
<div id="header">
  <span id="left"></span>
  <span id="topic">Lorem Ipsum Dolor</span>
  <span id="right"></span>
</div>

2

Answers


  1. Try setting all the default margins explicitly to 0. The margin of the body might be affecting your layout.

    * {
      margin: 0;
      padding: 0;
      box-sizing:  border-box;
    }
    
    Login or Signup to reply.
  2. * {
      margin: 0 auto;
      padding: 0;
      box-sizing: border-box;
    }
    
    #header {
      width: 100vw;
      height: 50px;
      background-color: grey;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    
    #left,
    #right {
      margin: 0; /* Reset the margin set in the first rule */
      
      background-color: red;
      width: 40px;
      height: 100%;
      text-align: center;
    }
    <div id="header">
      <span id="left"></span>
      <span id="topic">Lorem Ipsum Dolor</span>
      <span id="right"></span>
    </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search