
CSS Preprocessors: Less and Sass
09/05/2024
Advanced CSS Cheat Sheet
11/05/2024
After the HTML and CSS tutorials, use these worked projects to practice building a complete page. Read the brief and try the layout before opening a solution.
1. Complete-page CSS practice projects
The projects cover floated layouts, responsive breakpoints, a parallax hero, a form, and an alternative implementation with Flexbox.
1.1. Blog with a sidebar
Start with the supplied HTML. Write the CSS to match the two reference images at their respective widths.
References:
Viewport wider than 800px:

Viewport up to 800px:

Starter HTML:
<div class="main-wrapper">
<header>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Blog</a></li>
</ul>
</nav>
</header>
<main>
<img src="https://cdn.pixabay.com/photo/2015/09/09/19/56/office-932926_960_720.jpg" alt="Office workspace">
<section>
<h1>Lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Et nisi facilis facere sint tempora? Quos a harum quisquam, sit ratione rem similique quod in est eius ducimus architecto voluptatibus odio.</p>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Sed, blanditiis reiciendis placeat corporis nostrum ipsa totam distinctio, id, tenetur repellat asperiores officiis natus eius optio dolor aspernatur officia error veniam.</p>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Voluptatum aliquid alias hic! Aut illo aspernatur, quo vero officia, hic totam adipisci architecto itaque quibusdam, repellat fuga nam nesciunt quos voluptatibus.</p>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Dicta quae laborum magni enim tenetur sit aut reprehenderit quos. Excepturi, laboriosam nemo amet placeat explicabo facilis aliquid rerum quas incidunt soluta!</p>
</section>
</main>
<aside>
<h2>Lorem ipsum</h2>
<ul>
<li>Lorem ipsum dolor sit amet</li>
<li>Lorem ipsum dolor sit amet</li>
<li>Lorem ipsum dolor sit amet</li>
</ul>
</aside>
<footer>
<p>Eniun</p>
</footer>
</div>
Instructions:
- Use the universal selector to set margin and padding to zero and
box-sizingtoborder-box. - Use Arial for the font family.
- Set the page background to
#425067. - Center the main wrapper and give it a maximum width of 1000px.
- Make the header full width and 48px high with a
#eeeeeebackground. - Remove the list markers and float the navigation items left.
- Remove the link underlines. Use
display: inline-block, 15px vertical padding, 20px horizontal padding, and#2d3646text. On hover, use a#e52f6ebackground and white text. Keep keyboard focus visible. - Give
maina white background, float it left, and set it to 70% width. - Make the main image fill the available width.
- Add 30px of section padding.
- Justify the paragraphs. Use a 16px bottom margin and
line-height: 1.5. - Set the
h1to1.6emwith a 20px bottom margin. - Float the sidebar left at 30% width. Give it a
#25d6c8background and 30px of padding. - Remove list markers in the sidebar. Add a 16px bottom margin and a 1px solid black bottom border where the design shows separators.
- Use black for the sidebar heading, set its size to
1.4em, and add a 20px bottom margin. - Give the footer 70% width, 60px of padding, and a
#e52f6ebackground. Clear the floats so it starts underneath them. - Center the footer paragraph text and make it white.
- At 800px or below, make
main,aside, andfooterfull-width blocks and remove the column floats. - Follow CSS best practices. Validate the stylesheet and use Autoprefixer if your browsers need prefixes.
Worked solution in CodePen:
1.2. Website with a fixed menu, parallax hero, call to action, and WhatsApp link
Build the page shown in the reference. You can use Flexbox, Grid, or traditional layout techniques.
Reference:
Viewports wider than 700px:

Viewports up to 700px:
Stack the containers in a single column on narrower screens.
Instructions:
Use the universal selector to reset margin and padding and set the font to Roboto.
The header contains a logo and navigation:
- Pin the header to the top with
position: fixed,top: 0, andz-index: 1. Give it full width, a height of 70px, and a#F7F9FAbackground. - Center the navigation wrapper and set its maximum width to 1024px.
- Use
padding: 18px 10pxon the logo to reproduce the alignment shown in the prototype. - Float the
ulto the right in the traditional layout. - Remove the list markers and padding. Use inline items and an inline-block link so each link can have a clickable area.
- Use 1em black link text without an underline. The reference uses the 70px header height to align the menu and 26px vertical and 10px horizontal padding on the inline links. Test the final box height and use
#5E5D6Efor the hover text.
Create the parallax container:
.parallax {
background-image: url("https://www.eniun.com/wp-content/uploads/eniun-home-historia.jpg");
height: 400px;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
.parallax img{
max-width: 400px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
overflow: hidden;
}
A fixed header leaves normal flow. Add 70px of top padding to the body or reserve the same amount of space with a normal-flow element so the hero starts below it.
Create the fixed WhatsApp link:
- Set
position: fixed,bottom: 10px, andright: 10pxon#btn-fixed. - Set
.fa-whatsappto green with a font size of3em. Give the link an accessible name.
Create the call to action:
- Set
.call-to-actionto a maximum width of 700px withmargin: 150px auto,padding: 0 30px, and centered text. - Set
.bigto1.1emwith a line height of1.5. - Add a 20px bottom margin to the call-to-action heading, paragraph, and button.
- Use 15px vertical and 40px horizontal button padding, a black background, white 1em text, and a background-color transition of 0.5 seconds. On hover, use
#4A4959. Check the size of the clickable target and keep a visible focus style.
Build the information panel with Flexbox:
- Use a
#1C1D22background, centered white text, and 110px of vertical padding on the info box. - Add a 30px bottom margin to its
h2. - Set
#flex-ptodisplay: flex,justify-content: center, andflex-wrap: wrap. - Give the paragraphs inside
#flex-p30px of padding and a maximum width of 300px.
Complete the other containers using the reference as closely as possible.
Solution:
1.3. Recreate a responsive page with traditional CSS
Build the page from the desktop and mobile prototypes. Use the supplied HTML and create the missing form section from the design. The breakpoint is 800px.
- Use traditional CSS layout for this version. Save Flexbox and Grid for the next implementation.
- Keep your HTML and CSS consistently indented and organized. Avoid redundant rules.
- Compare the result with both prototypes and adjust the layout where it differs.
- You can edit the HTML. Use existing element relationships when they identify the intended styling target, and add classes where they clarify the structure.
Starter HTML:
<header>
<div class="container-center">
<h1>TRADE</h1>
<nav>
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
<a href="#">Link 4</a>
<button>Sign Up</button>
<button>☰</button>
</nav>
</div>
</header>
<section class="cta">
<h2>Ready to get started?</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor indididunt ut labore et dolore magna aliqua.</p>
<button>Start free trial</button>
</section>
<section class="">
<!--Add the form markup here-->
<!-- Join Our Newsletter
Subscribe to receive updates, access to exclusive deals, and more.
Name:
Email:
Subscribe-->
</section>
<footer>
<div class="container-center">
<div>
<h2>TRADE</h2>
<p>© 2000 – 2023</p>
<p>Privacy – Terms</p>
</div>
<div>
<h3>Product</h3>
<a href="#">Product</a>
<a href="#">Product</a>
<a href="#">Product</a>
</div>
<div>
<h3>Features</h3>
<a href="#">Feature</a>
<a href="#">Feature</a>
<a href="#">Feature</a>
</div>
<div>
<h3>Resources</h3>
<a href="#">Resource</a>
<a href="#">Resource</a>
<a href="#">Resource</a>
</div>
<div>
<h3>Company</h3>
<a href="#">Company</a>
<a href="#">Company</a>
<a href="#">Company</a>
</div>
</div>
</footer>
Prototypes:
Viewport wider than 800px:

Viewport up to 800px:

Solution:
1.4. Recreate the same responsive page with Flexbox
Repeat the previous project with Flexbox and compare how you arrange the header, form, and footer.
Solution:
Continue with the beginner CSS exercises, intermediate CSS exercises, or advanced HTML and CSS practice exams.