Viewers: in countries Watching now:
CSS: Page Layouts introduces basic layout concepts, gives advice on how to create properly structured HTML based on prototypes and mockups, and goes into critical page layout skills such as floats and positioning. Author James Williamson shows how to combine these techniques to create fixed, fluid, and responsive layouts. Designers are also shown how to enhance their pages through the creative use of CSS techniques like multi-column text, opacity, and the background property. Exercise files are included with this course.
In this chapter, we're going to focus on ways that you can enhance your page design through creative styling. I want to start by talking about creating multi-column text. In the past we've had to use some fairly restrictive techniques like floating to achieve multiple columns of text, but recent improvements in CSS have made it fairly simple to modify your text blocks. So I have the multiple-column.htm file from the 08_01 folder opened up, and I'm just going to preview this page for you really quickly to kind of show you what's going on here. We have a little bit of descriptive text, and then we have some body copy right down here that I want to place into multiple columns.
So I'm going to go back into my code, and if I look at the structure of the page, so I know who to target, I can see that the text that I want to target is in a section, and actually that's the only section that we have in the HTML code, so it makes a very quick and easy way to target it. Now, for our first example I am just going to do two of the available properties that we have to control multiple columns. I'm going to do column-count, and I'm going to make the column-count 2. Then I'm going to do column-gap, and I'm going to put the gap at 16 pixels.
So you can probably figure this out, that column-count basically says, okay, how many columns do I want to split this element into, and then the gap describes the amount of space between the columns. So if I save this and go back in my browser and preview it, you can see that now we have multiple columns of text, two columns, and there's 16 pixels' worth of space between them. All right! So other properties that you can control, we have column-width, column-count that we just used, column-gap, and column-rule. There are a few more, but those are really the main ones.
And some of these properties, like column-rule, have more then one property that govern them, but you can use shorthand notation to take care of them all at once if you want. Now, here's the bad news about dealing with multiple columns. Now, you'll notice I am in Opera right now. I'm going to switch over to the Firefox and test my page. Now, I'm going to switch over to Chrome and test my page. No multiple columns. You know, this is one of those instances where support for this is not universal among browsers, but there are ways where we can ask Chrome, Safari, and Firefox to support this property, and that's through the use of something called a vendor prefix.
So I am going to go back into my code and I am just going to take the properties that we wrote here for column-count, I'm going to copy those, and then I'm going to paste them twice. Now, I'm going to go up to the first set and I'm going to add a vendor prefix to that. I am going to add -moz-, and I'll do the same thing to column-gap, -moz-, no spaces there at all. And then right below that I'll do -webkit. WebKit of course is going to cover more than just one browser. That will be Chrome and Safari and any other WebKit-based browser.
I am going to go ahead and save this. Now, what are those? If you haven't seen those before, those are vendor prefixes, and essentially for newer CSS properties that browsers are just adopting, most browsers, including Opera, they will place a vendor prefix in front of the property. Now, what that does is it allows the browser manufacturer to sort of experiment and standardize the way that they support that property, while still allowing designers to utilize it. So when you use something that needs a vendor prefix, you need to go into that with your eyes open and realize that this is an implementation that is still being worked on, so it may not be stable over the course of that particular site.
So it's one of those things that's like, okay, I am going to use this to enhance my page, but I am not going to use it for something that's mission-critical. All right! So if I save this and I go back into Firefox and I refresh, now I get my multiple columns. And in Chrome I get my multiple columns as well. Cool! Now, I want to go back into my code really briefly here and talk about some of the other properties. In particular I want to focus on column-width. So I am going to go right down into section, and I'm just going to do column-width of 22 pixels.
Now, column-width does not do what you might think it does. Yes, it does control the width of the column, but it does not let you specify one column, for example, being wider than another. What happens is the columns are split up equally. So the two properties, column-count and column-width, are very closely tied together. If I save this and I go into Opera and I refresh this, our section is now split into 22 columns, which, while not readable, I find that strangely beautiful. All right! If I go back into my file and I change that to say 120 pixels and test it, you can kind of see what's happening here with the behavior.
Essentially it's saying, okay, of the available space that I have, I have 120 pixels for the column width so I am going to create as many as I can at that width. So what this tells you is that if you use column-width, it's essentially going to overwrite column-count. Column-counts says, hey, within the available space, give me two columns or three columns, and then the browser will calculate those widths for you. It will just automatically figure out those widths. But if you explicitly say, I want columns that are 120 pixels wide, then regardless of what your column-count is, that is what you are going to get.
I am going to go back into my code, and I am going to get rid of column-width, because we don't need that, and I will just go ahead and save that. Okay. So creating multi-column text, I think you can see that that is a really useful ability to have in CSS, but there are a couple of things that you need to keep in mind. Unfortunately, the current state of support means that we still have to treat it as a means of enhancing our designs and not as something that we are going to place into a really, really critical part of our layout, where it would fail if we didn't get our multiple columns. Now, thankfully, support for it has been announced for Internet Explorer 10, and the standardization of support in Firefox and WebKit will mean that we can drop those prefixes fairly soon for those browsers as well.
The other thing that you need to consider too is that when you do this to an element in the page, everything within that element, and I mean everything, is split into those columns, so headlines, images, anything else. So if you have sections of text that you want in multiple columns, but you don't want other content within that element to go into multiple columns, often you're going to have to go back into your code and wrap the text that you want in multicolumn text within a div tag or another section or something of that nature. Images that are too wide to fit in a column will be cropped off.
So those are all things that you need to consider before you start using multiple-column text, but I encourage you to go and experiment with it, because it is definitely something that can help you enhance your page design.
There are currently no FAQs about CSS: Page Layouts.
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.