Box Model Properties
Working code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Box Model Layout Example</title> <style> body { font-family: Arial, sans-serif; line-height: 1.6; margin: 0; padding: 0; background: #f4f4f4; } .container { width: 80%; margin: 0 auto; overflow: auto; background: white; padding: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } header, footer { background: #333; color: white; padding: 10px 0; text-align: center; } main { padding: 20px; min-height: 400px; } .box { width: calc(50% - 40px); /* Adjusting width for padding and border */ margin: 10px; padding: 20px; border: 5px solid teal; float: left; box-sizing: border-box; /* Include padding and border in the element's width */ } </style> </head> <body> <div class="container"> <header> <h1>Understanding the Box Model</h1> </header> <main> <div class="box">Box 1: This box model includes padding and border.</div> <div class="box">Box 2: This box model includes padding and border.</div> </main> <footer> <p>Footer Content Here</p> </footer> </div> </body> </html> |
Explanation of the Code
Container: To create a card-like effect, the .container class applies a shadow and padding to the content, centered it on the page.
Header and Footer: Text is centered, padding is used, and a background color is used. These serve as the primary content's bookends.
Significant padding surrounds the main content area to improve readability and attractiveness.
Box Elements: Every .box successfully illustrates the box model. To make sure that the padding and border are included in the width and height parameters, they employ box-sizing: border-box. Each of the floating side-by-side boxes occupies 50% of the width, less the area needed for the padding and border.
Box Model Properties
Working code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Box Model Layout Example</title> <style> body { font-family: Arial, sans-serif; line-height: 1.6; margin: 0; padding: 0; background: #f4f4f4; } .container { width: 80%; margin: 0 auto; overflow: auto; background: white; padding: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } header, footer { background: #333; color: white; padding: 10px 0; text-align: center; } main { padding: 20px; min-height: 400px; } .box { width: calc(50% - 40px); /* Adjusting width for padding and border */ margin: 10px; padding: 20px; border: 5px solid teal; float: left; box-sizing: border-box; /* Include padding and border in the element's width */ } </style> </head> <body> <div class="container"> <header> <h1>Understanding the Box Model</h1> </header> <main> <div class="box">Box 1: This box model includes padding and border.</div> <div class="box">Box 2: This box model includes padding and border.</div> </main> <footer> <p>Footer Content Here</p> </footer> </div> </body> </html> |
Explanation of the Code
Container: To create a card-like effect, the .container class applies a shadow and padding to the content, centered it on the page.
Header and Footer: Text is centered, padding is used, and a background color is used. These serve as the primary content's bookends.
Significant padding surrounds the main content area to improve readability and attractiveness.
Box Elements: Every .box successfully illustrates the box model. To make sure that the padding and border are included in the width and height parameters, they employ box-sizing: border-box. Each of the floating side-by-side boxes occupies 50% of the width, less the area needed for the padding and border.
Copyrights © 2024 letsupdateskills All rights reserved