<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>css channel</title>
    <link>http://tobyho.com/tag/css</link>
    <description>css channel</description>
    <language>en-us</language>
    <item>
      <title>The z-index IE bug</title>
      <description>Yeah, the &lt;a href="http://www.quirksmode.org/bugreports/archives/2006/01/Explorer_z_index_bug.html" mce_href="http://www.quirksmode.org/bugreports/archives/2006/01/Explorer_z_index_bug.html"&gt;z-index IE bug&lt;/a&gt;, have you heard of it? I was bitten by it a couple of days ago. In my case, I had a list of text fields in a form layed out from top to bottom. The problem is, I have these interactive drop downs on that can activate just under the text fields when you focus on the field and there is a validation error, which I use &lt;a href="http://tobyho.com/Relativize%20that%20thing:%20todays%20CSS%20war%20story" mce_href="http://tobyho.com/Relativize%20that%20thing:%20todays%20CSS%20war%20story"&gt;relative/absolute positioning&lt;/a&gt; to get in the right place, and so the &lt;font face="courier new,courier"&gt;position: relative&lt;/font&gt; declaration triggers the IE bug which causes the text field beneath the one that has the focus to occlude its drop down. My solution? I now have a javascript snippet that runs as the dom is ready that sets the z-index of all the containers(the one that has &lt;font face="courier new,courier"&gt;position: relative&lt;/font&gt;) of the text fields in descending order. So for example, if you have 10 text fields, the first one would have its &lt;font face="courier new,courier"&gt;z-index: 10&lt;/font&gt; and the last one would have &lt;font face="courier new,courier"&gt;z-index: 1&lt;/font&gt;.&lt;br&gt;&lt;br&gt;In a related note, if you use the relative/absolute positioning technique, the child element that has &lt;font face="courier new,courier"&gt;position:
absolute&lt;/font&gt; is considered the child of the parent element that has &lt;font face="courier new,courier"&gt;position: relative&lt;/font&gt; in terms of z-index, which if you then have overflow: hidden on the parent element or its ancestors, the child element would get cut out if it's position is out of bounds, vs if you didn't have &lt;font face="courier new,courier"&gt;position: relative&lt;/font&gt; set on the parent element then the child would not get cut out because it's considered to be the child of the root element in terms of z-index.&lt;br&gt;</description>
      <pubDate>Sat, 23 Aug 2008 14:38:16 -0400</pubDate>
      <guid>http://tobyho.com/The_z-index_IE_bug</guid>
      <author>toby ho</author>
      <link>http://tobyho.com/The_z-index_IE_bug</link>
    </item>
    <item>
      <title>Relativize that thing: todays CSS war story</title>
      <description>Today, I had a seemingly simple problem: position a floating label element inside of a text input field, inside a elastic layout. To achieve an effect like:&lt;img src="/uploads/tf.gif?1219608644" name="tf.gif" width="275"&gt;&lt;br&gt;&lt;br&gt;Moreover, I wanted to implement this as a generic javascript widget that I can reuse throughout the application. This was hard, real hard.&lt;br&gt;&lt;br&gt;At first, I just used &lt;font face="courier new,courier"&gt;position: absolute&lt;/font&gt; and set the position of the label relative the the root document, getting the coordinates required from the position and dimension of the companion text field. Well, this didn't work so well when the window is resized. Too bad we got an elastic layout, if we had a fixed width one I would have been done. My quick and dirty solution was to register the window.onresize callback and reset the positions of the labels whenever the window is resized. This actually worked well in IE, but not so in FF. The problem with FF is that the callback is invoked too sparsely, it's just not responsive enough when you are just dragging the corner of the window around, but you see these labels in all the wrong places while you are dragging around the corner of the browser until you leave your mouse still for a second, at which point the labels receive the event and jump to where they should be. This just plain looks bad, and although your users probably won't resize the window too much, I think it will definitely give the impression of a cheesy app. &lt;br&gt;&lt;br&gt;So, my first attempt at a work around is a brute force one. I wrote my onresize callback functionality for FF that is more responsive. Here was the code.&lt;br&gt;&lt;font face="courier new,courier"&gt;&amp;nbsp;/* this is a funny hack in FF to get window resize events more often */&lt;br&gt;var ffonresize = function(){&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var listeners = [];&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var dim = document.viewport.getDimensions();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var pe = null;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pe = new PeriodicalExecuter(function(pe) {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var nd = document.viewport.getDimensions();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!(nd.width == dim.width &amp;amp;&amp;amp; nd.height == dim.height)){&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dim = nd;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; listeners.each(function(l){l(nd)});&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }, 0.2);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return function(listener){&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; listeners.push(listener);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;}();&lt;/font&gt;&lt;br&gt;&lt;font face="courier new,courier"&gt;/*&lt;br&gt;...&lt;br&gt;*/&lt;br&gt;&lt;/font&gt;&lt;font face="courier new,courier"&gt;if (Prototype.Browser.Gecko)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ffonresize(this.__onResize);&lt;br&gt;else&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Event.observe(window, 'resize', this.__onResize);&lt;/font&gt;&lt;br&gt;&lt;br&gt;This improved the situation, but... not good enough. Then I thought, there must be a way with &lt;font face="courier new,courier"&gt;position: relative&lt;/font&gt; to do it. After all, isn't that what it's for?&lt;br&gt;&lt;br&gt;I tried making the label element &lt;font face="courier new,courier"&gt;position: relative&lt;/font&gt;, but this didn't work: you could shift the position of the element relative to where it would have been, but the space for where it would have been is still taken up, and now it's an empty space...&lt;br&gt;I did some research. One of the best resources is &lt;a href="http://www.quirksmode.org/css/position.html" mce_href="http://www.quirksmode.org/css/position.html"&gt;quirksmode &lt;/a&gt;again, &lt;a href="http://www.barelyfitz.com/screencast/html-training/css/positioning/" mce_href="http://www.barelyfitz.com/screencast/html-training/css/positioning/"&gt;this&lt;/a&gt; is also a helpful article. It turns out the common practice to use is to have a container that is relative and then a child under it that is absolute, which will cause the child to use the parent's position as the reference point. But trying the things out didn't work at first. After some trial and error, I figured out that, not only does the parent have to be &lt;font face="courier new,courier"&gt;position: relative&lt;/font&gt;, it also had to be &lt;font face="courier new,courier"&gt;display: block&lt;/font&gt;. My parent container happened to be table cells, so I either had to set their display to block or add a div under them. Setting their display to block didn't work for me because it completely messed up the layout of the table, so I had to go with the second method.&lt;br&gt;&lt;br&gt;Adding the div was annoying because not only did I have to go to a few different places in the app to add the markup, it also made my widget depend on more. Of course, I guess I could inject the div dynamically, but I haven't tried that yet. So, this worked, I no longer had to use the onresize callback and reset the position of the labels, I just set:&lt;br&gt;&lt;br&gt;&lt;font face="courier new,courier"&gt;position: absolute;&lt;br&gt;top: 2px;&lt;br&gt;right: 5%;&lt;/font&gt;&lt;br&gt;&lt;br&gt;Top of 2px to give the top some space, right of 5% to give enough space for the label. Both are relative to the divs I newly added. Well, this kinda worked... except for my short textfields. See, I had long text fields that take up almost 100% of the width of the parent, but also shorter ones that take up about 60%, so while it worked well for the long textfield, sitting right inside it on the right edge, it was well outside of the short textfields. I wanted to use javascript to figure out what's the % of the width of the text field, which I could use to calculate where the label should be, but that number is in my css, and using javascript you can only get dimensions in terms of pixels, i.e., all the percentage info is lost.&lt;br&gt;&lt;br&gt;What to do? Well, I calculated the percentage by doing a division between the text field and its parent's width in pixels, this is my code(using prototype.js):&lt;br&gt;&lt;font face="courier new,courier"&gt;right: (1 + 100 * (1 - this.field.getWidth() / this.field.up().getWidth())) + "%"&lt;/font&gt;&lt;br&gt;&lt;br&gt;Yeah, it's pretty crazy, but it worked, beautifully. It works in IE7, FF3, and Safari, didn't work in Opera, but that could have been because other javascript bugs I had wrt Opera.&lt;br&gt;</description>
      <pubDate>Fri, 22 Aug 2008 00:43:28 -0400</pubDate>
      <guid>http://tobyho.com/Relativize_that_thing%3A_todays_CSS_war_story</guid>
      <author>toby ho</author>
      <link>http://tobyho.com/Relativize_that_thing%3A_todays_CSS_war_story</link>
    </item>
    <item>
      <title>Styling Links</title>
      <description>Whenever you are styling links - like with background images, make sure you set display to block, otherwise things just won't work.&lt;br&gt;</description>
      <pubDate>Sun, 06 Jan 2008 09:06:33 -0500</pubDate>
      <guid>http://tobyho.com/Styling_Links</guid>
      <author>toby ho</author>
      <link>http://tobyho.com/Styling_Links</link>
    </item>
    <item>
      <title>How to make your inner frame extend all the way to the bottom of the window-you can't</title>
      <description>This problem has come up a couple of times for me in the past. I shruged it off the last time, but this time I decided to do some research. What I found - as to the best of my knowledge, is that you can't. The problem is this:&lt;br&gt;
I have a horizontal column that is centered in the middle of the window in my design, sort of like &lt;a href="http://www.csszengarden.com/?cssfile=/205/205.css&amp;amp;page=0"&gt;this&lt;/a&gt;. But what if the content is too short to fill up the entire screen? The bottom of the column abruptly ends and you end up with a discontinuity. There's no good way of fixing this that I am aware of. I've concluded the best way is just to use a background image at the bottom of the column to soften it's ending. Another thing I've done is to use the min-height hack to make short pages not so short. And in actuality you can use the min-height hack to make sure it always extends beyond the max of the screen, but I don't think it makes sense to create that much empty space at the bottom.&lt;br&gt;</description>
      <pubDate>Fri, 04 Jan 2008 14:40:20 -0500</pubDate>
      <guid>http://tobyho.com/How_to_make_your_inner_frame_extend_all_the_way_to_the_bottom_of_the_window-you_can%27t</guid>
      <author>toby ho</author>
      <link>http://tobyho.com/How_to_make_your_inner_frame_extend_all_the_way_to_the_bottom_of_the_window-you_can%27t</link>
    </item>
    <item>
      <title>CSS recipes: min-height hack</title>
      <description>&lt;a href="http://www.dustindiaz.com/min-height-fast-hack/" mce_href="http://www.dustindiaz.com/min-height-fast-hack/"&gt;This really helped me out&lt;/a&gt;&lt;br&gt;And the order of the lines is important, make sure it's:&lt;br&gt;&lt;font face="courier new,courier"&gt;&amp;nbsp; height:auto !important;&lt;br&gt;&amp;nbsp; height:640px;&lt;/font&gt;&lt;br&gt;and no the other way around. And one more thing: Do not use &lt;font face="courier new,courier"&gt;overflow: hidden&lt;/font&gt; with this.&lt;br&gt;</description>
      <pubDate>Thu, 03 Jan 2008 17:34:13 -0500</pubDate>
      <guid>http://tobyho.com/CSS_recipes%3A_min-height_hack</guid>
      <author>toby ho</author>
      <link>http://tobyho.com/CSS_recipes%3A_min-height_hack</link>
    </item>
  </channel>
</rss>
