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

Damon Bauer
InstructorDamon Bauer
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 5 years ago

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.

Instructor: [00:00] 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.

[00:30] 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.

[00:49] 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.

Tre' Codez
Tre' Codez
~ 7 years ago

Where is the code?

Damon Bauer
Damon Bauerinstructor
~ 7 years ago

Hmm.. not sure what's up with the code tab, but here's a link:

http://plnkr.co/edit/CDbdPh?p=preview

devilboy
devilboy
~ 7 years ago

Thanks Damon

Have a nice weekend

James Green
James Green
~ 7 years ago

There are issues with the sound quality on your lessons. The volume goes up and down from lesson to lesson. I have my PC volume on max and this lesson (Create a fixed-fluid-fixed layout using CSS calc()) I can barely hear.

Markdown supported.
Become a member to join the discussionEnroll Today