YUI Library Home

YUI Library Examples: AutoComplete Control: Skinning Model

AutoComplete Control: Skinning Model

This example demonstrates the CSS applied to an implementation of the AutoComplete control that uses the "Sam Skin". You can read more about the general approach to skinning YUI components in this in-depth article. Change any or all of the skin and implementation CSS for a more customized look and feel.

In order to enable the new skinning model, AutoComplete expects a wrapper DIV element around the INPUT element and the container DIV element, in this fashion:

    <div id="myAutoComplete">
        <input type="text" id="myInput">
        <div id="myContainer"></div>
    </div>

Implementers who are working with data from third-party sources, user input data, or otherwise untrustworthy sources should be sure to read the Security Considerations section of the AutoComplete user guide.

Sample Code

DOM Overview:

1<label for="input">Find a state:</label> 
2<div id="autocomplete" class="yui-ac"
3    <input id="input" type="text" class="yui-ac-input"
4    <div id="container" class="yui-ac-container"
5        <div class="yui-ac-content"
6            <div class="yui-ac-hd"></div> 
7            <div class="yui-ac-bd"
8                <ul> 
9                    <li class="yui-ac-highlight"></li> 
10                    <li class="yui-ac-prehighlight"></li> 
11                    <li></li
12                    ... 
13                </ul> 
14            </div> 
15            <div class="yui-ac-ft"></div> 
16        </div> 
17        <div class="yui-ac-shadow"></div> 
18        <iframe></iframe
19    </div> 
20</div> 
view plain | print | ?

AutoComplete CSS:

1/* styles for entire widget */ 
2.yui-skin-sam .yui-ac { 
3    position:relative;font-family:arial;font-size:100%
4} 
5 
6/* styles for input field */ 
7.yui-skin-sam .yui-ac-input { 
8    position:absolute;width:100%
9} 
10 
11/* styles for results container */ 
12.yui-skin-sam .yui-ac-container { 
13    position:absolute;top:1.6em;width:100%
14} 
15 
16/* styles for header/body/footer wrapper within container */ 
17.yui-skin-sam .yui-ac-content { 
18    position:absolute;width:100%;border:1px solid #808080;background:#fff;overflow:hidden;z-index:9050
19} 
20 
21/* styles for container shadow */ 
22.yui-skin-sam .yui-ac-shadow { 
23    position:absolute;margin:.3em;width:100%;background:#000;-moz-opacity0.10;opacity:.10;filter:alpha(opacity=10);z-index:9049
24} 
25 
26/* styles for results list */ 
27.yui-skin-sam .yui-ac-content ul{ 
28    margin:0;padding:0;width:100%
29} 
30 
31/* styles for result item */ 
32.yui-skin-sam .yui-ac-content li { 
33    margin:0;padding:2px 5px;cursor:default;white-space:nowrap
34} 
35 
36/* styles for prehighlighted result item */ 
37.yui-skin-sam .yui-ac-content li.yui-ac-prehighlight { 
38    background:#B3D4FF; 
39} 
40 
41/* styles for highlighted result item */ 
42.yui-skin-sam .yui-ac-content li.yui-ac-highlight { 
43    background:#426FD9;color:#FFF; 
44} 
view plain | print | ?

Implementation CSS:

1/* styles for this implementation */ 
2#autocomplete { 
3    width:15em/* set width for widget here */ 
4    padding-bottom:2em
5} 
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.

Copyright © 2011 Yahoo! Inc. All rights reserved.

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