Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
In this hands-on course, James Williamson demonstrates the concepts that form the foundation of Cascading Style Sheets (CSS), including styling text, adding margins and padding, and controlling how images display. The course also explores the tools needed to work with CSS, the differences between embedded and external styles, how to use selectors to target elements, and what to do when styles conflict.
So now that we've taken a look at all the different concepts involving style conflicts, it's time for our resolving conflicts lab. Now in this lab I want to test your ability to resolve the conflicts through using the cascade, inheritance, and specificity. Just like the previous lab, there are several different ways that you could accomplish our goals, so while concentrating on how to solve the problems, be sure to think about how the solutions are coming up with works within the overall structure of the site's styles.
You want to make sure you're also doing it in the most efficient way possible. So from the 03_07 directory, I have the galleries.htm file opened and the main.CSS opened that's located in the _CSS folder in the same directory. Okay, it's the same site that we worked at in our last lab. If I preview this in a browser, you can see this time we're just kind of playing around with the galleries page. There are some things going on here that I want to change. I am not happy with the paragraph styling over here. The styling here is obviously wrong. We're having some styling conflicts here within the headers of this page.
So there are some things that we need to clean up and that we need to change based on some style conflicts that are occurring. Okay, I'm going to go back into our code. Again it's very helpful if you review the structure of the page. We have at the very top a page header with an ID of page header. We have a nav with an ID of main nav. That's followed by a section called content. In this case, the article that follows directly inside of section has an ID of galleries. We have interior sections with their own classes applied to them. After the article, we have the aside, which is our sidebar. It has its own nav inside of it, a couple of sections inside of that, and then finally our footer.
So be aware of that structure. Review that structure as you're reviewing the goals for this lab. Now I'm going to switch over to main.css, and one of the biggest changes in this lab compared to the previous lab is that in the previous you went ahead and wrote all your selector in sort of one location, right down at the bottom of the page. But if I scroll down to the bottom of these styles, I find that although we have some instructions down here, this is not the locations that these selectors will need to be. You're going to need to find out where in the selectors, where in the styles themselves, the rules that you're about to write are going to be written. Some might need to be embedded styles, some might be in this external style sheet, some might need to be inline styles.
If you paid attention to last movie where I talked about structure, you might know what my opinion of using embedded styles and inline styles are relating to an entire site, but that might be your decision. So what I want you to do is we're going to go through these one by one, but really you're going to have to understand the structure of our styles as well. So take some time. Go through our styles. Take a look at how they're organized. You know again we have our global styles at top. They are followed by our basic layout styles. Those are followed by constant region styles. And if you take a look at these content regions, you know the header cells show up first. Then we have our navigation styles. Those are followed by our banner styles.
These are actually more or less in the same order of structure that you'll find the page in, and I do that on purpose. Number one it makes them easier to find, and number two, in terms of the cascade, they really help make sure that the styles that you're writing are applied after elements that have come before it. Okay, so you have to determine exactly where to place these selectors or which selectors to modify. Let's go take a look at what we have to write. So the first thing that I want you to do is, these properties, and you can copy and paste these properties and put them inside of the selector that you write, but these properties need to be applied to every element on the page as their default styling.
So you want to make sure that those properties are applied to every single element on the page just as their default styles. That's not the saying they might not be overwritten later on. I just want them to start out as the default styles. The second task is to browse up to line 244--we will do that in just a moment--and view the article styles section. These selectors are conflicting with the page-specific main content styles below them and preventing some of the formatting from those rules from being applied.
Modify the selectors in this section to resolve this conflict. So if I go up to line 244, I can see that here are my article styles. So I have a whole section of article styles, and then below them I have these page-specific styles. Now we're on the galleries page, so that's really what you should probably be paying attention to, but what is happening is these selectors, which are supposed to be sort more global, are actually overriding these selectors, which are page-specific and should be overriding the generic article styles when they're applicable.
So that's not happening right now. You'll need to figure out why that's not happening, and you'll need to modify the selectors in order to make that happen. For the third one, we've got some properties down here that need to be included in a rule that targets the heading 2s on the gallery page only. So remember what we said about area- specific styles, these page-specific styles. So here we have some selectors that are targeting individual page content. You need to take a look at the structure of the selectors and figure out how to structure your own selector to make sure that these properties are only being applied to heading 2s on the gallery page.
And then finally, we need to take these properties and write a rule that changes the paragraph formatting for the text in the page sidebar. Now remember, the page sidebar is that aside. We'll go and take a look at that in just a moment. You should be careful to make sure the rule is written so that it overwrites previous paragraph styling and limits the styling to the contest sections. So within our sidebar we have our archive galleries, and then we have our contest sections. There's two of those. We want to make sure that these properties only write those paragraphs in those contest sections, and you can go up and find those aside styles around line 509.
Okay, so that's what your goals are. Now, I'll admit that this lab is a little bit tougher than our last one, and that's mainly because you're going to have to go in, analyze, and write new styles in a style sheet that you didn't write or organize yourself. Now this could be quite a challenge, I totally understand that, but I'll be honest with you, it's not an uncommon task in the world of web design, so this is actually really good practice. Be sure to pay special attention to page structure and how these styles are organized as well. By going through the page structure carefully, you're going to have a better idea of how to solve the problems I've given you.
Okay, there you go. Have fun!
There are currently no FAQs about CSS: Core Concepts.
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.