<?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>JavaScript Infected &#187; CSS</title>
	<atom:link href="http://www.julianwong.net/blog/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.julianwong.net/blog</link>
	<description>Do everything with javascript</description>
	<lastBuildDate>Sat, 13 Aug 2011 07:32:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>A classname to save, using negative magin to remove the &quot;first&quot; / &quot;last&quot; class in your list</title>
		<link>http://www.julianwong.net/blog/2009/08/a-classname-to-save-using-negative-magin-to-remove-the-first-last-in-your-list/</link>
		<comments>http://www.julianwong.net/blog/2009/08/a-classname-to-save-using-negative-magin-to-remove-the-first-last-in-your-list/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 09:06:17 +0000</pubDate>
		<dc:creator>julian</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://julianwong.net/blog/?p=131</guid>
		<description><![CDATA[It is common to create a list with a separator in between like this: Item 1 &#124; Item 2 &#124; Item 3 One common way of doing this is create a list (ol / ul) then apply the border-left and add a class &#8220;first&#8221; to the first li setting the border to 0px. This is [...]]]></description>
			<content:encoded><![CDATA[<p>It is common to create a list with a separator in between like this:<br />
Item 1 | Item 2 | Item 3</p>
<p>One common way of doing this is create a list (ol / ul) then apply the border-left and add a class &#8220;first&#8221; to the first li setting the border to 0px. This is good, but this can be done in a better way.</p>
<p><span id="more-131"></span></p>
<p>Let start with an ordered list, and applying css border-left on it.<br />
&lt;ol id=&#8221;sample-list&#8221;&gt;<br />
&lt;li&gt;Item 1&lt;/li&gt;<br />
&lt;li&gt;Item 2&lt;/li&gt;<br />
&lt;li&gt;Item 3&lt;/li&gt;<br />
&lt;/ol&gt;</p>
<p>With the style:<br />
/* reset the li element */<br />
ol{margin:0px;padding:0px;}<br />
li{margin:0px;padding:0px;list-style:none;}</p>
<p>#sample-list li{border-left:1px solid #ccc;float:left;padding: 2px 5px;}</p>
<p>The result will become:<br />
| Item 1 | Item 2 | Item 3</p>
<p>Which shown an extra border at the left. One simple way to eliminate the first border is adding a classname to the first li and clear our the border, but this will add extra logic in your PHP code. So that will be nice if we can solve in CSS and keep the PHP code a bit cleaner.</p>
<p>By using negative margin, the item list above can be shown nicely without the extra class.</p>
<p>&lt;ol id=&#8221;sample-list&#8221;&gt;<br />
&lt;li&gt;Item 1&lt;/li&gt;<br />
&lt;li&gt;Item 2&lt;/li&gt;<br />
&lt;li&gt;Item 3&lt;/li&gt;<br />
&lt;/ol&gt;</p>
<p>With the style:<br />
/* reset the li element */<br />
ol{margin:0px;padding:0px;}<br />
li{margin:0px;padding:0px;list-style:none;}</p>
<p>#sample-list {overflow:hidden;display:block;}<br />
#sample-list li{border-left:1px solid #ccc;float:left;padding: 2px 5px;margin-left:-1px;}</p>
<p>In the CSS above, by setting li with margin-left:-1px; the first border-left will fall out of the ol. With ol#sample-list  set to overflow:hidden, that extra line will be wipe out from screen and leave all the other separators there.</p>
<p>This technique can works in a vertical list with horizontal separator. Just set the border to top and margin-top:-1px then set the container&#8217;s overflow to hidden. Done!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.julianwong.net/blog/2009/08/a-classname-to-save-using-negative-magin-to-remove-the-first-last-in-your-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making z-index works</title>
		<link>http://www.julianwong.net/blog/2009/06/making-z-index-works/</link>
		<comments>http://www.julianwong.net/blog/2009/06/making-z-index-works/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 07:12:41 +0000</pubDate>
		<dc:creator>julian</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://julianwong.net/blog/?p=71</guid>
		<description><![CDATA[It is common to have element stacking at bottom no matter how large the z-index is. There are 2 things to check when it happens. The position property in CSS z-index only affect elements with position property set to &#8220;relative&#8221;, &#8220;absolute&#8221;, and &#8220;fixed&#8221;.The z-index values of the all the parent Parent elements up the DOM [...]]]></description>
			<content:encoded><![CDATA[<p>
It is common to have element stacking at bottom no matter how large the z-index is. There are 2 things to check when it happens.
</p>
<h3>The position property in CSS</h3>
<p>z-index only affect elements with position property set to &#8220;relative&#8221;, &#8220;absolute&#8221;, and &#8220;fixed&#8221;.The z-index values of the all the parent </p>
<h3>Parent elements up the DOM tree</h3>
<p>
If you want a child element stack on top, all its parent elements must have an z-index that&#8217;s large enough to make itself stacking on top. That means if an element(Element A) stack below something, all the child nodes of Element A will stack below it.
</p>
<h3>Extra favor for IE6</h3>
<p>There is a serious bug in IE6, element with position set to  &#8220;relative&#8221;, &#8220;absolute&#8221;, or &#8220;fixed&#8221; without explicitly specify a z-index, the z-index of that element will be ZERO. This is 90% of the cause that makes z-index not working on IE6. When you found high z-index does not stack on top in IE6, but works well in firefox, you probably want to check all the parent elements with position set to the above 3 values.</p>
</li>
]]></content:encoded>
			<wfw:commentRss>http://www.julianwong.net/blog/2009/06/making-z-index-works/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A play with imageless button</title>
		<link>http://www.julianwong.net/blog/2009/06/a-play-with-imageless-button/</link>
		<comments>http://www.julianwong.net/blog/2009/06/a-play-with-imageless-button/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 03:09:12 +0000</pubDate>
		<dc:creator>julian</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://julianwong.net/blog/?p=70</guid>
		<description><![CDATA[The final result Open in new window What it does Just a basic markup and CSS which create an imageless button. It support zooming / changing font-size. But it is true that imageless button is bad in semantic markup compare to &#60;a> / &#60;input>, as the construct of the button is layers of &#60;div>. If [...]]]></description>
			<content:encoded><![CDATA[<h3>The final result</h3>
<p><iframe src="http://julianwong.net/samples/imageless-button/final.html" frameborder="0" width="200" height="35" scrolling="no"></iframe><br />
<a href="http://julianwong.net/samples/imageless-button/final.html" target="_blank">Open in new window</a><br/></p>
<h3>What it does</h3>
<p>Just a basic markup and CSS which create an imageless button. It support zooming / changing font-size. But it is true that imageless button is bad in semantic markup compare to &lt;a> / &lt;input>, as the construct of the button is layers of &lt;div>. If you compare the semantic to buttons using sliding window, it is pretty much the same.</p>
<p>Tested in Firefox 3, IE 6, IE 7, Safari 3.1</p>
<p><span id="more-70"></span></p>
<h3>The source code</h3>
<pre>
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
&lt;html>
&lt;link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.7.0/build/reset-fonts-grids/reset-fonts-grids.css">
&lt;style>
body{text-align:left;}
.imageless-button {display:inline-block;_display:inline;zoom:1;overflow:hidden;padding:1px;}
.imageless-button .imageless-button-outer {position:relative;display:inline-block;zoom:1;_display:inline;margin:-1px 0px;border:solid #bbb;border-width:1px 0px;}
.imageless-button .imageless-button-inner {position:relative;display:inline-block;zoom:1;_display:inline;margin:0px -1px;border:solid #bbb;border-width:0px 1px;_overflow:hidden;background:#ddd;_left:-1px;}
.imageless-button .imageless-button-top-shadow {width:100%;background:#F9F9F9;border-bottom:0.2em solid #EEEEEE;height:0.75em;overflow:hidden;position:absolute;left:0px;right:0px;}
.imageless-button .imageless-button-label {position:relative;display:inline-block;zoom:1;_display:inline;padding:0px 5px;line-height:1.5em;cursor:pointer;}
&lt;/style>
&lt;body>
&lt;div class="imageless-button">
    &lt;div class="imageless-button-outer">
        &lt;div class="imageless-button-inner">
            &lt;div class="imageless-button-top-shadow">&lt;/div>
            &lt;div class="imageless-button-label">Label 1&lt;/div>
        &lt;/div>
    &lt;/div>
&lt;/div>&lt;div class="imageless-button">
    &lt;div class="imageless-button-outer">
        &lt;div class="imageless-button-inner">
            &lt;div class="imageless-button-top-shadow">&lt;/div>
            &lt;div class="imageless-button-label">Lorem ipsum&lt;/div>
        &lt;/div>
    &lt;/div>
&lt;/div>
&lt;/body>
&lt;/html>
</pre>
<p>I have included the YUI reset-fonts-grids.css in the sample, but the imageless button works without it too. I just used to have YUI with me, so i put it in there to make sure it works with YUI.</p>
<h3>Brief explaination</h3>
<p><img src="http://www.julianwong.net/samples/imageless-button/imageless_button.png" /></p>
<p>The way i create the imageless button is by stacking 4 div elements. As you can see in the source code above, &lt;div class=&#8221;imageless-button&#8221;> is the base container of the 4 div element. Each div element inside create part of the imageless button. </p>
<ol>
<li>imageless-button-outer is top and bottom border</li>
<li>imageless-button-inner is left and right border, plus the dark grey background which act less a shade</li>
<li>imageless-button-top-shadow create the top shadow with a light background color and a darker border bottom</li>
<li>imageless-button-label is top most layer contain the label of the button</li>
</ol>
<p>There are two major problem in creating this, so when you adopting the code, you need to pay attention to it.</p>
<h4>IE 6/7 inline-block hack</h4>
<p>Except the imageless-button-top-shadow, the other 3 layer are all inline-block. IE 6/7 ignore display inline-block which it will still render the div element as block element. To make IE render inline-block, you need to use a block element, setting the display to inline, then use zoom:1 to trigger hasLayout. Then IE will magically create the inline-block</p>
<pre>
.inlineBlock {display:inline-block; *display:inline; *zoom:1;} /* this must be applied to block element, apply it on &lt;a> or &lt;span> will not work */
</pre>
<h4>A mysterious gap</h4>
<p>As you can see below, the line highlighted in red is not properly indented. This is intended to not to put a line break there as adding a line break will create a 5px gap between the buttons in Firefox 3.0 and Safari 3.1. I have no idea how and why a line break creates this problem. That will be great is someone can tell me&#8230;</p>
<pre>
            &lt;div class="imageless-button-label">Label 1&lt;/div>
        &lt;/div>
    &lt;/div>
<span style="color:red">&lt;/div>&lt;div class="imageless-button"></span>
    &lt;div class="imageless-button-outer">
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.julianwong.net/blog/2009/06/a-play-with-imageless-button/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with z-index</title>
		<link>http://www.julianwong.net/blog/2009/01/working-with-z-index/</link>
		<comments>http://www.julianwong.net/blog/2009/01/working-with-z-index/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 14:34:24 +0000</pubDate>
		<dc:creator>julian</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://julianwong.net/blog/?p=11</guid>
		<description><![CDATA[<h3>What is z-index</h3>
When we talk about 3D, we have the x,y,z dimension. z-index is the third dimension on a web page which determine how element stack. It works like Photoshop's layer. In general, larger z-index stack on top of smaller z-index. But there still other factors that will affect the layer stacking, which are the position property in CSS and the html structure.
<h3>How z-index works</h3>
It is often to find that z-index doesn't work as expected. Sometimes it work on Firefox but failed in IE 6. The first thing to make z-index work is you need to position that element. You can set the position property to absolute, fixed, or relative (but not static). Below is series of samples to test on how z-index stacking works.]]></description>
			<content:encoded><![CDATA[<h3>What is z-index</h3>
<p>When we talk about 3D, we have the x,y,z dimension. z-index is the third dimension on a web page which determine how element stack. It works like Photoshop&#8217;s layer. In general, larger z-index stack on top of smaller z-index. But there still other factors that will affect the layer stacking, which are the position property in CSS and the html structure.</p>
<h3>How z-index works</h3>
<p>It is often to find that z-index doesn&#8217;t work as expected. Sometimes it work on Firefox but failed in IE 6. The first thing to make z-index work is you need to position that element. You can set the position property to absolute, fixed, or relative (but not static). Below is series of samples to test on how z-index stacking works.<br />
<span id="more-11"></span></p>
<h3>Samples</h3>
<div class="code-toggle-con">
<div class="code">&lt;html&gt;<br />
&lt;head&gt;&lt;/head&gt;<br />
&lt;style&gt;<br />
div {width:100px; height:100px; position:absolute;}<br />
#item_1 {background:#f00; margin-top:0px; margin-left:0px; z-index:5;}<br />
#item_2 {background:#0f0; margin-top:50px; margin-left:20px; z-index:10;}<br />
#item_3 {background:#00f; margin-top:100px; margin-left:40px; z-index:15;}<br />
&lt;/style&gt;<br />
&lt;body&gt;<br />
&lt;div id=&#8221;item_1&#8243;&gt;This is item1&lt;/div&gt;<br />
&lt;div id=&#8221;item_2&#8243;&gt;This is item2&lt;/div&gt;<br />
&lt;div id=&#8221;item_3&#8243;&gt;This is item3&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
<label>sample 1-1</label></div>
</div>
<p><a href="http://julianwong.net/samples/working-with-z-index/code-1-1.html" target="_blank">demo 1-1</a></p>
<p>Sample 1-1 is a very simple case. Element #item_1, #item_2, and #item_3 are immediate child of document.body and has a distinct z-index with position set to absolute. The element with higher z-index stack on top of element with smaller z-index. Sweet!</p>
<div class="code-toggle-con">
<div class="code">&lt;html&gt;<br />
&lt;head&gt;&lt;/head&gt;<br />
&lt;style&gt;<br />
div {width:500px; height:100px; position:absolute;}<br />
span {display:block;position:absolute;}<br />
.group{width:300px; height:400px;}<br />
#group1{z-index:10;background:#900;margin-left:0px; margin-top:0px; border:1px solid #000;}<br />
#group2{z-index:20;background:#090;margin-left:280px; margin-top:5px; border:1px solid #999}<br />
#group1_item1 {background:#f00; margin-top:50px;z-index:40;}<br />
#group1_item2 {background:#ff0; margin-top:100px;z-index:50;}<br />
#group2_item1 {background:#0f0; margin-top:50px;z-index:30;}<br />
#group2_item2 {background:#0ff; margin-top:100px;z-index:-1;}<br />
&lt;/style&gt;<br />
&lt;body&gt;<br />
&lt;div id=&#8221;group1&#8243; class=&#8221;group&#8221;&gt;<br />
&lt;span&gt;This is Group1 z-index = 10&lt;/span&gt;<br />
&lt;div id=&#8221;group1_item1&#8243;&gt;This is group1_item1 z-index = 40&lt;/div&gt;<br />
&lt;div id=&#8221;group1_item2&#8243;&gt;This is group1_item2 z-index = 50&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;div id=&#8221;group2&#8243; class=&#8221;group&#8221;&gt;<br />
&lt;span&gt;This is Group2 z-index = 20&lt;/span&gt;<br />
&lt;div id=&#8221;group2_item1&#8243;&gt;This is group2_item1 z-index = 30&lt;/div&gt;<br />
&lt;div id=&#8221;group2_item2&#8243;&gt;This is group2_item2 z-index = -1&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
<label>sample 1-2</label></div>
</div>
<p><a href="http://julianwong.net/samples/working-with-z-index/code-1-2.html" target="_blank">demo 1-2</a></p>
<p>Inside sample 1-2, I set the z-index of #group1 to 10 and z-index of #group2 to 20. Each group got 2 child element with different z-index value. Sample 1-2 might confuse some people that why the stacking order is not z-index = 50 stack on top of 40 then 30, 20, 10, and -1. The reason is HTML structure is taking into account when browser determine the display stacking.</p>
<p>Simply speaking:</p>
<ol>
<li>Child element will stack on top of parent element no matter what z-index value you got, even negative.</li>
<li>When #group1 is stack behide #group2, all the child element in #group1 will stack behide #group2 (even one of #group2&#8242;s child has z-index = -1)</li>
</ol>
<p>Till now, everything should work exactly the same in Firefox and IE 6. The sample below will show a IE 6 bug in z-index. Taking the previous sample and just remove the z-index setting for #group1.</p>
<div class="code-toggle-con">
<div class="code">&lt;html&gt;<br />
&lt;head&gt;&lt;/head&gt;<br />
&lt;style&gt;<br />
div {width:500px; height:100px; position:absolute;}<br />
span {display:block; position:absolute;}<br />
.group{width:300px; height:400px;}<br />
#group1{background:#900;margin-left:0px; margin-top:0px; border:1px solid #000;}<br />
#group2{z-index:20;background:#090;margin-left:280px; margin-top:5px; border:1px solid #999}<br />
#group1_item1 {background:#f00; margin-top:50px;z-index:40;}<br />
#group1_item2 {background:#ff0; margin-top:100px;z-index:50;}<br />
#group2_item1 {background:#0f0; margin-top:50px;z-index:30;}<br />
#group2_item2 {background:#0ff; margin-top:100px;z-index:-1;}<br />
&lt;/style&gt;<br />
&lt;body&gt;<br />
&lt;div id=&#8221;group1&#8243; class=&#8221;group&#8221;&gt;<br />
&lt;span&gt;This is Group1 z-index = 10&lt;/span&gt;<br />
&lt;div id=&#8221;group1_item1&#8243;&gt;This is group1_item1 z-index = 40&lt;/div&gt;<br />
&lt;div id=&#8221;group1_item2&#8243;&gt;This is group1_item2 z-index = 50&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;div id=&#8221;group2&#8243; class=&#8221;group&#8221;&gt;<br />
&lt;span&gt;This is Group2 z-index = 20&lt;/span&gt;<br />
&lt;div id=&#8221;group2_item1&#8243;&gt;This is group2_item1 z-index = 30&lt;/div&gt;<br />
&lt;div id=&#8221;group2_item2&#8243;&gt;This is group2_item2 z-index = -1&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
<label>sample 1-3</label></div>
</div>
<p><a href="http://julianwong.net/samples/working-with-z-index/code-1-3.html" target="_blank">demo 1-3</a></p>
<p>When you open sample 1-2 and sample 1-3 in Firefox, you should found #group1_item1 and #group1_item2 is stack on top in sample 1-3 but not sample 1-2. While, if you open both sample in IE, there are no different. But which browser is correct in this? To explain this bug, here will need to introduce the concept on how z-index work.</p>
<h3>The Concept</h3>
<p>The way that browser determine which element stack on top is base on a tree like structure, i call it &#8220;z-index tree&#8221;. Sample 1-1 can be represented in the following &#8220;z-index tree&#8221;:</p>
<div class="img-con"><img src="http://julianwong.net/samples/working-with-z-index/fig_1-1.gif" alt="" /><br />
<label>fig. 1-1</label></div>
<p>item3, with z-index:15, stack on top of item2, with z-index:10, and item2 stack on top of item1, with z-index:5. All three item stack on top of document body and other elements without position / z-index being set. Pretty simple.</p>
<p>For sample 1-2, the browser found that #group1, with z-index:10, should stack below #group2, with z-index:20. But #group1_item1, with z-index:30, will not stack on top of #group2. The reason is z-index stack with hierarchy.</p>
<div class="img-con"><img src="http://julianwong.net/samples/working-with-z-index/fig_1-2.gif" alt="" /><br />
<label>fig. 1-2</label></div>
<p>As you can see in the fig. 1-2, the implication of #group1 stack below #group2 means all child nodes of #group1 will stack below #group2. If you know photoshop, z-index works somewhat like the layer folder.</p>
<p>For sample 1-3, Firefox and IE 6 will generate a different &#8220;z-index tree&#8221;. First take a look at figure 1-3-1, which is the &#8220;z-index tree&#8221; for Firefox.</p>
<div class="img-con"><img src="http://julianwong.net/samples/working-with-z-index/fig_1-3-1.gif" alt="" /><br />
<label>fig. 1-3-1</label></div>
<p>In sample 1-3, #group1 does not have any z-index value, so it is in the same layer as document body. This is different from DOM tree, elements have no z-index and a correct position value will stack on the same layer as their parent element. So #group1 will not create a node there and affect its child nodes stacking. As #group1 is gone, #group1_item1 and #group1_item2 will be compared directly to #group2. This result in a stacking order with #group1_item2 on top then #group1_item1, then #group2.</p>
<p>But for IE 6, the &#8220;z-index tree&#8221; will look like figure 1-3-2.</p>
<div class="img-con"><img src="http://julianwong.net/samples/working-with-z-index/fig_1-3-2.gif" alt="" /><br />
<label>fig. 1-3-2</label></div>
<p>When IE 6 encounter an element with position set to absolute / relative without a specified z-index, IE will set its z-index to zero. So #group1 become having z-index = 0 and stack below #group2. The resulting &#8220;z-index tree&#8221; of sample 1-3 will result in the same stacking as sample 1-2.</p>
<h3>Some Tips</h3>
<ol>
<li>Element stacking does not just relaying on the value of z-index, element position, html structure and browser will affect the way how element stack.</li>
<li>When an element with higher z-index stacking below a smaller z-index element, there must be some parent element up stream having an z-index that&#8217;s too small.</li>
<li>When dealing with IE 6, be very careful on the use of position property in CSS, and try to give it a z-index to make things clear.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.julianwong.net/blog/2009/01/working-with-z-index/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

