- What You Will Learn
- Defining a Static Site
- Passing and Using Data with Ajax
- Connecting the Country Profiles Page to HTML Data
- Styling the Spry Table
- Creating Spry Regions
- Displaying with a Spry Accordion
- Adding Images and the Country Name
- Refining Page Display Using CSS Styling and Positioning
- What You Have Learned
- Additional Spry Functionality in Dreamweaver CS4
- Additional Resources
Refining Page Display Using CSS Styling and Positioning
The page is now fully functional and the data is accurate and complete. So your work here is done, right? Well, no, not really. Depending on their screen resolution, some users may have to scroll down after choosing a country, in order to see the details of their selection in the accordion panel. When choosing a country with a vertical image (such as the ones for France, Peru, or Thailand), the user has to scroll down in the accordion panel itself to view the entire image. The information in the country table and the accordion panels is a bit crowded against the sides of their respective containers. The accordion panels need proper labels. Perhaps most egregious, the colors of the panel tabs just don't work with the rest of the scheme. Believe it or not, all of these problems are easily fixed with a little digital "spit and polish."
Padding and Positioning the Country Table
Some of the changes we'll make are dependent on one another, so the sequence in which we make these changes is important. To reduce user scrolling and make the best use of available screen real estate, we could move the accordion up alongside the table. But we need to fix the issues with the country table before we can be sure how much room we'll have for the accordion, so let's start there.
- Return to profiles.html. In the CSS panel, click the button for a new CSS rule. For Selector Type, choose ID. Name the new selector #countryTable and make sure that the rule definition is set to main.css. In the next dialog, click Box in the Category list, set Width to 300 pixels, set Float to left, and uncheck the "Same for all" box under Margin. Add the following values (all in pixels):
- Top: 5
- Right: 10
- Bottom: 10
- Left: 0
- To see the effects of the ID selector style you've created, you must add the proper ID to the country table. In design view, select the table. To make sure that you choose the table tag, you can click in the table heading and then use the tag selector to choose the table tag. Alternatively, using the Properties pane, you can choose countryTable from the list of table IDs, as shown in Figure 41.
- Save both main.css and profiles.html. Then view the changes through your browser (F12) or click the Live View button.
Figure 40 shows how the dialog should look before you click OK.
The number sign (#) at the beginning of your new custom CSS selector indicates that it's an ID selector. ID selectors are used for elements that are unique within a page. It's probably clear what setting the selector's width will do, but what about the other values? I'll talk about float in a moment, but how about the margin? The CSS Reference built into Dreamweaver (press Shift-F1 to open it) defines margin as "the space that extends beyond the border of an element to provide extra empty space between adjacent or nested elements." This means that we've muscled out a little white space around our table so that other elements don't crowd it.
The important distinction between margin and padding (the other option in the Box category) is that padding is the white space inside the border of the element, whereas the margin is outside. The 10-pixel margin you added to the right of the table element adds space to the 300-pixel width, making it total 310 pixels. If you added 10 pixels of padding, those 10 pixels of white space would be put inside your 300-pixel table element. Margin and padding are two key components of what's referred to as the "Box Model" in CSS, the other component being the border. To see a clear demonstration of these differences, experiment by adding a 1-pixel border to the table so you can observe the edges of your element. Play with the margin and padding values and see where the space is added. Remove the border when you're finished.
The other styling change you made in this step is perhaps the most dramatic. When you set float to left, the elementin this case, the tablewill stick to the left side of its containing element, while the rest of the page content flows around the element instead of being pushed down by it.
You've now assigned the ID to the table, and the styles you created are applied in design view. We're ready to take a look at the result.
When you reload the page, the change is fairly dramatic, as shown in Figure 42. The accordion is now alongside the table. That's a testament to the power of CSS. Content flows through a web page like water in a stream. Normally, block elements such as paragraphs, headings, and tables disrupt that flow, acting like a dam. All content before the block element stays before it, and content coming after the block element occupies the space below the element. By styling the table to float left, it's as if the table "grabs onto" the left side of its container, allowing the other content to swim up next to it. Now the "Record x of x" paragraph, as well as the accordion panels, can flow in the space next to the table, rather than being pushed downstream below it.
Padding and Positioning the Accordion Panels
Now that you have the accordion panels in the right area of the page, you can make final adjustments to their display. Let's begin by giving appropriate labels to the accordion panel tabs and making them more prominent.
- Switch to code view and locate the accordion panel. (It should start around line 50.) The label for the first tab looks like this:
- For the second tab, change Label 2 to Image and change the tag from <div> to <h3>. Save profiles.html and view your changes.
- The vertical images used for countries such as France and Thailand force a scrollbar in the panel. Let's get rid of it by making the panels' content cell taller. Open the CSS panel and scroll to the bottom of the list of selectors, where the styles from SpryAccordion.css are displayed. Click .AccordionPanelContent. Its properties will be displayed in the Properties pane under the selectors list. Change the height attribute from 200 to 270.
- Currently the content in the accordion panels rests against the sides of its panels. As we learned earlier, when you want to create white space on the inside of a container you use padding. Padding is applied as one value to the entire box, or as four values representing each side of the box, starting at the top and moving clockwise around the element. To move the content off the sides of the panel, let's add padding to the left and right sides.
- Your final change to the page is to bring the colors of the panel tabs in line with the rest of the design. You can make these changes using the handy shortcut you learned in the previous steps, or do it the traditional way by double-clicking and opening the edit window. I leave the choice to you.
- Save your changes and press F12 to preview the results (see Figure 44). Be sure to save SpryAccordion.css as well as profiles.html.
<div class="AccordionPanelTab">Label 1</div>
Change the text for the first panel tab from Label 1 to Details and change its tag from <div> to <h3>. Now the tag should look like this:
<h3 class="AccordionPanelTab">Details</h3>
By changing the panel tab to a heading level 3, you take advantage of the built-in font size and bold formatting of that heading level.
The remaining display modifications will be made to the style sheets. The accordion panels have their own CSS file, but you can access it easily through the CSS panel while you have profiles.html open. You can quickly access the CSS files through Dreamweaver CS4's new Related Files toolbar. All linked or included files are listed across the top of your file's window and can be accessed quickly by clicking their names.
Staying in the Properties pane at the bottom of the CSS panel, place your cursor after the padding value 0px, add a space, and then add 5px 0px 5px. The final value should read 0px 5px 0px 5px (see Figure 43). Press Enter (Return) or tab out of the field to make the change take effect.
If you look at the .AccordionPanelContent class in SpryAccordion.css, around line 70, you'll see the padding (0px 5px 0px 5px;) listed among its properties. This form of CSS shorthand is the effective equivalent of the following:
padding-top: 0px; padding-right: 5px; padding-bottom: 0px; padding-left: 5px;
Locate this selector and change its background color to #FFFF99:
.AccordionFocused .AccordionPanelTab
Next, locate this selector and change its color to #FFCC33:
.AccordionFocused .AccordionPanelOpen .AccordionPanelTab
These two selectors are considered to be advanced selectors. They reflect the relationships of elements, much like the padding you added to the <td> tag that was a descendent of the countryTable earlier in the class. The first selector is for an element with the class AccordionPanelTab, which is a descendent of an element with the class AccordionFocused. If you look in your code, you won't see any element with the AccordionFocused class. Spry adds that class to the main accordion <div> dynamically when you click anywhere on the accordion.
The second advanced selector reflects yet another layer of ancestry, again with Spry adding the AccordionFocused and AccordionPanelOpen classes to the elements dynamically, based on the user's mouse clicks. Nice functionality. Aren't you glad that Spry has written it for you? It saves quite a bit of time.
You've created a dynamic application for displaying the country profiles. It not only provides users with information they need to learn about the countries that your client's tours visit, but provides a richer experience for the users. I encourage you to keep an eye on the Spry development team's future releases, by visiting the Adobe Labs website.