Flylib.com

Books Software

 
 
 

Recipe 1.16. Using Relative Positioning


Recipe 1.16. Using Relative Positioning

Problem

You want to place content based on its position in the document. In other words, the element's position is modified relative to its natural position as rendered by the browser.

Solution

Use the position property with the relative value in the style sheet. Also add top , left or both properties to indicate where to position an element.

Using the following CSS rule on the image, the image was able to move over the paragraph content in Figure 1-39:

.relative {
 position: relative; 
 top: 100px; 
 left: 20px;
}

Figure 1-39. Relative positioning places an element based on its location within the document's natural flow

Discussion

Unlike absolute positioning, the sample code doesn't start at the top and left edges of the window. Instead, it begins where p elements would be if left alone. The code tells the browser to position the paragraph 100 pixels down from the top and 20 pixels over from the left edge of the original paragraph's position instead of from the edge of the window. With absolute , the content is placed exactly where the properties tell it to go from the edges in the current box.

See Also

W3C 2.1 specification on relative positioning at http://www.w3.org/TR/CSS21/visuren.html#relative-positioning and W3Schools tutorial on positioning at http://www.w3schools.com/css/css_positioning.asp.



Recipe 1.17. Using CSS in Adobe Dreamweaver

Problem

You use Dreamweaver for creating and editing web pages and want to use its CSS features.

Solution

Use the CSS Styles Panel to create, edit, delete, and view CSS styles (see Figures 1-40 and 1-41). You have several ways to work with styles sheets. While editing an HTML page, you can attach an external style sheet through the CSS Styles panel or start a new CSS document (click File New and then choose Basic page and CSS).

Figure 1-40. Start a new CSS file in Dreamweaver

Figure 1-41. Enter and edit styles in Dreamweaver's CSS document

Another option is to use the Code or Split view and enter the CSS directly into the code for inline and internal style sheets.

  1. To attach an external style sheet to any web page in Dreamweaver, click the Attach icon on the CSS Styles Panel (see Figure 1-42).

  2. Click File New and choose Basic page and CSS to start a blank CSS document.

  3. Edit the web page like a word document, Dreamweaver automatically adds internal styles.

  4. Enter styles in Code view.

You can view CSS properties by categories, such as font, background, and border. You can switch to List view, an alphabetical list of properties.

Figure 1-42. Use Dreamweaver's CSS Panel to attach an external style sheet

Discussion

If you add styles to content within an HTML page in Dreamweaver, using Properties, the application automatically adds inline CSS (see Figure 1-43). As you select fonts and color to selected text, Dreamweaver creates an internal style sheet rather than use font element. In older versions of Dreamweaver, the code would look like the following:

Figure 1-43. Dreamweaver automatically creates new styles when assigning font and colors to text

<font face="georgia, times new roman, serif" color="#ff0000" 
size="2">This is text.</font>

You can review the style sheet generated by Dreamweaver (see Figure 1-44).

Figure 1-44. Review the current document's styles in the CSS panel

See Also

Adobe's Best Practices of CSS selectors http://www.adobe.com/products/dreamweaver/bestpractices/css/ and Dreamweaver home at http://www.adobe.com/products/dreamweaver/.