0

<!DOCTYPE html>
<html>
    <head>
        <style>
            #one{
                background-color: brown;
                text-align: center;
                margin-top: 0;
            }
            #two{
                background-color: rgb(86, 74, 153);
                text-align: center;
                margin-top: 0;
            }
        </style>
    </head>
    <body>
        <div id="one">
            <h1>heading</h1>
        </div>
        <div id="two">
            <h2>welcome section</h2>
        </div>
    </body>
</html>

why do margin-top: 0and margin-bottom: 0 not working in css here? is there any rule like this in css?if i give border to both, it works. also when i give border of 1px, height of div is increasing automatically and margin goes zero but without border i can not set margin zero. why? please give brief discription of this rule.

  • Please go read [ask]. _β€œIs there any reason here?”_ is an absolutely terrible question title. – CBroe Jan 14 '21 at 08:06

1 Answers1

0

h elements have default margins. your h1 and h2 cause it.

#one h1, #two h2 {
   margin-top:0;
   margin-bottom:0;
}
mehmetx
  • 850
  • 6
  • 6