YUI Library Home

YUI Library Examples: Container Family: Skinning a Panel with Custom CSS: Advanced

Container Family: Skinning a Panel with Custom CSS: Advanced

In this example, we move beyond the basic skinning steps demonstrated in the introductory skinning example and show more advanced techniques with multiple styled Panel Control instances on the same page. Use the buttons below to show and hide the styled panels.

Skinning Panel: Beyond the Basics

Panels can be skinned using only CSS, and a bit of extra markup. In the previous Skinning Tutorial, we covered the basics of skinning Panels using CSS.

In this tutorial, we will create two Panels — one skinned to look like a Windows XP window, and one that looks like the Mac OS X Aqua style. First, let's look at the markup structure that will serve as the framework for our newly skinned Panels. You'll notice that a few additional elements have been added to the header and footer. The classes of these elements — "tl", "tr", "br" and "bl" — represent each of the corner images that will be applied to the XP skin. The Aqua skin will be built from script (not based on existing markup) using the same structure, although the rounded corners will only be applied to the top corners. The script and markup for the two skinned Panels are listed below:

1YAHOO.example.container.panel2.setHeader("<div class='tl'></div><span>Panel #2 from Script</span><div class='tr'></div>"); 
2YAHOO.example.container.panel2.setBody("This is a dynamically generated Panel."); 
3YAHOO.example.container.panel2.setFooter("<span>End of Panel #2</span>"); 
view plain | print | ?
1<div id="panel1"
2    <div class="hd"><div class="tl"></div><span>Panel #1 from Markup</span><div class="tr"></div></div
3    <div class="bd">This is a Panel that was marked up in the document.</div> 
4    <div class="ft"><div class="bl"></div><span>End of Panel #1</span><div class="br"></div></div
5</div> 
view plain | print | ?

The skinning of these Panels is achieved using CSS definitions. As with the basic skinning example, we'll start with container/assets/container-core.css as our base set of CSS rules, instead of container/assets/skins/sam/container.css, so that we don't have to reset the additional style properties which are applied to implement Sam Skin.

In this tutorial, we will use id selectors in our CSS definitions to specify which Panel should receive each skin. Most of the styles consist of background images that are applied to various pieces of the Panels. The styles are defined below:

XP Panel Skin CSS

1/* XP Panel Skin CSS */ 
2 
3/* Skin default elements */ 
4#panel1_c.yui-panel-container.shadow .underlay { 
5    left:3px
6    right:-3px
7    top:3px
8    bottom:-3px
9    position:absolute
10    background-color:#000
11    opacity:0.12
12    filter:alpha(opacity=12); 
13} 
14 
15/* Apply the border to the right side */ 
16#panel1.yui-panel { 
17    border:none
18    overflow:visible
19    background:transparent url(assets/img/xp-brdr-rt.gif) no-repeat top right
20} 
21 
22/* Style the close icon */ 
23#panel1.yui-panel .container-close { 
24    position:absolute
25    top:5px
26    right:8px
27    height:21px
28    width:21px
29    background:url(assets/img/xp-close.gif) no-repeat
30} 
31 
32/* Style the header with its associated corners */ 
33#panel1.yui-panel .hd { 
34    padding:0
35    border:none
36    background:url(assets/img/xp-hd.gif) repeat-x
37    color:#FFF; 
38    height:30px
39    margin-left:8px
40    margin-right:8px
41    text-align:left
42    vertical-align:middle
43    overflow:visible
44} 
45 
46/* Style the body with the left border */ 
47#panel1.yui-panel .bd { 
48    overflow:hidden
49    padding:10px
50    border:none
51    background:#FFF url(assets/img/xp-brdr-lt.gif) repeat-y;  
52    margin:0 4px 0 0
53} 
54 
55/* Style the footer with the bottom corner images */ 
56#panel1.yui-panel .ft { 
57    background:url(assets/img/xp-ft.gif) repeat-x
58    font-size:11px
59    height:26px
60    padding:0px 10px
61    border:none 
62} 
63 
64/* Skin custom elements */ 
65#panel1.yui-panel .hd span { 
66    line-height:30px
67    vertical-align:middle
68    font-weight:bold
69} 
70#panel1.yui-panel .hd .tl { 
71    width:8px
72    height:29px
73    top:1px
74    left:0
75    background:url(assets/img/xp-tl.gif) no-repeat
76    position:absolute
77} 
78#panel1.yui-panel .hd .tr { 
79    width:8px
80    height:29px
81    top:1px
82    right:0
83    background:url(assets/img/xp-tr.gif) no-repeat;  
84    position:absolute
85} 
86
87#panel1.yui-panel .ft span { 
88    line-height:22px
89    vertical-align:middle
90} 
91#panel1.yui-panel .ft .bl { 
92    width:8px
93    height:26px
94    bottom:0
95    left:0
96    background:url(assets/img/xp-bl.gif) no-repeat
97    position:absolute
98} 
99#panel1.yui-panel .ft .br { 
100    width:8px
101    height:26px
102    bottom:0
103    right:0
104    background:url(assets/img/xp-br.gif) no-repeat
105    position:absolute
106} 
view plain | print | ?

Aqua Panel Skin CSS

1/* Aqua Panel Skin CSS */ 
2 
3/* Skin default Panel elements */ 
4#panel2_c.yui-panel-container.shadow .underlay { 
5    position:absolute
6    background-color:#000
7    opacity:0.12
8    filter:alpha(opacity=12); 
9    left:3px
10    right:-3px
11    bottom:-3px
12    top:3px
13} 
14#panel2.yui-panel { 
15    border:none
16    overflow:visible
17    background-color:transparent
18} 
19 
20/* Apply styles to the close icon to anchor it to the left side of the header */ 
21#panel2.yui-panel .container-close { 
22    position:absolute
23    top:3px
24    left:4px
25    height:18px
26    width:17px
27    background:url(assets/img/aqua-hd-close.gif) no-repeat
28} 
29/* span:hover not supported on IE6 */ 
30#panel2.yui-panel .container-close:hover { 
31    background:url(assets/img/aqua-hd-close-over.gif) no-repeat
32} 
33 
34/* Style the header and apply the rounded corners, center the text */ 
35#panel2.yui-panel .hd { 
36    padding:0
37    border:none
38    background:url(assets/img/aqua-hd-bg.gif) repeat-x
39    color:#000
40    height:22px
41    margin-left:7px
42    margin-right:7px
43    text-align:center
44    overflow:visible
45} 
46/* Style the body and footer */ 
47#panel2.yui-panel .bd { 
48    overflow:hidden
49    padding:4px
50    border:1px solid #aeaeae; 
51    background-color:#FFF; 
52} 
53#panel2.yui-panel .ft { 
54    font-size:75%
55    color:#666
56    padding:2px
57    overflow:hidden
58    border:1px solid #aeaeae; 
59    border-top:none
60    background-color:#dfdfdf; 
61} 
62 
63/* Skin custom elements */ 
64#panel2.yui-panel .hd span { 
65    vertical-align:middle
66    line-height:22px
67    font-weight:bold
68} 
69#panel2.yui-panel .hd .tl { 
70    width:7px
71    height:22px
72    top:0
73    left:0
74    background:url(assets/img/aqua-hd-lt.gif) no-repeat
75    position:absolute
76} 
77#panel2.yui-panel .hd .tr { 
78    width:7px
79    height:22px
80    top:0
81    right:0
82    background:url(assets/img/aqua-hd-rt.gif) no-repeat
83    position:absolute
84} 
view plain | print | ?

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

Container Family Examples:

More Container Family Resources:

Copyright © 2009 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings