<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<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/"
	>

<channel>
	<title>Vacuous Virtuoso &#187; iPhone</title>
	<link>http://lipidity.com</link>
	<description>Despotic Development</description>
	<pubDate>Wed, 02 Apr 2008 14:18:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>Make the most of the iPhone SDK</title>
		<link>http://lipidity.com/apple/iphone-webkit-css-3/</link>
		<comments>http://lipidity.com/apple/iphone-webkit-css-3/#comments</comments>
		<pubDate>Tue, 26 Jun 2007 02:00:11 +0000</pubDate>
		<dc:creator>Ankur</dc:creator>
		
		<category><![CDATA[Apple]]></category>

		<category><![CDATA[Design]]></category>

		<category><![CDATA[Web]]></category>

		<category><![CDATA[CSS]]></category>

		<category><![CDATA[iPhone]]></category>

		<category><![CDATA[Mac]]></category>

		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://dev.lipidity.com/apple/make-the-most-of-the-iphone-sdk</guid>
		<description><![CDATA[<img src="http://dev.lipidity.com/wp-content/uploads/2007/06/safari.jpg" alt="Safari" title="Safari icon" class="fright" />
The iPhone, like Safari and many other browsers, runs on WebKit, which is one of the most blazing fast, powerful, standards-compliant rendering engine ever. Although there is no official Cocoa API for iPhone app development, it's not like we have nothing to work with. Writing web apps for the iPhone will be a pretty good experience for two reasons:

<ol>
<li>We don't have to worry about IE support when writing our web app</li>
<li>WebKit is amazing.</li>
</ol>

Highlighted below are ten CSS rules that make WebKit extra-great. <strong>Many of the previews require a WebKit-based browser like Safari, OmniWeb or Shiira.</strong><br />
<br />]]></description>
			<content:encoded><![CDATA[<h2>WebKit and <abbr title="Cascading Stylesheets">CSS</abbr></h2>

<h3>1. Native Controls</h3>

<p>A feature unique to the later versions of WebKit is the ability to style form controls. For a long time, the form inputs were kept as the operating system&#8217;s native controls, but now they are specifically styled that way. This means, we can easily over-ride that styling, or make elements appear like native controls.</p>

<p>Take a look at these text inputs:</p>

<div class="example">
<input type="text" value="I am a text input" />
<input type="text" style="-webkit-appearance:searchfield;" value="Me too, but I am round" />
<input type="search" value="I am a proper search input" />
</div>

<p>If you&#8217;re running a WebKit-based browser like Safari, you&#8217;ll see the first text input as a normal OS X-style
control, but the second one is a rounded control (like the search input minus the cancel widget).</p>

<p>Now look at these anchors:</p>

<div class="example">
<a href="#top">Go to top</a>
<a href="#top" style="-webkit-appearance:push-button;text-decoration:none;color:black">Go to top</a>
</div>

<p>Both are <code>&lt;a&gt;</code> tags, but the second one appears as a push-button in Safari.</p>

<p>That&#8217;s not all. Here are two button inputs:</p>

<div class="example">
<input type="button" value="I do nothing" />
<input type="button" value="I do nothing" style="-webkit-appearance:square-button" />
</div>

<p>Notice how the second button is a square button?</p>

<p>Have I caught your interest? Here&#8217;s how you do it.</p>

<h4>Mimic native widgets / controls</h4>

<p>Elements are styled to look like native controls for WebKit-based browsers using the <code>-webkit-appearance</code> <abbr title="Cascading Stylesheets">CSS</abbr> property. Some of the values this can take are (in two columns if you&#8217;re on WebKit):</p>

<div style="-webkit-column-count:2;-webkit-column-rule:1px solid rgba(0,0,0,0.1);">
<ul style="padding-left:2em">
<li>checkbox</li>
<li>radio</li>
<li>push-button</li>
<li>square-button</li>
<li>button</li>
<li>button-bevel</li>
<li>listbox</li>
<li>listitem</li>
<li>menulist</li>
<li>menulist-button</li>
<li>menulist-text</li>
<li>menulist-textfield</li>
<li>slider-horizontal</li>
<li>slider-vertical</li>
<li>sliderthumb-horizontal</li>
<li>sliderthumb-vertical</li>
<li>searchfield</li>
<li>searchfield-decoration</li>
<li>searchfield-results-decoration</li>
<li>searchfield-results-button</li>
<li>searchfield-cancel-button</li>
<li>textfield</li>
<li>textarea</li>
</ul>
</div>

<p>Setting <code>-webkit-appearance</code> simply makes the element appear as if it were the control. This could be of enormous use within WebViews inside Cocoa applications or with web apps for the iPhone.</p>

<p>If don&#8217;t have access to a WebKit-based browser, here&#8217;s a screenshot of what some of the &#8220;controls&#8221; look like:</p>

<p class="centre"><img class="feature" src="http://dev.lipidity.com/wp-content/uploads/2007/06/webkit-controls.png" alt="Webkit Controls" title="WebKit OS X Native Controls or Widgets" /></p>

<p>The important thing to note is that although the controls can be made to look like other controls using <code>-webkit-appearance</code>, their function is not affected. That is, textboxes will still accept text when they&#8217;re made to appear like <code>push-button</code> and so on.</p>

<h3>2. Element Drag</h3>

<p><ins class="block"><a href="http://fettig.net/weblog/2007/06/29/a-few-iphone-safari-notes/">Apparently</a> dragging doesn&#8217;t work with the iPhone, as it&#8217;s used for scrolling. That&#8217;s to be expected, I guess.</ins></p>

<p>Generally there is a lot of javascript involved in making an element draggable. Now you can achieve the same thing with only one line of <abbr title="Cascading Stylesheets">CSS</abbr>. Javascript will still be required to have drop targets, etc. but this allows the user to drag the entire element rather than just text or an image.</p>

<p>Try dragging this element (from the side):</p>

<div class="example" style="-webkit-appearance:push-button;-webkit-user-drag:element;-webkit-user-select:ignore">Drag me if you dare</div>

<p>Notice how the whole element is dragged? It&#8217;s just a regular <code>div</code> (made to act as a push-button) with the <abbr title="Cascading Stylesheets">CSS</abbr> rule <code>-webkit-user-drag:element</code> applied to it. Easy!</p>

<h3>3. Edit the webpage</h3>

<p><ins class='block'>Doesn&#8217;t work on the iPhone. You can click in the element, but the keyboard doesn&#8217;t show up. This is likely to work when there are copy-paste functions in the phone.</ins></p>

<p class="feature" style="-webkit-user-modify:read-write-plaintext-only">
This is a paragraph that you can edit if you&#8217;re running a WebKit-based browser like Safari or the iPhone. Just click here and edit the text like a normal textbox.
</p>

<p>To allow users to edit elements of the page (or all of it) in real time, there exists a property <code>-webkit-user-modify</code>. Obviously this defaults to read-only, but you can set it to the following:</p>

<ul>
<li>read-only</li>
<li>read-write</li>
<li>read-write-plaintext-only</li>
</ul>

<p><code>read-write</code> allows the user to copy and paste in <strong>rich</strong> <em>text</em> with formatting, while <code>read-write-plaintext-only</code> pastes in only the text. This could be useful with debugging or as part of a <abbr title="What You See Is What You Get">WYSIWYG</abbr> editor, etc. Just be careful with the security side of things.</p>

<h3>4. Selection (Highlighting)</h3>

<p style="-webkit-user-select:ignore" class="feature">I am a paragraph that you can&#8217;t select (if you&#8217;re running Safari). Try and highlight me and realize that your attempts are futile. Bwah, ha ha&#8230;</p>

<p>To disallow selection (highlighting) of text for a particular element, set the <abbr title="Cascading Stylesheets">CSS</abbr> rule <code>-webkit-user-select:ignore</code>. This may be useful for many web apps, but use it sparingly to avoid irritating the user.</p>

<p class="feature selection_hilite">I am a paragraph that you can select. If your browser supports the `::selection` selector, highlighting this will result in a black background and white text for the highlighted region.</p>

<h3>5. Rounded corners</h3>

<p><big class='example' style='-webkit-border-radius:6px; border:1px solid #000;'>
Rounded corners: Look, no hacks!
</big></p>

<p><code>-webkit-border-radius</code> specifies the radius of the corners. You can specify certain corners only by using one of</p>

<ul>
<li>-webkit-border-top-left-radius</li>
<li>-webkit-border-top-right-radius</li>
<li>-webkit-border-bottom-left-radius</li>
<li>-webkit-border-bottom-right-radius</li>
</ul>

<p>For example, the following has the top-right and bottom-left corners set to a radius of 7px:</p>

<p><big class='example' style='-webkit-border-top-right-radius:7px;-webkit-border-bottom-left-radius:7px;border:1px solid #000;'>
A bit of fancy corner-work
</big></p>

<p>Elliptical corners are possible by specifying two values, eg. <code>-webkit-border-radius: 3px 7px;</code>.</p>

<h3>6. Shadows</h3>

<h4>text-shadow</h4>

<p><big class='example' style='color:#FFF;text-shadow:2px 2px 2px #000;'>
This text has a shadow when viewed with a compliant browser.
</big></p>

<p>For the text-shadow <abbr title="Cascading Stylesheets">CSS</abbr> property, the parameters are</p>

<ol>
<li>horizontal offset (negative is to the left)</li>
<li>vertical offset (negative is up)</li>
<li>blur radius (higher is more blurred)</li>
<li>shadow color</li>
</ol>

<p>For example, using <code>text-shadow: 1px 1px 7px #000;</code> we get:</p>

<p><big class='example' style='color:#fff;text-shadow:1px 1px 7px #000;'>
this excellent text with a blurred, but visible shadow.
</big></p>

<h4>box-shadow</h4>

<p><big class='example' style='-webkit-box-shadow:1px 1px 7px #000;'>
This entire element has a shadow using -webkit-box-shadow:
</big></p>

<p>To add a shadow to the actual element rather than just the text, use <code>-webkit-box-shadow</code>. Parameters are the same as for the <code>text-shadow</code> property.</p>

<ol>
<li>the horizontal offset</li>
<li>the vertical offset</li>
<li>the blur radius</li>
<li>shadow color</li>
</ol>

<p>The shadow automatically compensates for any rounded corners you may have added.</p>

<p><big class='example' style='-webkit-box-shadow:1px 1px 7px #000;-webkit-border-radius:5px;'>
This element has a shadow, but also a border-radius.
</big></p>

<h4>text-stroke</h4>

<p><big class='example' style='-webkit-text-fill-color:yellow;-webkit-text-stroke:1px black;'>
I guess I&#8217;m really just a string of text. Oh, I&#8217;m stroked.
</big></p>

<p>Use <code>-webkit-text-stroke</code> to set a border or stroke around the text. Specify thickness and color.</p>

<p>To change the fill color, use -webkit-text-fill-color; otherwise value for the color property is used.</p>

<h3>7. Backgrounds</h3>

<p>WebKit allows multiple background images using <abbr title="Cascading Stylesheets">CSS</abbr>. If you&#8217;re running Safari or other WebKit-based browser, see <a href="http://www.decaffeinated.org/archives/projects/multibg/background-image.html">this great example</a> of multiple background images with <abbr title="Cascading Stylesheets">CSS</abbr>.</p>

<p>The syntax for multiple backgrounds:</p>

<pre><code>  background-image:    url("first-img"), url("second-img"),
                       url("other-img"), url("another-img");
  background-repeat:   no-repeat, no-repeat,
                       repeat-y, repeat-x;
  background-position: top left, top right,
                       left, top;
</code></pre>

<p>The first image is associated with the first background-repeat, and the first background-position value and so on. The order in which the images appear also determines the stacking order - earlier images are stacked higher.</p>

<p>Shorthand background notation also works, the example above is equivalent to:</p>

<pre><code>background: url("first-img") top left no-repeat,
            url("second-img") top right no-repeat,
            url("other-img") left repeat-y,
            url("another-img") top repeat-x;
</code></pre>

<p>This could be really handy with making the background of a web-app, such as for the iPhone, without the need for multiple nested elements.</p>

<h3>8. Border Image</h3>

<p>To set fancy borders, you often need to use images. However, you can do away with all the javascript and <abbr title="Cascading Stylesheets">CSS</abbr> hacks and use <code>-webkit-border-image</code>.</p>

<p>Syntax:</p>

<pre><code>-webkit-border-image: url("image-url") size fit fit;
</code></pre>

<p>&#8220;image-url&#8221; needs to be an image divided into nine parts for each corner and edge and the content. The size is the height / width of the squares that the image is divided into. Fit can be <code>round</code> or <code>stretch</code>, which are ways of fitting the image into the border. To show the border, you need to actually have a <code>border</code> rule, but that can be integrated into the border-image by using something like:</p>

<pre><code>-webkit-border-image: url("image-url") 27 / 27px round round;
</code></pre>

<p>The <code>/ 27px</code> bit specifies the width of the border and makes it show if it isn&#8217;t already.</p>

<h3>9. Resizing</h3>

<p><big class='example' style="border:1px solid;resize:both;overflow:auto;max-width:100%">
This element is actually resizable.<br />If you&#8217;re using a compatible browser, drag the handle at the bottom right to resize this box.<br />Max-width is restricted to 100%.
</big></p>

<p>Making an element resizable is really easy: just set the <code>resize</code> property to <code>vertical</code>, <code>horizontal</code> or <code>both</code>.</p>

<p><big class='example' style="border:1px solid;resize:horizontal;overflow:auto;max-width:100%">
This box can only be resized horizontally (along the x-axis)
</big></p>

<p>To make scrollbars appear when the content doesn&#8217;t fit completely inside the box, it&#8217;s a good idea to set <code>overflow:auto;</code>.</p>

<p>Restrict the size that an element can be resized to by setting <code>min-width</code>, <code>min-height</code>, <code>max-width</code> and / or <code>max-height</code>.</p>

<h3>10. Colors and Opacity</h3>

<p><big class='example' style="background-color: hsla(100,90%,50%,0.6);">I am a-hued, a-saturated, and a-alpha-ed.</big></p>

<p>Colors can be set using <code>rgb(red, green, blue)</code>, <code>rgba(red, green, blue, alpha)</code>, <code>hsl(hue, saturation, lightness)</code> or <code>hsla(hue, saturation, lightness, alpha)</code>.</p>

<p>The example above has the rule <code>background-color: hsla(100,90%,50%,0.6);</code>.</p>

<hr />

<div class='example' style="background-color: black; opacity: 0.5; color: white"><big>
Easily set opacity. This element has a black background, but an alpha value of 0.5.<br />
<span style='color: yellow'>Opacity is inherited by any child elements.</span>
</big></div>

<p>Set <code>opacity</code> as a number between 0 (completely transparent) and 1 (completely opaque). If you don&#8217;t want the opacity to be inherited by child elements, set the background color using rgba or hsla and specify the alpha value there.</p>

<h2>Further reading:</h2>

<ul>
<li><a href="http://qooxdoo.org/documentation/general/webkit_css_styles">http://qooxdoo.org/documentation/general/webkit_css_styles</a></li>
<li><a href="http://www.css3.info">http://www.css3.info</a></li>
<li><a href="http://andybudd.com/presentations/css3">http://andybudd.com/presentations/css3</a></li>
</ul>

<p><style type="text/css">
    .example {
        display: block;
        padding: 3px;
        text-align: center;
    }
    .selection_hilite::selection {
        background: rgba(2, 2, 2, 0.8);
        color: white;
    }
</style></p>
]]></content:encoded>
			<wfw:commentRss>http://lipidity.com/apple/iphone-webkit-css-3/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
