Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Create a fixed-fluid-fixed layout using CSS calc()


    CSS calc() allows you to mix and match units to get real-time calculations. It's useful when you need to size elements but you have some unknown number that you have to account for.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: Let's start out by targeting the main element. We'll set its margin left property to five rem. This five rem equals the width of the nav element. For the width, let's take width and we'll set that to a calc function of 100 percent minus 25 rem. Here, the 25 rem comes from the 5 rem width of the nav element plus the 20 rem width of the aside element.

    When I resize my window, the main element is still positioned in the correct location, and it grows and shrinks depending on the remaining available space. We can take this one step further by repeating this pattern inside of a MIDI query to ensure that the layout functions properly even when the elements change size.

    If I resize my window, the nav and aside elements shrink, and the main element continues to take up the remaining space, thanks to the calc function.