19 November 2012
Before starting this tutorial, read and complete the steps in
Beginning
Welcome to Part 3 of this six-part tutorial series on creating your first website. This tutorial shows you how to style the main heading using Adobe Edge Web Fonts, a library of hundreds of free fonts that you can use in your website. You’ll also learn how to eliminate the gap that often appears at the top of web pages, and how to convert an unordered list of links into a horizontal menu bar. The menu bar and main text will be maneuvered into position using a combination of relative and absolute positioning.
In Part 1 and Part 2 of this tutorial series, you defined a site for Check Magazine, a fictional publication, and created the basic structure for the home page. If you completed the first two parts, continue working with your existing files. If you’re not sure whether your HTML and CSS is correct, you can download the first_website_pt3_begin.zip sample file, and use its contents to replace your existing files.
At the end of Part 2, the page was still very bare (see Figure 1).

In this tutorial, you'll style the header section, and add the main text area. Figure 2 shows what the page will look like in a browser when you’re done with Part 3.

You’ll start by using a web font for the main heading.
The main heading uses a font called Sarina, which is not available on most computers, but you can add it to your web page using Adobe Edge Web Fonts, a vast library of free web fonts from Adobe, Google, and designers around the world.

To access the full range of fonts, you need either a subscription-based or free Creative Cloud membership. However, you can access a limited range even without signing up, so that’s what you’ll do in this tutorial.
The editable area below shows a preview of the font together with instructions on how to use it (see Figure 4).

<script> tags from the Edge Web Fonts site, and paste them into the <head> section of index.html in Dreamweaver just above the <link> that attaches the style sheet like this:<head>
<meta charset="utf-8">
<title>Check Magazine</title>
<script src="http://use.edgefonts.net/sarina.js"></script>
<link href="styles/check_cs6.css" rel="stylesheet" type="text/css">
</head>

font-size to 96px like this:h1 {
font-family: sarina, serif;
font-size: 96px;
}
<div>, and click the New CSS Rule icon at the bottom-right of the CSS Styles panel.<div>, so change the value of Selector Type from Compound to ID. Dreamweaver CS6 automatically changes the value of Selector Name to header.Note: If you’re using an earlier version of Dreamweaver, changing Selector Type to ID clears the Selector Name field. You need to type header manually.
#FFF) from the color picker (see Figure 6). This sets the color of the text.
#000).
Although there is nothing above the header, it has been pushed down the page, leaving an ugly white gap at the top. Also, the links in the unordered list haven’t changed to white like the rest of the text. Both issues need to be fixed. First, you’ll deal with the gap above the heading.
In this section, you’ll use Inspect Mode to investigate and fix the cause of the gap at the top of the page.

An unusual feature of CSS is that adjacent vertical margins merge to the height of the largest one. As a result, the heading’s top margin extends beyond the header <div>, pushing it away from the top of the page.
Notice also that there’s a narrow white strip above the top margin. That’s caused by browsers adding a default eight-pixel margin around the <body> element. You need to fix both issues.
h1 in the All Rules pane to display the properties for the heading.
margin.
<body> element to remove the default margin around the page. Click the New CSS Rule icon at the bottom right of the CSS Styles panel.<body> element are inherited by the rest of the page. So, in addition to removing the default margin, it’s a good idea to set the default font, text color, and background color.<div> is unchanged because you set a different color in the #header style rule earlier (see Figure 11).
#FFF).The Fashion + Lifestyle tag line needs to sit alongside the Check heading. The tag line is in a paragraph, while the heading is in an <h1> tag. CSS treats both as block-level elements that occupy a new line. To move them alongside each other, you need to apply the float property to the heading. This moves it to the side, allowing other elements to move up alongside. Once the tag line moves into the space next to the heading, you can adjust its padding and margins to move it into position.
left.<div>. #container #header p as the Selector Name. You don’t need #container. So, click Less Specific once to change the selector to #header p.30px.small-caps.
The final stage of fixing the header <div> involves converting the unordered list of links into a horizontal navigation bar. You’ll start by giving the the links a different color and font styles.
The links in the navigation bar need to have a style that won’t be shared by other links in the page. You do this with a selector that targets only links in the header <div>.
<div>, and then click the New CSS Rule icon at the bottom-right of the CSS Styles panel.#container #header ul li a as the Selector Name. Although this does what you want, it’s more efficient to simplify the selector.#header ul li a. Again, this is accurate, but all you need to target links inside the header <div> is #header a.ul li. As you edit the selector, the description below the field changes to show you which elements will be styled (see Figure 13).
20pxboldsmall-caps#FFF (white)none# in the Link field of the Property inspector. It’s styled differently from the links in the header because the #header a style rule that you have just created affects only links in the header <div> (see Figure 14).
To convert the links in the unordered list into a horizontal navigation bar, you need to remove the bullets, give the links a width, and turn them into block-level elements so that the full width of the link becomes clickable. Finally, you need to float them to the left.
<div>. Then select <ul> in the Tag selector at the bottom of the Document window (see Figure 15). This highlights the whole unordered list.
#container #header ul as the Selector Name.#header ul. Then click OK to create a style rule for the unordered list in the header <div>.none.#header a in the All Rules pane of the CSS Styles panel. Then click the Edit Rule icon at the bottom-right of the panel (see Figure 16) to reopen the CSS Rule Definition dialog box.
center, and Display to block.100px.<div>, and select <li> in the Tag selector at the bottom of the Document window. This selects the whole list item so you can define a style rule for list items in the header.#header ul li. Then click OK.left.
The problem is caused by both the main heading and the navigation bar floating. When items float, they’re no longer constrained by the element they’re nested inside—in this case, the header <div>.
#header in the All Rules pane of the CSS Styles panel, and click the Edit Rule icon.100px, and click Apply. The navigation bar should reappear and the main image move further left (see Figure 18).
Note: Don’t worry that the main image is still off to the right. Design view doesn’t always show an accurate representation of page layout.
The layout design calls for the menu to be at the bottom-right of the header. To move it into position, you’re going to use absolute positioning. Before showing you how to do it, I must sound a word of warning. Many beginners fall into the trap of trying to lay out their entire design with absolute positioning (or AP Elements, as Dreamweaver calls them).
Note: Earlier versions of Dreamweaver called absolutely positioned elements Layers or AP Divs. However, any HTML element can be absolutely positioned. It doesn’t apply only to <div> elements.
The attraction of absolute positioning is that you can place an element precisely on a page, making web design feel almost like desktop publishing. However, the web is a fluid medium. People view pages on different size screens, and at different resolutions. Absolutely positioned elements behave in a very different way from other elements. They stay where you put them, and don’t interact with the rest of the page. This often creates the illusion that the absolutely positioned element moves. In fact, the opposite happens; the rest of the page moves in relation to the absolutely positioned element. Also, an absolutely positioned element might disappear off screen on a mobile device without generating a scrollbar, making vital information inaccessible.
Although absolute positioning presents problems for laying out entire pages, it can be very effective when you want to align an element with another. You specify the position as one or two offsets from the element’s sides. For example, if you set the left offset to 150px and the top offset to 100px, the left and top sides of the element are positioned exactly that distance away from the element’s containing block (see Figure 19).

