Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
One of the key advantages print designers have held over their web counterparts is the ability to easily lay out text in multiple columns. If you ever worked in a layout program like Adobe InDesign, you know how simple it is to flow text from one frame to another. Now thanks to CSS3 web designers can quickly set up any number of columns in their web pages and the text will flow just as easily and automatically. To show you how this looks, take a look at the page here and this is done without multicolumns, but now if I switch to the final completed page, here you can see the two columns side by side, and this is done with one simple CSS rule.
So let me show you how that works. The first thing I want to do is place these two columns in a single div and to do that, I'm going to go ahead and switch out of Live View and then go down to where the Tour vouchers start. The first step is to wrap the two paragraphs, Tour vouchers and Trip planning, into a single div. So I'm going to go into Split view here to make sure that I get both of those paragraphs, starting with each of the h3 tags. So I have Tour vouchers in the first paragraph and I'm scrolling down.
I now have Trip planning and I want to end it before Tour checklist. So now with that selected, I can press Command+T on the Mac or Ctrl+T on the PC, and you can see the wrap tag that jumped to the top of the screen there. This is the Quick Tag Editor and now I'm ready to put in my div and give it a special ID of multiple columns. Once I have that complete, just hit Enter or Return and there is my wrapping tag.
So now we are ready to create our new CSS rule and to do that, I'm going to go to main.css and I'll just scroll down to the bottom and start a new entry, with the hash mark and the ID multipleCols for multiple columns, put in my opening curly brace and my closing curly brace. The first thing I want to do is align the text to the left just to make sure that that is set up properly. Now you could do text-align justify which is a very common technique, but only, I think, if your entire page is using justified text.
Next we're going to put in vendor- specific tags for three different properties; column-count, column-gap, and column -rule and we'll do it for both the Mozilla and Webkit. So we'll start out by putting in a hyphen which indicates a vendor-specific prefix, and then we'll use moz for Mozilla followed by another hyphen and then the keywords column and you can see as we just put in the C, code hints goes right to column-count. So I'll go ahead and hit Enter and we have two columns here, and I'll close that off with a semicolon and another vendor-specific preference of moz, C for columns, and this time we want to do the column-gap, that's the area between the two columns and I'm going to make that 1. 5 em, and then finally the last and moz with another column property and this time column-rule, which is the straight line between the two columns.
This follows the syntax of CSS borders, so you put in the Width which is going to be 1 pixel, the Type which is solid, and then the Color, and I have a color value that I've picked up from elsewhere on the page. So it's c4c8cc. Press Return. Now we have the Mozilla rules; let's add in the Webkit ones. So -web, and then I can go ahead and hit Return for code hints to complete it, and again C for columns. This time I'm going to scroll down a little bit till I get to column-count and again, that's 2.
Repeat that Webkit column and this time we'll do column-gap 1.5 em. The final one, webkit-column-rule and again, we'll keep this same as we have with Mozilla. So 1 pixel, solid, and then the color value of c4c8cc. Let's make sure that we closed off our CSS rule. We did. So let's take a look in Design view, you'll notice that there is no significant change at all, but if we go into Live view and scroll down, you'll see our two columns automatically taking shape.
The ability to specify multiple columns in CSS is a real boon for web designers, as the feature greatly expands the layout possibilities.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.