-webkit-appearance your little known friend

Remember years ago, when you styled your site up just the way you wanted and then you included a < input type=’file’ and then everything went to pot. You couldn’t style it up, so you had to hide it, create your ‘button’ and then simulate a click via javascript to get it to open. Well, I say years ago, nearly every browser today still can’t style the system provided buttons.


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan

<p>Remember years ago, when you styled your site up just the way you wanted and then you included a < input type='file'> and then everything went to pot. You couldn't style it up, so you had to hide it, create your 'button' and then simulate a click via javascript to get it to open. Well, I say years ago, nearly every browser today still can't style the system provided buttons.</p> <p>Webkit provides a bit of a 'hack' (well, I call it a hack) that allows you to style these hidden elements through the use of special Webkit specific CSS selectors and extensions. But back to the subject. If you use < input type='file' >, how do you style the OS button? There are two selectors you need, the first is a standard input[type='file'] selector. This allows you to change the basic appearance of the text and colours for example:</p> <div class="CodeRay"> <div class="code"><pre><span class="type">input</span>[<span class="attribute-name">type="file"</span>] { <span class="key">color</span>: <span class="value">white</span>; <span class="key">margin</span>: <span class="float">0px</span>; }</pre></div> </div> <p>The second selector is <code>::-webkit-file-upload-button</code>, this gives you direct access to the OS button. Once you are in there you can do a couple of things. You can change its color or font. You can also change its appearance, and what I mean by this, is that you can change it to look like something a lot different. In the following example, I am changing the appearance to be a square button rather than the default circle button on OSX, it is a very simple and subtle change. There are a lot of <a href="http://css-infos.net/property/-webkit-appearance">different appearances</a> an element can take; I could even make it look like a radio-button (hmm).</p> <div class="CodeRay"> <div class="code"><pre>:<span class="pseudo-class">:-webkit-file-upload-button</span> { <span class="key">-webkit-appearance</span>: <span class="value">square-button</span>; }</pre></div> </div>


This content originally appeared on Modern Web Development with Chrome and was authored by Paul Kinlan


Print Share Comment Cite Upload Translate Updates
APA

Paul Kinlan | Sciencx (2010-12-03T00:00:00+00:00) -webkit-appearance your little known friend. Retrieved from https://www.scien.cx/2010/12/03/webkit-appearance-your-little-known-friend/

MLA
" » -webkit-appearance your little known friend." Paul Kinlan | Sciencx - Friday December 3, 2010, https://www.scien.cx/2010/12/03/webkit-appearance-your-little-known-friend/
HARVARD
Paul Kinlan | Sciencx Friday December 3, 2010 » -webkit-appearance your little known friend., viewed ,<https://www.scien.cx/2010/12/03/webkit-appearance-your-little-known-friend/>
VANCOUVER
Paul Kinlan | Sciencx - » -webkit-appearance your little known friend. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2010/12/03/webkit-appearance-your-little-known-friend/
CHICAGO
" » -webkit-appearance your little known friend." Paul Kinlan | Sciencx - Accessed . https://www.scien.cx/2010/12/03/webkit-appearance-your-little-known-friend/
IEEE
" » -webkit-appearance your little known friend." Paul Kinlan | Sciencx [Online]. Available: https://www.scien.cx/2010/12/03/webkit-appearance-your-little-known-friend/. [Accessed: ]
rf:citation
» -webkit-appearance your little known friend | Paul Kinlan | Sciencx | https://www.scien.cx/2010/12/03/webkit-appearance-your-little-known-friend/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.