Note: The offsets can be positive or negative. As Figure 19 shows, a positive 150px left offset moves the element 150px to the right away from the left of the containing block. A negative offset moves the element in the opposite direction outside its containing block, which is simply the point from which the offsets are calculated.
The secret to using absolute positioning successfully is understanding the principle of the containing block. Usually, an element’s containing block is the nearest block-level element higher up the HTML structure. In the case of the navigation bar, this is the header <div>. However, absolute positioning is different. The containing block is the nearest element higher up the HTML structure that has its position property set to absolute, fixed, or relative. If no such element exists, the page becomes the containing block.
To fix the navigation bar at the bottom-right of the header, the bottom and right offsets need to be set to 0. However, without first defining a containing block, the navigation bar would end up at the bottom-right of the page. To calculate the offsets from the header <div>, you need to set its position property to relative. Relative positioning is similar to absolute positioning, except the offsets are calculated from the element’s normal position in the document. So, if you make an element relatively positioned, but don’t set any offsets, it remains in its normal position, but with the crucial difference that it acts as the containing block for any absolute elements nested inside. It sounds complicated, but it’s very simple to implement.
So much for the theory. Now you can put it into practice to dispel any doubts you might have about the preceding explanation.
#header ul, and click the Edit Rule icon.absolute0px0px#header a, in the All Rules pane of the CSS Styles panel.color property in the lower pane to reveal an icon with a tooltip that reads Disable CSS Property. Then click the icon to temporarily disable the color of the links. You should now see the navigation bar at the bottom-right of the Document window (see Figure 20). The navigation bar doesn’t have a positioned containing block, so the offsets are calculated from the bottom and right of the page rather than the header <div>.
<div>, you need to make the <div> relatively positioned. Select the #header rule in the All Rules pane of the CSS Styles panel.<div> (see Figure 21).
Note: Design view sometimes gets confused by positioned elements. If the header disappears in Design view, close and reopen index.html.
Although the main_image <div> looks as though it’s filled with a large image, there’s actually nothing inside the <div>. The image is simply the background. The design calls for a block of text with a white background to be placed close to the white cross at the bottom-right of the image. You’ll use the same technique as for the navigation bar to move the text into position using a combination of relative and absolute positioning.
The text consists of two headings and a paragraph, so you need to create a <div> to hold them all together, and nest it inside the main_image <div>.
The most accurate way of inserting a new <div> is to use the options in the Insert Div Tag dialog box. It doesn’t matter where the Insertion point is, the options enable you to insert the <div> accurately, as long as your page elements have IDs.
Alternatively, use the Insert menu. In the Creative Cloud update, choose Insert > Div. In earlier versions of Dreamweaver, choose Insert > Layout Objects > Div Tag.

The options available are:
<div> is inserted wherever the Insertion point currently is. <div> is inserted immediately before the specified element’s opening tag.<div> is inserted immediately after the specified element’s opening tag. <div> is inserted immediately before the specified element’s closing tag. <div> is inserted immediately after the specified element’s closing tag.<div> is wrapped around the selected element(s).<div> needs to be nested inside the main_image <div>, so it needs to go after the starting tag of main_image. Set the Insert pop-up menu to After Start Of Tag. (Because the main_image <div> is empty, you could also use Before End Of Tag in this case.)This activates a new pop-up menu to the right of the Insert pop-up menu.
<body> tag, along with all other page elements that have an ID (see Figure 23).
<div id="main_image"> from the list.#main_text). However, you need to check that Rule Definition is set to check_cs6.css. If it says This Document Only, select check_cs6.css from the Rule Definition list.#FFF). <div> to 300 pixels. <div> with some placeholder text. <div> should now have a 300-pixel wide, white box containing placeholder text (see Figure 24).
The white background of the main_text div covers the background image, so the text can be clearly read.
<div>, and paste the text from your clipboard by pressing Ctrl+V/Cmd+V or choosing Edit > Paste.The text you copied from main.txt replaces the placeholder text, and the main_text <div> automatically expands vertically to accommodate it (see Figure 25).

The main_text <div> will be absolutely positioned with the main_image <div> as its containing block. Although the technique is the same as used for the navigation menu, you need to work out the offsets from the bottom and right of the main_image <div>. You could try to judge the distance by eye and keep adjusting the values until you get it right. A more efficient way is to use guides in the Dreamweaver Document window to measure the distance accurately.

485px).<div> to be. The exact position isn’t important. Use your eye to judge what looks good.
Note: If you have difficulty positioning the guides, double-click one of the guides to open the Move Guide dialog box, and set the position by typing a value in the Location text box. Use 425px for the horizontal guide. The value for the vertical guide will depend on the size of the Document window. Double-click the guide on the right edge of the main image to find its position, subtract 60, and use that value for the main_text vertical guide.
<div> the containing block for the main_text <div>, so select #main_image in the All Rules pane of the CSS Styles panel. #main_text and click the Edit Rule icon to reopen the CSS Rule Definition dialog box for the #main_text style rule.px.<div> should move into position.<div> should be aligned precisely with the green guides, as shown in Figure 28.
Note: If the main_text area still doesn’t move. Try closing index.html and reopening it.
The Check Magazine home page is beginning to take shape, but it needs more content. You’ll add that next in Part 4: Inserting images and styling text.
Comments are currently closed as we migrate to a new commenting system. In the interim, please provide any feedback using our feedback form. Thank you for your patience.
Tutorials and samples |