table系タグのposition:relative

結構はまった。

tableのtdタグに、position:relative; をつけて、その中にposition:absolute を使おうとしたら、Firefoxでは全然違うところに配置された。

具体的なコードは以下の通り

そして、こちらがIE(Chromeもほぼ同じ)の結果
sample_20131226_2

こちらが、Firefoxでの結果
sample_20131226

Firefoxでは、position:relativeは効いているのだが、tableのtdタグのposition:relativeは無視されている。

ちなみに、これはFirefoxのバグではなく、Firefoxが正しい実装である。

The effect of ‘position:relative’ on table-row-group, table-header-group, table-footer-group, table-row, table-column-group, table-column, table-cell, and table-caption elements is undefined.

引用元:http://www.w3.org/TR/CSS2/visuren.html#block-boxes

なので、正しい実装としては、tdの中でdivタグのブロックレベルタグで囲んでdivタグにposition:relativeを使うようにしなければならないらしい。

分かった後で、”position:relative firefox 効かない” で検索すると同じようにはまった人がちらほら。Androidも効かないものがあるらしい。Chromeは効くのにね・・・。

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">