Polish how it looks

INPUT · Slides

Send things to the left and the right

01 / 05

A header splits left and right

The headers you see most often have the logo on the left and the menu on the right, with a big gap between them.

In the beginner chapter you lined things up from the left with float: left;, but that could never push anything to the right edge.

02 / 05

float: right pushes it right

float also takes the value right. The element you set it on floats over to the right.

left on the group on the left, right on the group on the right. That alone sends them to the two edges.

.logo {  float: left;}.nav {  float: right;}

03 / 05

Floating right reverses the order

Put float: right; on several elements and the one written first ends up furthest right, because they pack in from the right.

If the order comes out backwards from what you meant, remember this.

.a {  float: right;}.b {  float: right;}

04 / 05

Match the height and make it a band

Set the height of the band and give the left and right groups the same line-height, and the words line up vertically. The move from the beginner chapter works here as it is.

That gives you the shape of a header.

.header {  height: 72px;}.logo {  line-height: 72px;}

05 / 05

How it differs from text-align: right

text-align: right; pushes the words inside a box to the right; the box itself does not move.

To move the box itself, use float: right;. They look alike but they have different jobs, so do not mix them up. Have a go.