0

I want to remove the margin around a #header. It should be the same slim margin as in the #content box. In the first place, I do not understand, why #header and #content have different margins.

Any pointers are appreciate

#box {
  background-color: lightgreen;
}

#header {
  background-color: grey;
  float: right;
  width: 150px;
  text-align: center;
  padding: 0;
  margin: 0;
}

#content {
  background-color: lightblue;
  clear: both;
}
<div id="box">
  <div id="header">
    <p>Header</p>
  </div>
  <div id="content">Content</div>
</div>

https://jsfiddle.net/datvLg9r/1/

j08691
  • 204,283
  • 31
  • 260
  • 272
Tim
  • 11
  • 3

3 Answers3

1

<p></p> Tag have margin so you have to set margin:0 for p element.

Mohit Yadav
  • 471
  • 8
  • 17
0

This targets the p element within the div with id header only and removes the margin.

 #header p {
    margin: 0;
  }

see demo https://jsfiddle.net/datvLg9r/1/

Raymond Nijland
  • 11,488
  • 2
  • 22
  • 34
0

update HTML as follow - remove p element it will work.

<div id="box">

<div id="header">Header
</div>

<div id="content">Content</div>

</div>
jjj
  • 1,136
  • 3
  • 18
  • 28