<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vacheslav Starikov&#039;s &#187; yui</title>
	<atom:link href="http://starikovs.com/cat/yui/feed/" rel="self" type="application/rss+xml" />
	<link>http://starikovs.com</link>
	<description>BLOG</description>
	<lastBuildDate>Sun, 05 Sep 2010 18:05:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Inline YUI AutoComplete layout</title>
		<link>http://starikovs.com/2009/11/04/inline-yui-autocomplete-layout/</link>
		<comments>http://starikovs.com/2009/11/04/inline-yui-autocomplete-layout/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 11:28:27 +0000</pubDate>
		<dc:creator>Vacheslav</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://starikovs.com/?p=71</guid>
		<description><![CDATA[ Recently, i had a problem with YUI AutoComplete layout. I wanted it being inline, fixed width and working with different browsers like IE6/7/8, Opera, FF etc. There were some problems that i solved primarily in CSS. More precisely, i needed an inline YUI AutoComplete layout in such a way that i can place autocomplete [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://starikovs.com/wp-content/uploads/2009/11/yuiautocompletelayout.PNG" alt="Inline YUI AutoComplete layout" title="Inline YUI AutoComplete layout" width="281" height="81" class="alignleft size-full wp-image-73" /> Recently, i had a problem with YUI AutoComplete layout. I wanted it being inline, fixed width and working with different browsers like IE6/7/8, Opera, FF etc. There were some problems that i solved primarily in CSS. More precisely, i needed an inline YUI AutoComplete layout in such a way that i can place autocomplete &lt;input&gt; next to the &lt;label&gt; without a line break. I just set my styles in CSS and override some existing styles and it works ok!</p>
<p><strong>So, problems i had to solve for my needs:</strong></p>
<ul>
<li>an outer container is a DIV so INPUT always goes on the next line</li>
<li>inline-block for DIV doesn&#8217;t work in IE6/7</li>
<li>an outer container has width of 100%</li>
<li>INPUT is absolutely positioned so an outer DIV is collapsed</li>
<li>width of 100% makes INPUT 6px larger then outer DIV in IE6</li>
<li>using inline-block, INPUT aligns vertically on the bottom in IE6</li>
</ul>
<p><span id="more-71"></span></p>
<h3>YUI files to include</h3>
<p>Let&#8217;s begin with files to include:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--CSS file (default YUI Sam Skin) --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.8.0r4/build/autocomplete/assets/skins/sam/autocomplete.css&quot;</span>&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- Dependencies --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.8.0r4/build/yahoo-dom-event/yahoo-dom-event.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.8.0r4/build/datasource/datasource-min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- Source file --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://yui.yahooapis.com/2.8.0r4/build/autocomplete/autocomplete-min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>Well, i&#8217;m explaining below how i&#8217;ve achieved an inline YUI AutoComplete layout. The code is well-commented to understand what is happening <img src='http://starikovs.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>HTML</h3>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- </span>
<span style="color: #808080; font-style: italic;">Let's use SPAN becase it has &quot;display: inline&quot; by default.</span>
<span style="color: #808080; font-style: italic;">IE6/7 can apply &quot;display: inline-block&quot; only for elements</span>
<span style="color: #808080; font-style: italic;">that have &quot;display: inline&quot; by default.</span>
<span style="color: #808080; font-style: italic;">Read more: http://www.quirksmode.org/css/display.html.</span>
<span style="color: #808080; font-style: italic;">--&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;input&quot;</span>&gt;</span>YUI AutoComplete<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;autocomplete&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;input&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;results&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
/* creating a data source out of js array */
var ds = new YAHOO.util.LocalDataSource([&quot;apples&quot;, &quot;apricots&quot;, &quot;bananas&quot;]);
&nbsp;
/* creating a yui autocomplete */
var ac = new YAHOO.widget.AutoComplete(&quot;input&quot;, &quot;results&quot;, ds);
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<h3>CSS</h3>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* outer container */</span>
<span style="color: #cc00cc;">#autocomplete</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* behaving like an inline element */</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> -moz-inline-box<span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* for FF less then 3.0 */</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> inline-<span style="color: #993333;">block</span> !important<span style="color: #00AA00;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
    <span style="color: #808080; font-style: italic;">/* standard width of a textbox */</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">145px</span><span style="color: #00AA00;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* align vertically on the center */</span>
    <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">middle</span><span style="color: #00AA00;">;</span> 
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* input */</span>
<span style="color: #cc00cc;">#autocomplete</span> input <span style="color: #00AA00;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* preventing an outer container DIV collapsing */</span> 
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
    <span style="color: #808080; font-style: italic;">/* tweaking to traditional box model
     * width = border + padding + content
     */</span>
    box-sizing<span style="color: #00AA00;">:</span> border-box<span style="color: #00AA00;">;</span>
    -moz-box-sizing<span style="color: #00AA00;">:</span> border-box<span style="color: #00AA00;">;</span>
    -webkit-box-sizing<span style="color: #00AA00;">:</span> border-box<span style="color: #00AA00;">;</span>
    -ms-box-sizing<span style="color: #00AA00;">:</span> border-box<span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* ie8 */</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* CSS Expression to calculate width for the input.
     * 2px border + 1px padding + 1px padding + 2px border = 6px.
     * Only for IE6/7 because traditional box model cannot
     * be tweaked by any css property.
     * currentStyle object - IE css styles as specified by 
     * global style sheets, inline styles, and HTML attributes.
     */</span>
    <span style="color: #00AA00;">*</span><span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> expression<span style="color: #00AA00;">&#40;</span>parseInt<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">this.parentNode.currentStyle.width</span><span style="color: #00AA00;">&#41;</span>-<span style="color: #cc66cc;">6</span><span style="color: #00AA00;">+</span><span style="color: #ff0000;">'px'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>I&#8217;ve tested this soluting in <strong>FireFox 3.5</strong>, <strong>Opera 10</strong>, <strong>IE 6/7/8</strong>. YUI version i&#8217;m using is <strong>2.8</strong>.</p>
<h3>Further reading:</h3>
<ul>
<li><a href="http://developer.yahoo.com/yui/autocomplete/" target="_blank">YUI 2 Autocomplete</a></li>
<li><a href="http://www.quirksmode.org/css/box.html" target="_blank">CSS Box Models</a></li>
<li><a href="http://www.quirksmode.org/css/display.html" target="_blank">Display declarations</a></li>
<li><a href="http://wiki.orbeon.com/forms/doc/contributor-guide/ie-bugs#TOC-Inline-block" target="_blank">inline-block in IE</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms535889(VS.85).aspx" target="_blank">IE runtimeStyle Object</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms528441(VS.85).aspx" target="_blank">IE currentStyle Object</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms535898(VS.85).aspx" target="_blank">IE style Object</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://starikovs.com/2009/11/04/inline-yui-autocomplete-layout/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
