Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat?
CSS in ContextNemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni 17 Licensed to siowchen@darke.biz Chapter 1: Getting the Lay of the Land dolores eos qui ratione voluptatem sequi nesciunt Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Keep Adding ContentYou can see that as you keep adding content to this page, it adds nicely boxed and centered material down the center of the page.
Some Links- Rachel Andrew
- SitePoint Home
- SitePoint Forums
- Firefox
- Internet Explorer
- Opera
- Safari
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident.
18 Licensed to siowchen@darke.biz Chapter 2: Putting CSS into Perspective Here’s the style rule that creates the effect in Figure 2.2 As you can see, it’s fairly straightforward, yet the result of its use is certainly dramatic body { color: yellow; background-color: black; } As we’ll see in Chapter 5, naming the colors you want is just one of several ways to define color in CSS Here’s the style rule that creates the effect in Figure 2.3 No surprises here: it’s the opposite of the code that was used to generate the look in Figure 2.2 body { color: black; background-color: yellow; } Figure 2.3 Black-on-yellow version of fall holiday page Maybe you find the use of a starkly contrasting color for the entire background of a page a bit overwhelming Figure 2.4 shows another variation on the text color theme Here, we’ve provided yellow text on a black background only behind the headings on the page The rest of the page’s background color, and all nonheading text, remains unchanged from the original design in Figure 2.1 24 Licensed to siowchen@darke.biz Fonts and CSS Figure 2.4 Yellow-on-black headings on fall holiday page Here’s the style rule that generates the heading effect shown in Figure 2.4 h1, h2, h3, h4, h5, h6 { color: yellow; background-color: black; } Notice that we didn’t have to anything fancy, like put the headings inside and tags, or create a rectangular box around them In the view of the web browser, the heading is a block level element, which occupies the full width of the space in which it resides, by default So, if you give a heading a background-color property, that property will apply to the entire horizontal block that contains the heading CSS provides a range of other advantages to the color-conscious designer, but we’ll leave those details to Chapter Our purpose here is merely to touch upon the variety of things you can expect to accomplish using CSS Fonts and CSS In Chapter 1, we saw a number of examples that used fonts in CSS style rules From that exposure, you’re probably comfortable with defining the fonts in which you want the body text and headings of various levels to be displayed You can apply fonts to smaller amounts of text by enclosing that text within and tags (a subject we’ll treat in detail in Chapter 9), then ap 25 Licensed to siowchen@darke.biz Chapter 2: Putting CSS into Perspective plying style properties to the span You might use this approach, for example, to highlight a sentence in the middle of a paragraph, as shown in Figure 2.5 Figure 2.5 Highlighting an important sentence To this, we simply need to wrap the sentence in and tags, then add a style rule for the new span Note that these span elements should be used sparingly, and that there are a number of issues to consider before you apply these techniques—see Chapter and Chapter for all the details Below is the HTML that was used to create this effectLorem ipsum dolor sit amet, consectetur adipisicing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
You can target a particular span by adding an id or class attribute (we’ll look at this in more detail in Chapter 3), then adding the id or class to the selector, as shown here: important { font-weight: bold; background-color: yellow; color: red; } One type of HTML text element to which it’s sometimes quite useful to apply font rules is the list We generally create lists in an effort to call specific attention to several items that are related to one another, and using a font style to set the list off even more clearly from the text can be a good technique Figure 2.6 shows a list that has been set in a font that contrasts with the main text of the page, 26 Licensed to siowchen@darke.biz Fonts and CSS and is bold The list stands out from the page, calling attention to itself as being particularly important Figure 2.6 Highlighting an important list Once we’ve identified this list in HTML using an id attribute, we can style it by adding a rule to our style sheet- children (at 7:30 p.m in the downstairs kitchen)
- teens (at 9:30 p.m in the youth room)
- adults (at 11:00 p.m in the fellowship hall)