17 August 2009
This tutorial requires some basic knowledge of Fireworks CS4, web design concepts in general, and XHTML/CSS code.
Beginning
Adobe Fireworks CS4 is a powerful graphic design tool to be used mostly for web design. Its excellent combination of vector/bitmap tools and live effects is unique in the web design world. But Fireworks is much more than that; it can also export a graphic design as images and (almost) valid CSS code—thus helping graphic designers or web designers create a working web page in a very short time. The output from Fireworks can be used then as a working demo, which could be presented to a client for approval (before the actual XHTML/CSS coding of the page will start) or as a good basis for the final web design code. In either case, the ability for Fireworks to create the CSS and slice the images automatically can be very useful.
So what will you learn in this tutorial?
First, I will list the key tools that can help you when preparing a Fireworks web design mock-up to go to the web. I'll review each tool in detail and will provide some examples. I will illustrate my work with graphic samples and screenshots. Second, I'll continue with a simple website design mock-up example (you will be able to open and deconstruct the PNG file, which is provided with this tutorial). Finally, I will review and help you optimize quickly the exported CSS/HTML code.
As a basis for my work, I have used my working experience with Fireworks CS4 and a variety of external resources, including one excellent Fireworks Developer Center article, Creating standards-compliant web designs with Fireworks CS4, by Matt Stow. You may want to check the article first, but don't worry—this is not obligatory at all, as I will guide you step by step in this tutorial.
The screenshots throughout the tutorial are made on Windows XP Professional. They should be very similar on Windows Vista and Mac OS X.The keyboard shortcuts are noted as in Windows, but if you are working on a Mac, simply substitute the Control key with the Command key, and Alt key with the Option key.
In case you are familiar with certain operations that I show in detail, you can safely skip some parts of the tutorial.Some sections in the tutorial have related sample PNG files, which you can study and deconstruct. To find them, unzip the ZIP file supplied with the tutorial. Inside, you will find two folders:
Note: When you open the sample files, Fireworks may show you the Replace Fonts dialog box (see Figure 1). This is normal if Verdana is not installed on your system. (I used Verdana in all Fw PNG examples.) Verdana is one of the most widespread fonts, both on the Windows and Mac platforms, but if it's missing on your system, you can install it manually; or you could simply ignore the dialog box, as the examples will work even if the font is missing. Just select the option "Maintain Appearance"—this will keep the elements' position in the examples unchanged.
Before beginning this tutorial, you need to update two important components in Fireworks CS4: the CSS Export Script itself and the HTML library. You should also upgrade to the latest version of Fireworks CS4.
Both the CSS Export Script and the HTML library in Fireworks CS4 have updated versions (created by Matt Stow). You should use the contents of the Fw CS4 Updated Components folder in the ZIP archive provided with this tutorial.
First, update the CSS Export script in Fireworks. Navigate to Fireworks' HTML Code folder and rename the file CssLayers.htt to Old_CssLayers.htt.
C:\Program Files\Adobe\Adobe Fireworks CS4\Configuration\HTML Code\CssLayers.htt
[User account]/Library/Applications/Adobe/Adobe Fireworks CS4/Configuration/HTML Code/CssLayers.htt
Copy and paste the new CssLayers.htt to the same location (the new file is in Fw CS4 Updated Components\CSS Export Script\CssLayers.htt). Your CSS Export script is now updated.
Next, update the HTML Symbols. Navigate to Fireworks' Common Library folder.
C:\Program Files\Adobe\Adobe Fireworks CS4\Configuration\Common Library
[User account]/Applications/Adobe Fireworks CS4/Configuration/Common Library
Create a new folder here called HTML Enhanced, then copy all PNG and JSF files from Fw CS4 Updated Components\HTML Symbols\HTML in the ZIP archive for this tutorial and paste them into the new folder you just created. You can now use the HTML enhanced component symbols and the Export to CSS and Images.
In May 2009, Adobe released a very important update to Fireworks CS4, version 10.0.3. I strongly recommend updating your copy of Fireworks. This update addresses several critical issues present in Fireworks CS4 (including the text-shifting bug). You can read more at the Fireworks Support Center.
The 10.0.3 update can be downloaded from the Support Center (both Windows and Mac versions are available) or you can use the Adobe Auto Updater. Here's how:
That's all, your copy of Fireworks was updated successfully!
Let's say you have created your amazing website design in Fireworks. It's still just an image of a website, a simple PNG file, and it's not yet close to the actual real-life website you would like to show to your client, even as a draft or mock-up, before the design goes into production phase. Or say you are a graphic designer and web designer at the same time, but your experience with CSS is rather limited and you'd like to get some external help to speed up things with code creation. In either case, Fireworks CS4 can help.
Here I will present to you a very simple web design mock-up, made in Fireworks. (You can find the PNG file in the folder: Fw CS4 Tutorial Demo Files\ex-12-design-mockup-demo.fw.png.) Figure 4 shows the website mock-up, made in Fireworks, with the main page elements—header, navigation, main_content, sidebar, footer—labeled in green.
The layout is very basic, but once you master the technique in such a simple example, it'll be very easy for you to prepare more complex website mock-ups in Fireworks, which you will export later as CSS code and images (see Figure 4).
Here are the key tools that you'll be using throughout this tutorial:
I'll review all these three features in great detail in the next sections. Once you master all of the tools to export a web design mock-up as CSS and Images, you'll be able to open, test and understand better the demo file provided at the end of the tutorial (ex-12-design-mockup-demo.fw.png).
This feature will enable you to tag text objects (by following a very simple naming convention) in such a manner that they will match the corresponding XHTML tags on output.The XHTML elements that can be automatically created from a text object are as follows: <div>, <span>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <p>, <a>, <blockquote>, and <label>. If you do not specify a tag, or if you specify a tag different from one of these 12 elements, Fireworks will simply produce a paragraph (<p>) and place it inside a <div> element—for better CSS layout compatibility.
When you want to specify that a text object should use a specific tag, name its beginning with the tag name, like this:
<h1>title
or like this:
<div>
Now you'll see how to put this knowledge into practice, by creating your first, very-easy-to-do example:
<h1>.To change the name of the text object, first select it and then either double-click its name in the Layers panel (if the Layers panel is not open, press F2 to open it) or change its name in the Property inspector (see Figure 7).
<h1>title
<h1>title, and you want to export the file to see the results. Use the Export dialog box (File > Export or Control+Shift+R) to export your document. Select CSS and images from the pop-up menu (see Figure 9 for more details).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>hello-world</title>
<link rel="stylesheet" type="text/css" href="./test.css" media="all" />
<!--[if IE]>
<style type="text/css" media="all">.borderitem {border-style: solid;}</style>
<![endif]-->
</head>
<body>
<div id="main">
<h1 class="h1_title">
Hello World!
</h1>
<div class="clearFloat"></div>
</div>
</body>
</html>
So, the text block was exported correctly as <h1> and also received automatically the class of "h1_title". (The corresponding CSS styles can be found in the file hello-world.css, which was automatically created together with the file hello-world.html. You may check it, if you like, but I'll be reviewing the CSS code in more detail later.)
Similarly, you can tag a text object as <h2>, <h3>, or <div>—take your pick and experiment! You can choose from the 12 elements I have mentioned earlier (<div>, <span>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <p>, <a>, <blockquote>, and <label>).
In this example, I used <h1>title as the name for the text object, which generated the following piece of code:
<h1 class="h1_title">Hello World</h1>
If I had named the text object simply <h1>, then the output would be (a bit surprisingly):
<h1 class="h1">Hello World</h1>
and not just:
<h1>Hello World</h1>
This is how the CSS export in Fireworks works. It will always assign a class to the object, when you export it as CSS.
Also note that the CSS Export positions the text according to its bounding box and not to its actual position on the canvas. So, when you prepare your design/mock-up to be exported as CSS and Images, it is important to position the text so that the bounding box is positioned exactly where you want the text to be positioned on export. The text then can appear slightly unaligned in your design in Fireworks (because you'll use the bounding box as a guide)—but when it's exported, it'll position exactly where you want it.
Before I move to the other components in Fireworks, you may check the sample file ex-01-text-tagging.fw.png, related to tagging of text blocks (it's in the Fw CS4 Tutorial Demo Files folder). Open it in Fireworks CS4 and check its contents. It contains just three text blocks, each on a separate layer, each text block having a specific name, which will output a correct HTML tag on CSS export. Then export it as CSS and Images and check the output HTML and CSS. The example will help you better understand the text tagging options.
To access the new HTML component symbols (rich symbols), open the Common Library panel (Window > Common Library, or press F7), shown in Figure 13.
Rich symbols were first introduced in Fireworks CS3. In Fireworks CS4 they were improved, which includes the new HTML Enhanced symbols by Matt Stow.
Note: In Fireworks CS4, Rich Symbols were renamed to "Component Symbols," which is now a more exact term. However, you can find both Component Symbols and Rich Symbols used in the Fireworks CS4 Help files. They mean one and the same thing, actually, so this should not confuse you.
Together with the tagging of text elements, the HTML symbols can help you a lot in preparing your website design to be exported as XHTML, CSS and images. In the HTML Enhanced folder in the Common Library panel, the following symbols can be found: Button, Checkbox, ComboBox, Heading 1, Heading 2, Heading 3, Heading 4, Heading 5, Heading 6, Link, List Item, RadioButton, TextArea and TextField. All of the form elements have both Windows Vista and Mac OS X default theme variants.
Note: To learn more about how to create new rich symbols, you may read the following two articles:
Follow these easy steps:
An HTML symbol's properties can be changed through the Symbol Properties panel while the symbol is selected on the canvas. Select the symbol and open the Symbol Properties panel (see Figure 12) to view or edit the symbol's properties:
:hover (when you mouseover the link), or any other available property.
I will review some of the available properties of HTML symbols, as well as their possible uses in your designs.
The Heading 1 to Heading 6 symbols (they will produce the heading tags <h1> to <h6> on export) have the following editable properties:
So, should you use a symbol when you want to produce a heading in the HTML code, or should you use a regular text block with the correct name (for example, "<h1>title" or "<h1>another_title")?
It depends. While HTML symbols—including the ones used for headings—can be useful, you should know their limitations. For example, they cannot have multiple lines of text (a regular text block is much more flexible in this aspect), symbols cannot have a specified width (they always size themselves to their text content), and changes in the Line height value in a symbol won't be represented in Fireworks visually (they will be seen in the output code, though).
Note: There are also some other subtle differences: for example, a text element marked as "<h1>title" will produce an <h1> tag in the HTML with the class of "h1_title". And a Heading 1 symbol with the default name of "Heading1" will produce an <h1> tag in the HTML, with the ID of "Heading1". HTML Symbols produce IDs, and tagged text elements produce classes in the HTML.
While in most of the cases the use of an HTML heading symbol (instead of a regular text block, named appropriately) can't be that much recommended, the link and form element symbols can be very useful in preparing your design (I'll review them next).
I have included an example PNG file that will help illustrate better the difference between tagging a text element as <h1> and using a Heading 1 HTML symbol. Open the file ex-02-heading-symbols-and-tagging.fw.png from the Fw CS4 Tutorial Demo Files folder. Export it as heading-symbols-and-tagging.html (choose the Export as CSS and Images option), and then open the HTML file in your browser and view its source. It will be similar to this code:
<h1 id="h1_symbol">
Heading 1 Symbol
</h1>
<div class="clearFloat"></div>
<h1 class="h1_tagged_text">
Heading 1 Tagged Text
</h1>
You will see that the Heading 1 symbol received an ID and the text block, tagged as <h1>, received a class, when exported. Experiment and study the example to understand the differences more clearly.
The Link symbol has the following editable properties:
You can also edit the color, font weight and text decoration properties for the :visited, :hover, and :active CSS pseudo-classes.
Let me show you a quick example of using a Link symbol:
:hover states), or any other available property (see Figure 13).
Locate the exported HTML file and open it in your browser. Notice that the link is keeping all of the edited properties of the symbol that you changed. The link will also have an ID, which will be created based on the object's name in Fireworks. For example, if the Link symbol you inserted in the PNG file has the default name of "Link," the ID of the link will be "Link". See the sample HTML code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="./link-test.css" media="all" />
<!--[if IE]>
<style type="text/css" media="all">.borderitem {border-style: solid;}</style>
<![endif]-->
</head>
<body>
<div id="main">
<a href="#" id="Link">
Link
</a>
<div class="clearFloat"></div>
</div>
</body>
</html>
The relevant CSS styles (which style the link and the whole HTML document) are automatically generated by Fireworks, too, and can be found in the linked file link-test.css.
Finally, you may open and review the example PNG file for this illustration: ex-03-link-symbol.fw.png. You can export the file as link-symbol.html and review the symbol's properties in Fireworks, as well as the exported HTML and CSS code.
The improved HTML symbols include the List Item symbol. You'll be using it a lot in your designs, because HTML unordered lists (<ul>/<li>) play a very important role in today's web design process. For example, they are extensively used for navigation, which is semantically logical and correct—most of the time, a navigation block is just an (unordered) list of links.
The List Item symbol has the following editable properties:
The Node type and Is link? properties of the List Item symbol are very important:
<a href="#">) inside the list item (<li>), and thus allow you to style it similarly to the Link symbol.The options for the Node type property are as follows:
<li>text</li><ul><li>text</li><li>text</li></ul><ul><li>text</li></ul>By combining a few List Item symbols, and setting their Node type correctly, you can export a nicely structured unordered list—for example, to create a navigation block.
To better understand the Link Item symbol and how it works, I'll show you a simple example now. You'll create a short horizontal navigation list like the one in Figure 14.
Then you'll export it as valid CSS and HTML code. Here's how to proceed:
(If the Layers panel is not open, use Window > Layers, or press F2.)
If you followed the instructions closely, the HTML source will be very similar to this one:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>ex-04-nav-list</title>
<link rel="stylesheet" type="text/css" href="./nav-list.css" media="all" />
<!--[if IE]>
<style type="text/css" media="all">.borderitem {border-style: solid;}</style>
<![endif]-->
</head>
<body>
<div id="main">
<ul class="symbolList">
<li id="link1">
<a href="#">Nav Link 1</a>
</li>
<li id="link2">
<a href="#">Nav Link 2</a>
</li>
<li id="link3">
<a href="#">Nav Link 3</a>
</li>
<li id="link4">
<a href="#">Nav Link 4</a>
</li>
</ul>
<div class="clearFloat"></div>
</div>
</body>
</html>
Fireworks CS4 has created automatically an unordered list (<ul>), and has assigned to each list item (<li>) an ID, based on the each symbol's name, which you have assigned in the Layers panel.
For your reference, I have provided a ready-to-use Fireworks PNG file ex-04-nav-list.fw.png. Open this file and export it using the Export as CSS and Images option, then view its source to compare with your results.
Using the List Item symbol in Fireworks, you can also easily create vertical unordered lists. But when you attempt to create a vertical unordered list, the float—clearing mechanism in Fireworks CS4 will generate invalid HTML code upon export. To avoid that, when you create a vertical navigation, simply remove the float—clearing <div> elements and assigning the class of "clearFloat" to each of the list items (<li>). I will better explain this with an example.
The list shown in Figure 18 is very simple, and looks much like the list in the previous (horizontal) example, with the difference that the four list items are arranged vertically.
The file for this example is ex-05-nav-list-vertical.fw.png. Open the PNG sample file and export it using the Export as CSS and Images option. The HTML for the vertical list, automatically created by Fireworks, will be as follows:
<div id="main">
<ul class="symbolList">
<li id="link1">
<a href="#">Nav Link 1</a>
</li>
<div class="clearFloat"></div>
<li id="link2">
<a href="#">Nav Link 2</a>
</li>
<div class="clearFloat"></div>
<li id="link3">
<a href="#">Nav Link 3</a>
</li>
<div class="clearFloat"></div>
<li id="link4">
<a href="#">Nav Link 4</a>
</li>
</ul>
<div class="clearFloat"></div>
</div>
You will notice that Fireworks has added the following block of code between each list item:
<div class="clearFloat"></div>
This block of code between the list items will invalidate the HTML document.
Note: I recommend you to edit the HTML/CSS code in Adobe Dreamweaver CS4 because of its easy integration with Fireworks CS4, but you can use any other text/code editor as well.
To fix this, simply assign the class of "clearFloat" to each list item instead, and delete the clearing divs. Here's the correct, revised code for the example above:
<div id="main">
<ul class="symbolList">
<li id="link1" class="clearFloat">
<a href="#">Nav Link 1</a>
</li>
<li id="link2" class="clearFloat">
<a href="#">Nav Link 2</a>
</li>
<li id="link3" class="clearFloat">
<a href="#">Nav Link 3</a>
</li>
<li id="link4" class="clearFloat">
<a href="#">Nav Link 4</a>
</li>
</ul>
<div class="clearFloat"></div>
</div>
Also note that if you try to visually divide the List Items in Fireworks CS4 with an object (rectangle, line, or other construct), it will also produce invalid HTML markup in both horizontal and vertical lists. You can later add these dividers in the HTML/CSS, so that you obtain the desired output.
Form element symbols in Fireworks CS4 are similar to the other HTML symbols we have already reviewed—they have various editable properties, and their new, enhanced versions (both Windows and Mac visual variants are available), are improved, too.
The editable properties for form element symbols are as follows:
Here's the list of all the available form element symbols:
For Buttons, the Type property allows you to display and export buttons of the type Submit, Reset, or Button. For TextFields, you can choose to export standard Text or Password inputs. The State property varies among the form symbols, but generally it allows you to represent the element in the following states: Normal, Over, Press, Disabled. Figure 19 illustrates all of the form symbols in one place.
Here are some considerations when working with Form element symbols:
<form> element will be automatically created and it will wrap the whole contents on the page. In some cases this is OK, but in some other cases you will have to manually modify the document's form structure (for example, when multiple, separate forms exist in the page, like a search form and a message/comment posting form). Then you will have to create one <form> element for every separate form on the page.<fieldset> or <legend> elements will be created or exported. You will need to manually add them after the export process and style them appropriately with CSS (for example, to make them invisible, when this is needed) because Fireworks cannot create them automatically for you. (This topic is related to the creation of semantic and accessible HTML code, but it is outside of the scope of this tutorial.)<label> element. If you require a visible <label> in your design for other form elements, create a text object and then tag it as <label>. You will still need to associate the label to the relevant form control manually by adding a for attribute with the value of the form control's specific id. If you do not require visible <label> tags, you can omit them in your design, but then add them in the HTML (after the PNG has been exported as CSS and Images) and hide them using CSS, when appropriate.Figure 20 shows a simple example to better explain Form HTML element symbols in Fireworks.
This represents a very simple online form. Open the sample file, ex-06-form-elements.fw.png, and then export it as form-example.html (selecting the Export as CSS and Images option). Study the PNG file in Fireworks and compare it to the source code in the automatically exported HTML document. It will be similar to this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>ex-06-form-elements</title>
<link rel="stylesheet" type="text/css" href="./form-example.css" media="all" />
<!--[if IE]>
<style type="text/css" media="all">.borderitem {border-style: solid;}</style>
<![endif]-->
</head>
<body>
<form action="#" method="get">
<div id="main">
<input type="text" name="name_field" id="name_field" value="Your name" />
<div class="clearFloat"></div>
<textarea name="message_field" id="message_field" cols="20" rows="5">Your message</textarea>
<div class="clearFloat"></div>
<input type="submit" id="send_button" value="Send" />
<div class="clearFloat"></div>
</div>
</form>
</body>
</html>
There are also a few other things to mention about forms, when exporting the CSS from Fireworks automatically, but they are outside of the direct goal of this tutorial.
In the next section, I will move on to image slicing, the third important tool when preparing a web design to be exported as CSS and Images.
I've shown you so far two important Fireworks CS4 features when preparing a graphic design to be exported as CSS and HTML: the HTML tagging of text objects and the HTML enhanced symbols. Here, I will explain to you the basics of the third main feature that you will need to learn: image slicing (and optimization).
What is slicing? When creating and editing your website mock-up in Fireworks, you can specify how certain areas of the PNG image file will be exported, in what graphics format, and so on. Fireworks then slices your PNG into separate images according to the guidelines you've specified.
Slicing of images in Fireworks CS4 was improved a lot by adding background image slicing, which complements the new CSS Export feature extremely well. This feature enables you to specify different sections of a design and then automatically export them as background images (in <div> containers). You can also specify the background-repeat and background-position properties of the background image; thus, you can easily create tiled horizontally or vertically backgrounds.
Your options when creating a slice area are as follows—you can specify the slice as follows:
<img src...> image tag in the HTML code and will export the image automatically.I'll review all three options separately, but will explain in most detail the option to export a slice as background image, as this is the most important one for exporting a website design/mock-up correctly as CSS, HTML and images.
When you select this option, it will produce a standard <img src="" ...> image tag in the HTML code and will export the corresponding image. When you need to have images in your design that are part of the website's content (and not part of the design), then this is the correct option to choose.
Here's a basic example for this slice type:
You can see the slice selected in the Web Layer in the Layers panel, and its properties in the Property inspector. The slice rectangle covers the object below it and controls how it will be exported.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="./slice-foreground-image.css" media="all" />
<!--[if IE]>
<style type="text/css" media="all">.borderitem {border-style: solid;}</style>
<![endif]-->
</head>
<body>
<div id="main">
<img src="my_image.jpg" id="my_image" alt="" />
<div class="clearFloat"></div>
</div>
</body>
</html>
Fireworks CS4 has automatically created the HTML/CSS and sliced the image (you'll find the image in the same location where you saved the HTML file, and it will be correctly named my_image.jpg and exported as a JPG file, with the selected quality settings).
If you're curious to compare your example with the one provided with this tutorial, open ex-07-slice-foreground-image.fw.png and then export it as CSS and Images.
When you select a slice from the Property inspector, you can choose from several basic image export settings for it: GIF (including animated GIF) and JPEG (two options: Better Quality or Smaller File), as shown in Figure 23.
Of course, you are not limited to JPG or GIF only. But to select from a wider variety of image export formats, and any additional image—related settings, you should open the Optimize panel (Window > Optimize, or press F6). From there, you can select any kind of image export format, including the most popular ones on the web (GIF, JPG, PNG), and customize their quality, number of colors, and other settings.
To use the Optimize the panel, simply open it, select the slice, and then edit its image export settings in the panel. (See Figure 24 for more details.)
Only the basic slice image export options are available through the Property inspector, so you'll probably need to open also the Optimize panel, and explore its options as well.
This is the most useful option when exporting a graphic design as CSS and Images, and you'll be using it a lot in your designs. I'll first show you how to export a slice as a background image. You'll create a similar document to the one in the previous example, with just one small difference.
Here's how to proceed:
You'll notice that in the browser, the rectangle looks the same; but Fireworks magically used just a one-pixel-wide image as background, based on your settings (background-repeat set to repeat-x, which means "repeat horizontally").
You can compare your work to the sample file for this section, ex-08-slice-background-image1.fw.png. Here's the source code for this exported file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>ex-08-slice-background-image1</title>
<link rel="stylesheet" type="text/css" href="./slice-background-image.css" media="all" />
<!--[if IE]>
<style type="text/css" media="all">.borderitem {border-style: solid;}</style>
<![endif]-->
</head>
<body>
<div id="main">
<div id="my_background">
</div>
<div class="clearFloat"></div>
</div>
</body>
</html>
Fireworks CS4 created a <div> element with the class my_background, exported the slice image automatically, and created the CSS, which positioned the <div> and the background image. Lots of time saved!
The option to create background images (including tiled ones, like in this example), and position them automatically can be useful to you in a lot of ways. For example, you can create the background of a <div> element, which will include other content (navigation, or a heading, or an unordered list, and so on), and the image will be very small in size.
Let's review a bit more complex example now:
Preview the HTML file in your browser. Try to resize the text—for example, make it bigger. (In Internet Explorer 7, choose View > Text size > Largest; in Firefox 3.0/3.5, choose View > Zoom > [check Zoom Text Only] and then click Zoom In a couple of times.) Notice that the <div> with the green linear background expands in a fluid manner, along with the text! Fireworks CS4 specifies in the CSS all the fonts as percentages, and this allows them to be scaled in every browser (including Internet Explorer, which otherwise has problems scaling fonts specified in pixels), and this improves the accessibility.
Here's the HTML from the CSS export (you can compare it with the results from exporting the sample file for this section: ex-09-slice-background-image2.fw.png):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>ex-09-slice-background-image2</title>
<link rel="stylesheet" type="text/css" href="./slice-background-image2.css" media="all" />
<!--[if IE]>
<style type="text/css" media="all">.borderitem {border-style: solid;}</style>
<![endif]-->
</head>
<body>
<div id="main">
<div id="my_background">
<div class="my_text">
<p class="lastNode">White Text Inside Rectangle
</p>
</div>
<div class="clearFloat"></div>
</div>
<div class="clearFloat"></div>
</div>
</body>
</html>
Another interesting thing to notice is that when the font is increased and the <div> element grows in size, where the background image ends, it still blends with the rest of the container. This is because you have first set the solid background color of the rectangle, before applying a linear fill to it. Thus, it is important to remember that even if an object has a gradient fill, its original solid color is remembered by Fireworks. This can help create containers which can expand later (if the text size is changed, or the amount of text varies inside), and still have gradient fills applied to them, which will blend well.
In exactly the same manner, you can create slices that work with a horizontal gradient, and repeat on the y axis (background-repeat: repeat-y).
Now here's the most interesting use of the background image slices: the so-called three-slice technique. In web design, you often encounter designs that have a static top, a middle section for any amount of content (text, images, or other content), and a static bottom. Using the background image slice type and the Fireworks three-slice technique, you can easily achieve this effect in Fireworks CS4 (see Figure 28).
In this case, you should specify three slices for this element: one for the top (25 px high); one for the middle content, which will be vertically fluid in size (small, 1 pixel height background image, repeating around the y axis will be OK); and one for the bottom (25 px high).
Note: You can use this technique, for example, when you need rounded corners on a container because the current CSS standard (CSS 2.1) does not support this feature. I should mention, though, that a new specification (CSS 3) is on the way and it will include the possibility to use rounded corners, gradients, and even drop shadows—without any need for images. Firefox 3.5 or later, Safari 4 or later, and other modern browsers already have limited support for some CSS 3 features. However, we will need more time before CSS 3 becomes widely supported by the browser market. In the meantime, the Fireworks three-slice technique remains very useful.
Open the sample file ex-10-slice-background-image3.fw.png, with which I will illustrate the three-slice technique. Inside, you will find the following objects (inside Layer 1):
And the three slices are specified as follows (see the Web Layer, Figure 29):
background-repeat set to repeat-y.All three slices will export as PNG images, 32 bit (PNG32), with settings set in the Optimize panel.
When you create the three background slices (one for the top, one repeating for the middle section, and one for the bottom) over the top of an object—a rectangle, a rounded rectangle, or other element—the CSS Export in Fireworks automatically switches to the three-slice method. Now export our sample file, ex-10-slice-background-image3.fw.png (export it as slice-background-image3.html) and view the source code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>ex-10-slice-background-image3</title>
<link rel="stylesheet" type="text/css" href="./slice-background-image3.css" media="all" />
<!--[if IE]>
<style type="text/css" media="all">.borderitem {border-style: solid;}</style>
<![endif]-->
</head>
<body>
<div id="main">
<div id="Box3SliceContainer">
<div id="Box3SliceContainer_top_1">
</div>
<div class="text_fill">
<p class="lastNode">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat [...] nulla facilisi.
</p>
</div>
<div class="clearFloat"></div>
<div id="Box3SliceContainer_bottom_1">
</div>
</div>
<div class="clearFloat"></div>
</div>
</body>
</html>
Fireworks CS4 has created an element with id="Box3SliceContainer" and inside, you can see the three divs, corresponding to the three slices that you have created. All CSS, HTML and image export was done automatically!
Note: If you would like to add text (like a heading, for example) to the top of the image, the top slice would need to be exported again separately, without the text visible. Otherwise, Fireworks will export the text as part of the top background image.
When you select this option, it will produce HTML code instead of an image. The use of this option is rather limited, as it will work well only with rectangles of solid color, with or without borders applied to them. Here's a very basic example:
You'll have something like Figure 31.
Locate the HTML file and open it in your browser. View its source:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="./slice-html.css" media="all" />
<!--[if IE]>
<style type="text/css" media="all">.borderitem {border-style: solid;}</style>
<![endif]-->
</head>
<body>
<div id="main">
<div id="html_rectangle">
</div>
<div class="clearFloat"></div>
</div>
</body>
</html>
You can see that Fireworks created a <div> element with id="html_rectangle", applied the correct background color to it, and a 1 px black border. The relevant styles are in the CSS file (slice-html.css):
#html_rectangle {
margin-left: 50px;
margin-top: 20px;
display: inline;
float: left;
margin-bottom: 0;
background-color: #f93;
border: 1px solid #000;
width: 198px;
padding-top: 0px;
height: 49px;
}
Interestingly enough, you can create an HTML slice even for a circular shape, or select a linear fill background color, but Fireworks will always produce a rectangular shape with solid color on CSS export. CSS currently doesn't support round shapes, or rounded rectangles, and the color of objects can be only solid. But in case you need to create a rectangle with solid color (with or without border), you can use this option for creating the slice.
You can open the sample file ex-11-slice-html.fw.png and then export it as CSS and Images to compare with your results.
Now you have at your fingertips all the tools you need to produce XHTML and CSS code automatically from within Fireworks CS4. I have reviewed and provided examples to the main three options you'll be using extensively: tagging of text elements, HTML symbols, and background image slicing.
I have provided you with a ready demo design mock-up, and in it I have used most of the techniques I have reviewed in detail in this tutorial. Open ex-12-design-mockup-demo.fw.png in Fireworks CS4 and study its structure (check how layers are organized, check the slices in the Web Layer and their settings, and so on). Then try to export the file as design-mockup-demo.html and open the file in the browser. Check its source code; also check the CSS code (design-mockup-demo.css). You will see that it looks almost identical in the browser.
If you try to validate the HTML file using the W3C Validator, it will even validate as a Valid XHTML 1.0 Transitional document.
This doesn't mean, though, that the code cannot be further improved. I would suggest using Dreamweaver or some other good code editor for this purpose.
Some final notes before concluding:
background-repeat set to repeat-x), the sidebar consists of three background images (three-slice technique used), the main column is a simple HTML slice, and the footer is another small background image, with background-repeat set to repeat-x.<form> element into it. But you can try to insert a few <form> elements yourself and export the file after that.<div> with the ID of "main", so make sure not to name any element in your design as "main"! Otherwise, you may end up with two elements having the same ID in the HTML, which will invalidate the page and most probably lead to problems with the XHTML/CSS design, as well.Now that you have exported the mock-up design, how could you manually improve it, in Dreamweaver, or some other code editor? Well, you could do a lot of things. But most importantly, I would suggest to you to simplify the CSS rules by removing most of the font-family and color references. Assign them to the body instead, or to specific containers.
How?
Here's a very simple example taken from the exported design mock-up CSS. See the styling of the nav links:
#home {
color: #fff;
font-weight: normal;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 200%;
margin-left: 12px;
margin-top: 10px;
display: inline;
float: left;
margin-bottom: 0;
}
#about {
color: #fff;
font-weight: normal;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 200%;
margin-left: 26px;
margin-top: 10px;
display: inline;
float: left;
margin-bottom: 0;
}
#publications {
color: #fff;
font-weight: normal;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 200%;
margin-left: 24px;
margin-top: 10px;
display: inline;
float: left;
margin-bottom: 0;
}
[ etc... ]
You will notice that although all fonts in the Fireworks design mock-up are Verdana, Fireworks still assigns the font-family attribute to most of the separate elements on the page—in this case, to the links in the navigation.You can safely delete the line
font-family: Verdana, Arial, Helvetica, sans-serif;
from the nav links (#home, #about, #publications, and the rest) and put it in the body, like this:
body {
background-color: #fff;
font-size: 62.5%;
margin: 0;
padding: 0;
font-family: Verdana, Arial, Helvetica, sans-serif; /* added */
}
You can perform similar optimizations for most of the CSS rules created by Fireworks. Some rules, like this one, you can safely assign to the body; in some other cases, you can simply organize the CSS better by assigning rules to specific containers.
Here's another example. This is the HTML code for the nav bar:
<div id="nav">
<ul class="symbolList">
<li id="home"><a href="#">home</a></li>
<li id="about"><a href="#">about</a></li>
<li id="publications"><a href="#">publications</a></li>
<li id="contact"><a href="#">contact</a></li>
</ul>
<div class="clearFloat"></div>
</div>
You can see that all list items (<li>) in the navigation list are contained within a <div> element with id="nav". If you take another look at the CSS for the list items in the navigation, you will see that some of the rules are repeating:
#home {
color: #fff;
font-weight: normal;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 200%;
margin-left: 12px;
margin-top: 10px;
display: inline;
float: left;
margin-bottom: 0;
}
#about {
color: #fff;
font-weight: normal;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 200%;
margin-left: 26px;
margin-top: 10px;
display: inline;
float: left;
margin-bottom: 0;
}
[ etc... ]
For example, color, font-weight, font-family, and font-size are all the same for all links in the navigation. You can safely delete them from the individual rules and assign them to the <div> with id="nav":
#nav a {
color: #fff;
font-weight: normal;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 200%;
/* etc. */
}
This code reads like this: "All links (anchors) that are inside a <div> element with id="nav" should have the following styles applied to them." You can simplify and optimize most of the CSS code generated by Fireworks in a similar manner.
But even if you don't perform this final step, the code from Fireworks is still usable in a lot of ways. And it also validates (or almost validates, in which case you can easily fix it yourself by editing it slightly) as XHTML 1.0 Transitional, the most widespread standard for HTML documents currently.
To go from design mock-up to CSS, XHTML, and (automatically) sliced images, you just need to name your text elements properly, insert HTML symbols, and create and optimize the background image slices. Everything else will be done by Fireworks.
I hope you enjoyed this tutorial!
Check out the following resources (doing so in order wouldn't be a bad idea) to learn more about CSS methodology and using CSS with Fireworks CS4:

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
| 09/07/2011 | How do I use FXG XML markup in Shape subclasses? |
|---|---|
| 10/15/2010 | Flex4 Dotted Line |
| 06/25/2010 | ComboBox that uses a NativeMenu (Air API) |
| 05/21/2010 | Localizing a Creative Suite 5 extension |