In this example, custom CSS and images are applied to the appearance of a Panel instance to stylize it similar to a Mac OS X document window. Use the buttons below to show and hide the Panel.
Panels (and all other containers using Standard Module Format) can be skinned using CSS to customize the look and feel of each component. In order to best explain how to customize the Panel's style, it is important to first understand the structure of the basic Panel. The Panel, with the default Sam skin applied looks like this:
Breaking the Panel down into its basic Standard Module Format, its structure can be diagrammed as such:
Since we're modifying virtually every aspect of the default Sam skin look for the panel, we'll include container/assets/container-core.css
as our base set of CSS rules, instead of container/assets/skins/sam/container.css
.
This way, we don't have to reset the additional style properties which are applied to implement Sam skin's look and feel. Our Understanding YUI Skins article provides more information about skinning YUI components and the CSS files involved.
The Panel, like all other YUI Container controls, has a header, body, and footer. In addition, the Panel also has a "close" element containing a background image to give it the appearance of a UI window close control. In this tutorial, we will manipulate the CSS styles for these elements and create several new elements to allow for additional pieces of the skin to be styled.
First, we will create rounded corners for our skin by applying images to the top left and top right corners of the Panel header. All of our CSS styles are applied to this Panel instance using ID selectors. In this case, the Panel's ID will be "myPanel", so all styles will begin with "#myPanel". In order to facilitate the creation of these corners, we will create two new empty div
elements in the header, classed as "tl" and "tr" for "top left" and "top right":
Notice that the title is placed into a span
tag. This is so that it can be more easily styled using CSS. The images will be applied as background images to each of our new corner elements, along with width and height styles, positioning, and margins:
After absolutely positioning the new corner elements, they are anchored to the left and right corners of the header, as shown in this diagram:
In this skin, we want our close icon to be positioned on the left side of the header, rather than the right side. We can override the existing "close" style so that the icon will be placed on the left. At the same time, we will apply background images to the close icon for both secure (https) and non-secure (https) servers. Since mixed content from secure and non-secure sites can cause security warnings in some browsers, YUI Container provides CSS hooks for both contexts so that you can specify proper sources for both.
Again, charting the repositioned close icon, it would look like this:
Styling the body and footer are as simple as overriding the default styles with the desired ones:
After applying all the styles to our Panel instance, the final output looks like the image below. Looking at the chart, we can see where the original familiar elements end up in the new layout, in addition to our newly created corner elements:
We will tackle another skinning example in the Advanced Skinning Tutorial.
Copyright © 2008 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings