Why doesn’t margin get filled with background color in CSS?

You should use padding instead of margin as described by CSS’s Box Model.

  • Margin is providing space beyond the element’s box and therefore won’t be colored – it’s simply space.

  • Padding on the other hand provides space around the inside of the element’s box and is colored and affected by other styles.

<!doctype html>
<html>      
  
  <head>
     <style>
        #footer {
           background: #263238;
           padding: 100px;
        }
        .footer-text {
           margin: 0;
           color: #fff;
        }
     </style>
  </head>
    
  <body>
     <div id="footer">
        <div class="footer-text">All Rights Reserved © 2016</div>
     </div>
  </body>   
 
</html>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)