Putting theory into practice is essential for mastering CSS. In this chapter, we’ll tackle practical projects to solidify your skills and build your portfolio.
Example:
<!-- Blog Page Example --> <header> <h1>My Blog</h1> <nav> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </nav> </header> <main> <article> <h2>Blog Post Title</h2> <p>Excerpt of the blog post...</p> </article> <aside> <h3>Recent Posts</h3> <ul> <li><a href="#">Post Title 1</a></li> <li><a href="#">Post Title 2</a></li> </ul> </aside> </main> <style> header, nav, ul, li, a { margin: 0; padding: 0; list-style: none; } header { background: #333; color: white; padding: 10px 0; } nav ul { display: flex; justify-content: space-around; } main { display: flex; margin: 20px; } article { flex: 2; margin-right: 20px; } aside { flex: 1; } </style>
Example:
<!-- Responsive Navigation Example --> <nav> <div class="hamburger"></div> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </nav> <style> nav ul { display: flex; flex-direction: column; } .hamburger { display: block; width: 30px; height: 30px; background: #333; } @media (min-width: 600px) { nav ul { flex-direction: row; } .hamburger { display: none; } } </style>
Example:
<!-- Product Gallery Example --> <div class="gallery"> <div class="product"> <img src="product1.jpg" alt="Product 1"> <h3>Product 1</h3> <p>Description of product 1</p> </div> <div class="product"> <img src="product2.jpg" alt="Product 2"> <h3>Product 2</h3> <p>Description of product 2</p> </div> </div> <style> .gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; } .product { border: 1px solid #ccc; padding: 10px; text-align: center; } </style>
Example:
<!-- Complete Website Example --> <header> <h1>My Website</h1> <nav> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Services</a></li> <li><a href="#">Contact</a></li> </ul> </nav> </header> <main> <article> <h2>Welcome to My Website</h2> <p>This is a complete, responsive website example.</p> </article> <aside> <h3>Sidebar</h3> <p>Additional content here.</p> </aside> </main> <footer> <p>Contact: email@example.com</p> </footer> <style> header, nav, ul, li, a, footer { margin: 0; padding: 0; list-style: none; text-align: center; } header { background: #333; color: white; padding: 10px 0; } nav ul { display: flex; justify-content: center; gap: 10px; } main { display: flex; justify-content: center; margin: 20px; } article { flex: 2; margin-right: 20px; } aside { flex: 1; } footer { background: #333; color: white; padding: 10px 0; } </style>
Conclusion
Practical projects bring your CSS skills to life. In the next chapter, we'll focus on performance and optimization to ensure your designs are not just beautiful, but also efficient.
Please Sign In to post a comment.