7.2 Student Activity
Create a Simple Layout with Header, Two-Column Content, and Footer
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS Positioning Layout</title> <style> body { font-family: Arial, sans-serif; } header { background-color: #333; color: white; text-align: center; padding: 10px; } .flex-container { display: flex; margin: 20px; } .column { width: 50%; padding: 10px; box-sizing: border-box; } footer { background-color: #333; color: white; text-align: center; padding: 10px; position: fixed; width: 100%; bottom: 0; } </style> </head> <body> <header> <h1>My Web Layout</h1> </header> <h2>Without clear</h2> <div class="div1">div1</div> <div class="div2"> div2 - Notice that div2 is after div1 with float left in the HTML code. However, since div1 floats to the left, the text in div2 flows around div1, because it is not cleared. </div> <br /><br /> <h2>With clear</h2> <div class="div3">div3</div> <div class="div4"> div4 - Here,css is set to clear: left; moves div4 down below the floating div3. The value "left" clears elements floated to the left. You can also clear "right" and "both". </div> <footer> <p>Footer Content</p> </footer> </body> </html>
Last updated