|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
Dreamweaver Best Practices with CSS in Dreamweaver MX
Cascading Style Sheets (CSS) Is Changing The Website Design Process
By: Rachel Andrew
May. 26, 2005 09:45 AM
The increasing use of Cascading Style Sheets (CSS) is changing the website design process. To meet the rising needs of CSS-conscious designers, Macromedia Dreamweaver MX includes many new and improved CSS-related features. With these new features, you can plan for future updates, build websites that are more compatible with World Wide Web Consortium (W3C) standards, and comply with new accessibility laws. This article discusses best practices when using CSS and highlights specific CSS features in Dreamweaver MX. Style sheets are, in general terms, a collection of formatting rules that control the appearance of content in a web page. You can implement CSS on your pages three different ways:
An important consideration in the use of CSS styles is the fact that different browsers (and different versions of the same browser) render CSS styles differently. In addition to variations in web browser compatibility, you should be aware that many other types of browsers exist, such as aural browsers, TV-based browsers, handheld devices such as Palm Pilots, and TTY (teletypewriter). If you want to learn more about the basics of CSS before proceeding on with a "best practices" analysis, review some of the materials listed in the More Resources section at the end of this article. What does CSS "Best Practices" Mean? In general, developers should aim to "separate content from presentation" as much as possible on all web pages. Proper separation is recommended in order to:
Best Practices with CSS in Dreamweaver MX Inline CSS Dreamweaver MX uses inline CSS mark-up primarily for positioning page elements (these positioned items are called "Layers" in the Dreamweaver MX UI), or to enable a specific DHTML effect which requires an inline style to alter an object¹s properties with JavaScript. Embedded CSS External CSS Files
Creating a CSS style in Dreamweaver MX You can also select an existing style sheet in the New Style dialog box to edit or add more definitions to it. Should You Link or Import Your External Style Sheet? Linking to the style sheet is the most common approach. Selecting the "link" option will attach your external style sheet to your page by adding the following markup: <link href="mystyles.css" rel="stylesheet" type="text/css" /> All CSS-enabled browsers support the linking option, and this method should be followed if you need older browsers (such as Netscape 4.x) to "see" the styles. If you choose the "import" option, the style sheet will be attached with the following mark-up:
<style type="text/css">
<!--
@import url("mystyles.css");
-->
/style>
The import method of attaching a style sheet is not recognised by the older, version 4, browsers. However, it can come in handy. Developers often use the import method in order to include CSS styles designed for new browsers while also linking to an external style sheet to include styles for Netscape 4.x. This technique is explained in more detail below. One Strategy to Cover Newer and Older Browsers To accomplish this, you first attach the style sheet for the older browsers using the link method. Then, select import to attach the style sheet for newer browsers. The resulting code will look similar to this:
<link href="oldbrowsers.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
@import url("newbrowsers.css");
-->
</style>
The version 4 browsers will completely ignore the imported style sheet and render the page according to the values in the linked one, leaving you free to fully use the capabilities of CSS for those browsers that support it. This approach eliminates the possibility of causing an unreadable page in older browsers. The CSS Property Inspector You can always toggle back into HTML mode to work on a non-CSS based website. Ready-Made Style Sheets To get started, choose File > New. In the New Document dialog box (under category) select CSS style sheets. A whole list of ready-made style sheets will appear in the right-hand pane. To implement best practices, you should choose one of the style sheets marked Accessible (see Figure 4). You can now save this document into your site folder and attach the CSS file to your pages as described above. Design Time Style Sheets Design Time style sheets will also be helpful for developers who are using style sheets that will be housed on the server-side (with, for instance, ASP, PHP, or ColdFusion Application servers) or accessed with JavaScript on the client side. These server-side style sheets are another way to cope with the lack of CSS support in older browsers. However, in previous versions of Dreamweaver, this approach restricted you from seeing the effect of the style sheet applied to your page while you were designing. Design Time style sheets allow you to apply your style sheet so you can work visually within Dreamweaver. Another benefit to using Design Time style sheets is that when you upload your site files, you won¹t have to remember to go through the site removing unnecessary style sheets. Validation Dreamweaver MX does not have a CSS validator, but you can accomplish this by using the W3C CSS Validation Service on the W3C website. Alternately, you can validate your HTML or XHTML mark-up from within Dreamweaver MX by choosing File > Check Page > Validate Markup (for HTML) or File > Check Page > Validate as XML for XHTML. Dreamweaver MX provides you many tools that will assist you in the development of your CSS-based websites. With Dreamweaver MX and a solid understanding of CSS and the importance of writing valid, accessible CSS code, you are well on your way to creating websites that will stand the test of time. More Resources The Dreamweaver MX Help documentation. For further, more advanced information on CSS, consult these sites: Reader Feedback: Page 1 of 1
Your Feedback
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||