<?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>QUOIT Blog &#187; input</title>
	<atom:link href="http://ken.quoit.jp/tag/input/feed/" rel="self" type="application/rss+xml" />
	<link>http://ken.quoit.jp</link>
	<description>Programming, OpenSource, HTML/CSS etc...</description>
	<lastBuildDate>Fri, 03 Sep 2010 07:46:05 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>input fileをCSSでキレイにしたい</title>
		<link>http://ken.quoit.jp/2009/10/27/input-file%e3%82%92css%e3%81%a7%e3%82%ad%e3%83%ac%e3%82%a4%e3%81%ab%e3%81%97%e3%81%9f%e3%81%84/</link>
		<comments>http://ken.quoit.jp/2009/10/27/input-file%e3%82%92css%e3%81%a7%e3%82%ad%e3%83%ac%e3%82%a4%e3%81%ab%e3%81%97%e3%81%9f%e3%81%84/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 10:23:28 +0000</pubDate>
		<dc:creator>yakumo</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[input]]></category>

		<guid isPermaLink="false">http://ken.quoit.jp/?p=294</guid>
		<description><![CDATA[結構この壁にぶつかってる人はいると思います。 textとかsubmitをキレイにしたのに、fileの参照ボタンが…！という思いをした人は多いでしょう。 というか僕がぶつかったので記事を書いているわけですが。 というわけで早速調べてみました。 一番参考になったのはこちらのサイト。 CSS2/DOM &#8211; Styling an input type=&#8221;file&#8221; 英語です。 なので、大事なとこだけ簡単に要約します。 ＜CSS＞ １．&#60;input type=&#8221;file&#8221; /&#62;を「position:relative」で配置した要素（divとか）の中に配置する。 ２．「position:relative」で配置した要素（divとか）の中に子要素（divとか）を配置して、そこに&#60;input /&#62;と&#60;img /&#62;（実際表示されるもの）を入れる。 ３．&#60;input type=&#8221;file&#8221; /&#62;に「z-index:2」「opacity:0」をかける。 ４．おしまい ＜JavaScript＞ ここでJavaScriptが出てくる理由は大きく分けて２つ。 １）CSSの２．で配置した&#60;input /&#62;の中に何にも表示されないので、ファイルのパスファイル名を表示させたい。 ２）設定したCSSがきいてくれない古いブラウザ対応 しかし古いブラウザっていっても、上記サイトで言及されていたのはNetScape3/4とIE4です。 これはもう無視していいレベルと勝手に判断。 ※もしかしたら他のブラウザで問題があるかもなので、自分で調べてください！ なので、ファイルのパスファイル名を表示させる処理だけ加えれば完成ということになりそうですな。 一通り上記の内容をまとめるとこうなります。 ＜HTML＞ &#60;div class=&#8221;fileinputs&#8221;&#62; &#60;input type=&#8221;file&#8221; name=&#8221;img&#8221; /&#62; &#60;div class=&#8221;fakefile&#8221;&#62; &#60;input id=&#8221;targetInput&#8221; /&#62;&#60;img src=&#8221;img/btn-choose-file.jpg&#8221; /&#62; &#60;/div&#62; &#60;/div&#62; ＜CSS＞ div.fileinputs { position: relative; [...]]]></description>
			<content:encoded><![CDATA[<p>結構この壁にぶつかってる人はいると思います。<br />
textとかsubmitをキレイにしたのに、fileの参照ボタンが…！という思いをした人は多いでしょう。<br />
というか僕がぶつかったので記事を書いているわけですが。</p>
<p>というわけで早速調べてみました。<br />
<span id="more-294"></span></p>
<p>一番参考になったのはこちらのサイト。</p>
<blockquote><p><a href="http://www.quirksmode.org/dom/inputfile.html" target="_blank">CSS2/DOM &#8211; Styling an input type=&#8221;file&#8221;</a></p></blockquote>
<p>英語です。</p>
<p>なので、大事なとこだけ簡単に要約します。</p>
<p><strong>＜CSS＞</strong></p>
<p>１．&lt;input type=&#8221;file&#8221; /&gt;を「position:relative」で配置した要素（divとか）の中に配置する。<br />
２．「position:relative」で配置した要素（divとか）の中に子要素（divとか）を配置して、そこに&lt;input /&gt;と&lt;img /&gt;（実際表示されるもの）を入れる。<br />
３．&lt;input type=&#8221;file&#8221; /&gt;に「z-index:2」「opacity:0」をかける。<br />
４．おしまい</p>
<p><strong>＜JavaScript＞</strong><br />
ここでJavaScriptが出てくる理由は大きく分けて２つ。</p>
<p>１）CSSの２．で配置した&lt;input /&gt;の中に何にも表示されないので、<del datetime="2009-10-28T05:14:14+00:00">ファイルのパス</del>ファイル名を表示させたい。<br />
２）設定したCSSがきいてくれない古いブラウザ対応</p>
<p>しかし古いブラウザっていっても、上記サイトで言及されていたのはNetScape3/4とIE4です。<br />
これはもう無視していいレベルと勝手に判断。<br />
※もしかしたら他のブラウザで問題があるかもなので、自分で調べてください！</p>
<p>なので、<del datetime="2009-10-28T05:14:14+00:00">ファイルのパス</del>ファイル名を表示させる処理だけ加えれば完成ということになりそうですな。</p>
<p>一通り上記の内容をまとめるとこうなります。</p>
<blockquote><p><strong>＜HTML＞</strong></p>
<p>&lt;div class=&#8221;fileinputs&#8221;&gt;<br />
&lt;input type=&#8221;file&#8221; name=&#8221;img&#8221; /&gt;<br />
&lt;div class=&#8221;fakefile&#8221;&gt;<br />
&lt;input id=&#8221;targetInput&#8221; /&gt;&lt;img src=&#8221;img/btn-choose-file.jpg&#8221; /&gt;<br />
&lt;/div&gt;<br />
&lt;/div&gt;</p>
<p><strong>＜CSS＞</strong></p>
<pre style="margin-right: -561px;">div.fileinputs {
 position: relative;
 height:20px;
}

div.fakefile {
 position: absolute;
 top: 0px;
 left: 0px;
 z-index: 1;
}

input.file {
 position: relative;
 text-align: right;
 -moz-opacity:0 ;
 filter:alpha(opacity: 0);
 opacity: 0;
 z-index: 2;
}

<strong>＜JavaScript＞</strong>
&lt;script type="text/javascript" language="javascript" src="js/jquery-1.3.2.min.js"&gt;&lt;/script&gt;
&lt;script language="javascript" type="text/javascript" &gt;
$(function(){
 $(".file").change(function(){
 $("#targetInput").val($(".file").val());
 });
});
&lt;/script&gt;</pre>
</blockquote>
<p>※jQueryを使ってます。</p>
<p>あとはお好きにデザインしちゃってください！</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=input+file%E3%82%92CSS%E3%81%A7%E3%82%AD%E3%83%AC%E3%82%A4%E3%81%AB%E3%81%97%E3%81%9F%E3%81%84+-+http://bit.ly/byapFV&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://ken.quoit.jp/2009/10/27/input-file%e3%82%92css%e3%81%a7%e3%82%ad%e3%83%ac%e3%82%a4%e3%81%ab%e3%81%97%e3%81%9f%e3%81%84/&amp;t=input+file%E3%82%92CSS%E3%81%A7%E3%82%AD%E3%83%AC%E3%82%A4%E3%81%AB%E3%81%97%E3%81%9F%E3%81%84" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-tumblr">
			<a href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fken.quoit.jp%2F2009%2F10%2F27%2Finput-file%25e3%2582%2592css%25e3%2581%25a7%25e3%2582%25ad%25e3%2583%25ac%25e3%2582%25a4%25e3%2581%25ab%25e3%2581%2597%25e3%2581%259f%25e3%2581%2584%2F&amp;t=input+file%E3%82%92CSS%E3%81%A7%E3%82%AD%E3%83%AC%E3%82%A4%E3%81%AB%E3%81%97%E3%81%9F%E3%81%84" rel="nofollow" class="external" title="Share this on Tumblr">Share this on Tumblr</a>
		</li>
		<li class="shr-hatena">
			<a href="http://b.hatena.ne.jp/add?mode=confirm&amp;url=http://ken.quoit.jp/2009/10/27/input-file%e3%82%92css%e3%81%a7%e3%82%ad%e3%83%ac%e3%82%a4%e3%81%ab%e3%81%97%e3%81%9f%e3%81%84/&amp;title=input+file%E3%82%92CSS%E3%81%A7%E3%82%AD%E3%83%AC%E3%82%A4%E3%81%AB%E3%81%97%E3%81%9F%E3%81%84" rel="nofollow" class="external" title="Bookmarks this on Hatena Bookmarks">Bookmarks this on Hatena Bookmarks</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://ken.quoit.jp/2009/10/27/input-file%e3%82%92css%e3%81%a7%e3%82%ad%e3%83%ac%e3%82%a4%e3%81%ab%e3%81%97%e3%81%9f%e3%81%84/&amp;title=input+file%E3%82%92CSS%E3%81%A7%E3%82%AD%E3%83%AC%E3%82%A4%E3%81%AB%E3%81%97%E3%81%9F%E3%81%84" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://ken.quoit.jp/2009/10/27/input-file%e3%82%92css%e3%81%a7%e3%82%ad%e3%83%ac%e3%82%a4%e3%81%ab%e3%81%97%e3%81%9f%e3%81%84/&amp;title=input+file%E3%82%92CSS%E3%81%A7%E3%82%AD%E3%83%AC%E3%82%A4%E3%81%AB%E3%81%97%E3%81%9F%E3%81%84" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://ken.quoit.jp/2009/10/27/input-file%e3%82%92css%e3%81%a7%e3%82%ad%e3%83%ac%e3%82%a4%e3%81%ab%e3%81%97%e3%81%9f%e3%81%84/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
