<?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>Lateral Code &#187; html</title>
	<atom:link href="http://www.lateralcode.com/tag/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lateralcode.com</link>
	<description>A Web Development Blog Focused on Code and Technology</description>
	<lastBuildDate>Thu, 26 Aug 2010 22:29:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Working with Addresses? Use the new Google Maps API!</title>
		<link>http://www.lateralcode.com/new-google-maps-api/</link>
		<comments>http://www.lateralcode.com/new-google-maps-api/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 23:10:25 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1575</guid>
		<description><![CDATA[Would you like to travel to Paris? Maybe Singapore? How about Hawaii? Many people love to travel to discover new places, meet family, or just have a great time. In order to get from place to place, they often use maps. Indeed, maps are a vital part of traveling, providing directions to new, exciting locations. [...]]]></description>
			<content:encoded><![CDATA[<p>Would you like to travel to Paris? Maybe Singapore? How about Hawaii? Many people love to travel to discover new places, meet family, or just have a great time. In order to get from place to place, they often use maps. Indeed, maps are a vital part of traveling, providing directions to new, exciting locations.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/new-google-maps-api/1.jpg" alt="Maps" class="list-post-img"/></p>
<p>With the new technology age, maps have moved from tangible paper to the virtual world, allowing anyone to access them with a simple visit to <a href="http://maps.google.com">Google Maps</a>. More importantly, with the new <a href="http://code.google.com/apis/maps/index.html">Google Maps API Version 3</a>, it&#8217;s simple to integrate these maps into any website.</p>
<p>In the following article, I&#8217;ll be explaining how to get started with the new API and embrace the technology from the folks at Google.</p>
<p><span id="more-1575"></span></p>
<h2>Focus</h2>
<p>We&#8217;re going to focus on creating a static map, which is just an image of a location. This is in contrast to a dynamic map, which enables the user to move and zoom. In a follow-up article, which will be posted later this week, we&#8217;ll tackle a dynamic map using JavaScript.</p>
<h2>Static Map</h2>
<p>The static map only requires an image tag and a few configuration options:</p>
<pre><code>&lt;img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false" alt="Static Map of Chicago, Illinois"&gt;&lt;/img&gt;</code></pre>
<p>It looks a bit daunting at first, but, when broken down, it&#8217;s much easier to understand. Note that all the magic happens in the <code>src</code> attribute:</p>
<ul>
<li><code>http://maps.google.com/maps/api/staticmap?</code> &#8211; the base URL which we pass configuration options to.</li>
<li><code>center=Chicago,IL</code> &#8211; the center of the map, which, in this case, is Chicago, Illinois. Note that this can be any address.</li>
<li><code>zoom=8</code> &#8211; the amount to zoom in. This value was determined purely by experimentation.</li>
<li><code>size=512x512</code> &#8211; the size of the map in pixels. In this case, it&#8217;s 512px by 512px.</li>
<li><code>maptype=roadmap</code> &#8211; the type of the map. Possible values are roadmap, terrain, satellite, and hybrid.</li>
<li><code>sensor=false</code> &#8211; tells Google Maps whether we are trying to sense the user&#8217;s location. In this case, we aren&#8217;t.</li>
</ul>
<p>The above code produces the following image:<br />
<img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false" alt="Static Map of Chicago, Illinois" class="list-post-img"/></p>
<p>We can play around with the options a bit to produce a much different map:</p>
<pre>&lt;img alt="Static Map of New York City, New York" src="http://maps.google.com/maps/api/staticmap?center=New+York+City,NY&#038;zoom=4&#038;size=512x512&#038;maptype=hybrid&#038;sensor=false"&gt;&lt;/img&gt;</pre>
<p>These new configuration options yield the following map:<br />
<img src="http://maps.google.com/maps/api/staticmap?center=New+York+City,NY&#038;zoom=4&#038;size=512x512&#038;maptype=hybrid&#038;sensor=false" alt="Static Map of New York City, New York" class="list-post-img"/></p>
<p>When creating maps, it&#8217;s also necessary to mark important locations, whether they be destinations or areas to avoid. To do so, we can use the <code>markers</code> parameter:</p>
<pre>&lt;img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=Chicago,IL" alt="Static, Marked Map of Chicago, Illinois"&gt;&lt;/img&gt;</pre>
<p>Notice the new parameter:</p>
<pre>markers=Chicago,IL</pre>
<p>This will create the following marked map:<br />
<img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=Chicago,IL" alt="Static, Marked Map of Chicago, Illinois" class="list-post-img"/></p>
<p>We can add in more configuration options to the marker parameter, including a color and a label. For example:</p>
<pre>markers=color:blue|Chicago,IL</pre>
<p>Notice the pipe operator (<code>|</code>) which separates the color from the location. This change will edit the marker color, yielding the following map:<br />
<img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=color:blue|Chicago,IL" alt="Static, Marked (Blue) Map of Chicago, Illinois" class="list-post-img"/></p>
<p>As you can see, the blue marker still has a dot representing the location. When working with multiple locations, you might want to change this dot to a number or letter in order to differentiate between locations:</p>
<pre>markers=color:blue|label:A|Chicago,IL</pre>
<p>Instead of the dot, the image now has the letter <em>A</em>:<br />
<img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=color:blue|label:A|Chicago,IL" alt="Static, Marked (Labeled A) Map of Chicago, Illinois" class="list-post-img"/></p>
<p>To add multiple markers, just add in another <code>markers</code> parameter:</p>
<pre>&lt;img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=color:blue|label:A|Chicago,IL&#038;markers=color:purple|label:B|Hammond,IN" alt="Static, Marked Map of Chicago, Illinois and Hammond, Indiana"&gt;&lt;/img&gt;</pre>
<p>Now there are two markers: one for Chicago, Illinois and another for Hammond, Indiana:<br />
<img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=color:blue|label:A|Chicago,IL&#038;markers=color:purple|label:B|Hammond,IN" alt="Static, Marked Map of Chicago, Illinois and Hammond, Indiana" class="list-post-img"/></p>
<p>This is accomplished using the following marker code:</p>
<pre>markers=color:blue|label:A|Chicago,IL&#038;markers=color:purple|label:B|Hammond,IN</pre>
<p>Finally, when specifying the markers attribute, note that the <code>center</code> and <code>zoom</code> parameters are no longer required. If we omit these, we get the following code:</p>
<pre>&lt;img src="http://maps.google.com/maps/api/staticmap?size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=color:blue|label:A|Chicago,IL&#038;markers=color:purple|label:B|Hammond,IN" alt="Static, Marked Map of Chicago, Illinois and Hammond, Indiana with no Center and Zoom"&gt;&lt;/img&gt;</pre>
<p>And the corresponding map:<br />
<img src="http://maps.google.com/maps/api/staticmap?size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=color:blue|label:A|Chicago,IL&#038;markers=color:purple|label:B|Hammond,IN" alt="Static, Marked Map of Chicago, Illinois and Hammond, Indiana with no Center and Zoom" class="list-post-img"/></p>
<p>As shown in the image, Google Maps will automatically use a fitting <code>center</code> and <code>zoom</code> in order to display the two locations.</p>
<h2>Conclusion</h2>
<p>As you can see, we&#8217;ve created multiple static maps all through the new Google Maps API. With no needed API key (which was previously required) and some simple URL manipulation, Google makes it near effortless to integrate a map into any website.</p>
<p>Are you interested in the <a href="http://code.google.com/apis/maps/index.html">Google Maps API</a>? Do you have any questions or comments? Did you stumble upon more useful features for static maps? Leave a comment below and a share your thoughts!</p>
<p>Don&#8217;t forget that we&#8217;ll be creating dynamic maps with the JavaScript API later this week!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/new-google-maps-api/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding Tooltips to Option Tags</title>
		<link>http://www.lateralcode.com/adding-tooltips-to-option-tags/</link>
		<comments>http://www.lateralcode.com/adding-tooltips-to-option-tags/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 12:00:20 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[question]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=642</guid>
		<description><![CDATA[A short while back, Abhilash SR commented on our poll with a question that he had: Is there any way to show the select box text as [a] tool tip when user moves the mouse down the list? In other words, Abhilash would like to know whether it&#8217;s possible to add tooltips to option tags. [...]]]></description>
			<content:encoded><![CDATA[<p><big>A short while back, Abhilash SR commented on our <a href="http://www.lateralcode.com/2009/02/poll-what-are-your-feelings-about-lateral-code/" title="Lateral Code Poll">poll</a> with a question that he had:</p>
<blockquote><p>Is there any way to show the select box text as [a] tool tip when user moves the mouse down the list?</p></blockquote>
<p></big></p>
<p>In other words, Abhilash would like to know whether it&#8217;s possible to add tooltips to <code>option</code> tags. Luckily, the answer is yes!</p>
<p><span id="more-642"></span></p>
<h2>Title Attribute</h2>
<p>There are many complicated ways of adding tooltips to the <code>option</code> tag, but the simplest one is accomplished by using the title attribute.</p>
<p>Why do I recommend using the title attribute?</p>
<ul>
<li>It is supported by Internet Explorer.</li>
<li>No JavaScript or CSS is required!</li>
<li>It only needs a short amount of code.</li>
</ul>
<p>Thus, adding a tooltip is as easy as:</p>
<pre><code>&lt;option title="Your tooltip here"&gt;Your text here&lt;/option&gt;</code></pre>
<h2>Automating the Process</h2>
<p>But, we at Lateral Code want to make this a bit more interesting. In Abhilash&#8217;s case, the text that is inside the <code>option</code> tag is exactly what should be used as the tooltip.</p>
<p>As many of us don&#8217;t like to waste time copy-pasting this text into the title attribute, why don&#8217;t we write a script to do it for us?</p>
<p>Let&#8217;s use jQuery to make this very straightforward. Our JavaScript will go through each <code>select</code> element. It will add a title attribute to every <code>option</code> tag inside the given element.</p>
<p>Our algorithm is as follows:</p>
<ol>
<li>Find the total number of <code>option</code> tags to loop through.</li>
<li>Loop through each tag.</li>
<li>Set the title attribute of the tag to it&#8217;s inner HTML.</li>
</ol>
<p>This yields:</p>
<pre><code>var total = $('select option').length;
var cur;
for ( var i = 0; i < total; i++ )
{
	cur = $('select option:eq(' + i + ')');
	cur.attr( 'title', cur.html() );
}</code></pre>
<p>Remember to import jQuery:<br />
</code></pre>
<pre><code>&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;</code></pre>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/adding-tooltips-to-option-tags/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Placing Links In Images</title>
		<link>http://www.lateralcode.com/placing-links-in-images/</link>
		<comments>http://www.lateralcode.com/placing-links-in-images/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 04:53:36 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=274</guid>
		<description><![CDATA[Many of us love to use vivid, clean images to enhance a website design. Unfortunately, it may be necessary to embed links into such an image, which can be a hassle. In this article, we will present a quick and easy way to add links to your images using a small amount of HTML markup [...]]]></description>
			<content:encoded><![CDATA[<p>Many of us love to use vivid, clean images to enhance a website design. Unfortunately, it may be necessary to embed links into such an image, which can be a hassle.</p>
<p>In this article, we will present a quick and easy way to add links to your images using a small amount of HTML markup and CSS.</p>
<p>To begin, we must initialize our HTML. For this example, we will use the logo presented by Patrick Lin in his <a href="http://www.lateralcode.com/2009/01/creating-clever-logo-banners/" title="Creating Clever Logo Banners">previous article</a>:</p>
<p>It contains the following HTML:</p>
<pre><code>&lt;div id="logo"&gt;
	&lt;h1&gt;&lt;a href="/" title="Home Page"&gt;&lt;span&gt;Sample Logo&lt;/span&gt;&lt;/a&gt;&lt;/h1&gt;
&lt;/div&gt;</code></pre>
<p><span id="more-274"></span></p>
<p>and CSS:</p>
<pre><code>#logo {
    background: url(path_to_banner.jpg);
    width: 718px;
    height: 66px;
    padding-left: 62px;
    padding-top: 34px;
}

#logo:hover {
    background-position: 0 -100px;
}

#logo h1 a span {
    display: none;
}</code></pre>
<p>Notice that Patrick uses a span element to mask the text that would normally appear. This method is vital in order to place a well-positioned link in the image.</p>
<p>To begin, let&#8217;s add properties to the link element inside the <code>#logo</code> div:</p>
<pre><code>#logo h1 a {
    display: block;
}</code></pre>
<p>This line is key for our link. By displaying the link element as a block, we are able to give it a width and height. Note that by doing so, it is possible to place this link in an area that covers the sample text in our logo.</p>
<p>Next we need to add some dimensions:</p>
<pre><code>#logo h1 a {
    display: block;
    width: 172px;
    height: 44px;
}</code></pre>
<p>Using this width and height, we are able to make the link reside in the correct area for our logo image.</p>
<p>Now that the basics have been presented, let&#8217;s move on to one main exception: Internet Explorer.</p>
<p>If you place two or more of these block links on the same image, IE7 and below seem to remove the link attribute. This has been the case with our RSS link in the logo image.</p>
<p>To solve this problem, we have noticed a peculiar case. If we place a background color or image for the link, it seems to work fine. For example:</p>
<pre><code>#logo h1 a {
    display:block;
    width:172px;
    height:44px;
    background: #fff;
}</code></pre>
<p>With two block links or more, the above code solves the problem. Unfortunately, having a white background completely hides the actual RSS image. The trick is to use opacity. By setting the opacity to 0, we are able to remove the background color but still maintain the link:</p>
<pre><code>#logo h1 a {
    display: block;
    width: 172px;
    height: 44px;
    background: #fff;
    filter: alpha(opacity = 0);
}</code></pre>
<p>The opacity for IE is defined in an odd fashion that causes the CSS not to validate.</p>
<p>By placing the last line of code in an ie-only css file, you can still maintain valid CSS in your template.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/placing-links-in-images/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating Clever Logo Banners</title>
		<link>http://www.lateralcode.com/creating-clever-logo-banners/</link>
		<comments>http://www.lateralcode.com/creating-clever-logo-banners/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 07:04:24 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=258</guid>
		<description><![CDATA[Good designs are always clever. They need something to help them stand out from the rest. Here&#8217;s how to create a clever logo banner that looks good and is SEO Friendly, like the one Lateral Code uses, using an image and some clever CSS. The first step is to create the banner. For demonstration purposes, [...]]]></description>
			<content:encoded><![CDATA[<p>Good designs are always clever. They need something to help them stand out from the rest. Here&#8217;s how to create a clever logo banner that looks good and is SEO Friendly, like the one Lateral Code uses, using an image and some clever CSS.</p>
<p>The first step is to create the banner. For demonstration purposes, the following banner will be used:<br />
<a href="http://www.lateralcode.com/wp-content/uploads/cleverbanner.jpg"><img src="http://www.lateralcode.com/wp-content/uploads/cleverbanner-150x100.jpg" alt="Sample Logo" title="Sample Logo" width="150" height="100" class="aligncenter size-thumbnail wp-image-263" /></a></p>
<p>This is the markup involved:</p>
<pre><code>
&lt;div id="logo"&gt;
	&lt;h1&gt;&lt;a href="/" title="Home Page"&gt;&lt;span&gt;Sample Logo&lt;/span&gt;&lt;/a&gt;&lt;/h1&gt;
&lt;/div&gt;
</code></pre>
<p><span id="more-258"></span><br />
with the following CSS:</p>
<pre><code>
#logo {
    background:url(path_to_banner.jpg);
    width:780px;
    height:100px;
}
</code></pre>
<p>That part is easy enough. The next step is a little bit of clever CSS and some measurements.</p>
<p><a href="http://www.lateralcode.com/wp-content/uploads/cleverbanner2.jpg"><img src="http://www.lateralcode.com/wp-content/uploads/cleverbanner2-150x150.jpg" alt="Measuring the Sample Logo" title="Measuring the Sample Logo" width="150" height="150" class="aligncenter size-thumbnail wp-image-265" /></a></p>
<p>In this example, the Logo runs from 62px to 234px horizontally, and 34px to 78px vertically, or 172x44px, so we add the following CSS:</p>
<pre><code>
#logo h1 a {
    display:block;
    width:172px;
    height:44px;
}
</code></pre>
<p>And to position it, we add to #logo:</p>
<pre><code>
#logo {
    background:url(path_to_banner.jpg);
    width:718px;
    height:66px;
    padding-left:62px;
    padding-top:34px;
}
</code></pre>
<p>Notice that I have shrunk the width and the height. This is because of how the <a href="http://www.w3.org/TR/CSS2/box.html">CSS Box Model</a> works &#8211; the actual width is the specified width added to the padding.</p>
<p>Now we are stuck with a problem: the text from the HTML overlays the text in the image, making it look unappealing. The reason we wrap the text in a span is so we can hide it, like so:</p>
<pre><code>
#logo h1 a span {
    display:none;
}
</code></pre>
<p>And it looks great.</p>
<p>As a bonus tip, you can increase interactivity by having the image show a friendly tip on hover &#8211; which, unfortunately, does not work in Internet Explorer 6.</p>
<p>We do this using a technique known as CSS Spriting &#8211; putting two images in one and only displaying part of it at a time. Here, I duplicate the image vertically and put an extra tidbit on the second one.</p>
<p><a href="http://www.lateralcode.com/wp-content/uploads/cleverbanner3.jpg"><img src="http://www.lateralcode.com/wp-content/uploads/cleverbanner3-150x150.jpg" alt="Sprited Logo" title="Sprited Logo" width="150" height="150" class="aligncenter size-thumbnail wp-image-266" /></a></p>
<p>Because we set #logo to a specified height, the part below what we want to show gets hidden. Then we add the hover effect:</p>
<pre><code>
#logo:hover {
    background-position:0 -100px;
}
</code></pre>
<p>Then, when the user hovers over logo, it shifts the background position and shows the second image, that has the tip.</p>
<p>So the final CSS is:</p>
<pre><code>
#logo {
    background:url(path_to_banner.jpg);
    width:718px;
    height:66px;
    padding-left:62px;
    padding-top:34px;
}
#logo:hover {
    background-position:0 -100px;
}
#logo h1 a {
    display:block;
    width:172px;
    height:44px;
}
#logo h1 a span {
    display:none;
}
</code></pre>
<p>To create the effect.</p>
<p>Of course, to make it work in Internet Explorer 6, it is possible to use jQuery to add the hover effect that CSS isn&#8217;t able to:</p>
<pre><code>
$(function() {
    $("#logo").hover(function() {
        $(this).css("backgroundPosition", "0 -100px");
    },
    function() {
        $(this).css("backgroundPosition","0 0");
    });
});
</code></pre>
<p>And there you have it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/creating-clever-logo-banners/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>5 Simple CSS Tricks</title>
		<link>http://www.lateralcode.com/5-simple-css-tricks/</link>
		<comments>http://www.lateralcode.com/5-simple-css-tricks/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 07:19:47 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=248</guid>
		<description><![CDATA[CSS can be the key to make or break a site design. To enable you to create and edit your own template, we have decided to present 5 Simple CSS tricks. Please feel free to directly use the code shown here in your own site. Reset Values Many web browsers have default CSS settings for [...]]]></description>
			<content:encoded><![CDATA[<p>CSS can be the key to make or break a site design. To enable you to create and edit your own template, we have decided to present 5 Simple CSS tricks. Please feel free to directly use the code shown here in your own site.</p>
<ol>
<li><strong>Reset Values</strong>
<p>Many web browsers have default CSS settings for HTML elements. Unfortunately, these settings differ across each browser. In order to maintain a similar look of your site in multiple browsers, resetting these values is a must. Here is a quick reset snippet commonly used:</p>
<pre><code>* {
     margin: 0;
     padding: 0;
}</code></pre>
<p><span id="more-248"></span></p>
<p>For more in-depth and thorough code, you may visit <a href="http://meyerweb.com/eric/tools/css/reset/">CSS Tools</a>.</li>
<li><strong>CSS Hover Pseudo Class</strong>
<p>Creating nice hover effects can greatly help out your visitors. Many websites create a basic effect that changes the text color, border, or background when the mouse hovers over a link. This enables visitors to easily identify these elements and follow them to access your content.</p>
<pre><code>a:hover {
     border-bottom: 1px solid black;
}</code></pre>
<p>This sample piece of code adds a 1 pixel wide bottom border when the user hovers over a link.</p>
<p>Many web designers only use the hover pseudo class while dealing with links. Note that it can be used much more often. For example:</p>
<pre><code>input {
     background-color: #e7e7e7;
}

input:hover {
     background-color: #fff;
}</code></pre>
<p>This changes the background of a hovered input box to signify that the user may type in it.</li>
<li><strong>Image Display</strong>
<p>Search engines are only able to understand the words that you place into your HTML markup. Flash content or images are not directly identifiable. </p>
<p>A problem may arise when you create a logo image. If you want to have actual words on the logo image (as we have done in our site&#8217;s logo), you are not expressing this content to the search engines. For example, let&#8217;s say you wanted to integrate your logo image:</p>
<pre><code>#logo {
     width: 960px;
     height: 150px;
     background: #fff url(your-image-name.jpg) no-repeat;
}

&lt;div id="logo"&gt;

&lt;/div&gt;</code></pre>
<p>As you can see, there is no content in your logo div. Search engines will not be able to understand any text placed in your image. This is where an easy CSS trick comes in handy.</p>
<p>Let&#8217;s say that you placed your site&#8217;s name, which we will represent with &#8220;Site Name&#8221;, directly into your image. It is possible to do the following:</p>
<pre><code>#logo {
     width: 960px;
     height: 150px;
     background: #fff url(your-image-name.jpg) no-repeat;
}

#logo h1 {
     display: none;
}

&lt;div id="logo"&gt;
     &lt;h1&gt;Site Name&lt;/h1&gt;
&lt;/div&gt;</code></pre>
<p>By adding this invisible text, the search engine is able to see the words you placed on your logo without them actually appearing on your site twice.</li>
<li><strong>Fixed Width Wrapper</strong>
<p>Many sites use a fixed width design. The common values for such a design are 780px and 960px.</p>
<p>Some web designers make the mistake of restating this width every time they create a new element. For example:</p>
<pre><code>#logo {
     width: 960px;
     height: 150px;
     margin: 0 auto;
     background: #fff url(some-image.jpg) no-repeat;
}

#menu {
     width: 960px;
     height: 50px;
     margin: 0 auto;
}

#content {
     width: 960px;
     margin: 0 auto;
     background: #fff;
}</code></pre>
<p>Definitions can easily become messy and out of shape when creating a fixed width design like this. A simple way to combat this problem is by creating a wrapper div that contains all other elements:</p>
<pre><code>#wrapper {
     width: 960px;
     margin: 0 auto;
}

#logo {
     height: 150px;
     background: #fff url(some-image.jpg) no-repeat;
}

#menu {
     height: 50px;
}

#content {
     background: #fff;
}</code></pre>
<p>This produces clean, efficient code that takes advantage of the CSS cascading property.</li>
<li><strong>Vertical Alignment</strong>
<p>Many beginning CSS users have trouble making an element vertically aligned in a container. For example, given the following HTML and CSS:</p>
<pre><code>#logo {
     width: 960px;
     height: 150px;
}

&lt;div id="logo"&gt;
     &lt;h1&gt;Site Name&lt;/h1&gt;
&lt;/div&gt;</code></pre>
<p>A vertical alignment can be created using absolute positioning. By giving the logo a position style of relative, the header can be placed in the dead center of the container&#8221;</p>
<pre><code>#logo {
     position: relative;
     width: 960px;
     height: 150px;
}

#logo h1 {
     position: absolute;
     top: 50%;
}

&lt;div id="logo"&gt;
     &lt;h1&gt;Site Name&lt;/h1&gt;
&lt;/div&gt;</code></pre>
<p>And that is all there is to it. The text is now vertically aligned. To make it centered horizontally, add the following line to the <code>#logo h1</code> definition:</p>
<pre><code>left: 50%;</code></pre>
</li>
</ol>
<p>Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/5-simple-css-tricks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Building a contact form with HTML and PHP</title>
		<link>http://www.lateralcode.com/building-a-contact-form-with-html-and-php/</link>
		<comments>http://www.lateralcode.com/building-a-contact-form-with-html-and-php/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 08:19:26 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=237</guid>
		<description><![CDATA[A while back, my colleague Karthik posted a CSS styled form. This time, I am going to show how to build the backend of an HTML form using PHP. To begin with, you can take the code from Karthik&#8217;s example and paste it into a file called &#8216;contact.php&#8217; or a name of your own choosing. [...]]]></description>
			<content:encoded><![CDATA[<p>A while back, my colleague Karthik posted a <a href="http://www.lateralcode.com/2008/12/neatly-styled-forms-with-css/">CSS styled form</a>. This time, I am going to show how to build the backend of an HTML form using PHP.</p>
<p>To begin with, you can take the code from Karthik&#8217;s example and paste it into a file called &#8216;contact.php&#8217; or a name of your own choosing.</p>
<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en" &gt;
&lt;head&gt;
	&lt;link rel="stylesheet" type="text/css" href="style.css" /&gt;
	&lt;title&gt;Form Styling!&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

	&lt;h2&gt;Input Form&lt;/h2&gt;
	&lt;form id="input-form" name="input-form"&gt;
		&lt;label for="first-name"&gt;First Name: &lt;/label&gt;
		&lt;input type="text" id="first-name" name="first-name" class="field" /&gt;
		&lt;label for="last-name"&gt;Last Name: &lt;/label&gt;

		&lt;input type="text" id="last-name" name="last-name" class="field" /&gt;
		&lt;label for="e-mail"&gt;E-mail: &lt;/label&gt;
		&lt;input type="text" id="e-mail" name="e-mail" class="field" /&gt;
		&lt;label for="text"&gt;Message: &lt;/label&gt;
		&lt;textarea id="text" name="text" class="field"&gt;&lt;/textarea&gt;

		&lt;input type="submit" id="submit" name="submit" value="Submit" /&gt;
	&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<p><span id="more-237"></span></p>
<p>Of course, Karthik&#8217;s form doesn&#8217;t supply a method or action, as it is just an example. Let&#8217;s add that in. For this example, we will have the method be POST, because it can handle longer messages, and have the action be blank, meaning it will call the same page.</p>
<pre><code>&lt;form id="input-form" name="input-form" method="post" action=""&gt;</code></pre>
<p>So, let&#8217;s put some PHP into it before the Doctype.</p>
<pre><code>
&lt;?php
	$first_name = isset($_POST['name']) ? $_POST['first-name'] : '';
	$last_name = isset($_POST['subject']) ? $_POST['last-name'] : '';
	$e_mail = isset($_POST['email']) ? $_POST['e-mail'] : '';
	$text = isset($_POST['content']) ? $_POST['text'] : '';

	$ip = $_SERVER['REMOTE_ADDR'];
?&gt;
</code></pre>
<p>What this does is fetch the values posted by the form if it exists, otherwise sets the variable to empty. If the variable has not been set, and we try to assign it to a variable, PHP might choke on it, so we should check before we assign just in case. The next step is to check if the person has submitted the form, or if they&#8217;ve only opened the page. If the person has submitted the form but has left certain fields, we&#8217;ll want to tell him/her. Now we&#8217;ll add a piece of PHP between the body tag and the form tag.</p>
<pre><code>
&lt;?php
if (isset($_POST['email']) &#038;&#038; (empty($first_name) || empty($last_name) || empty($e_mail) || empty($text)) {
	echo "&lt;ul class=\"validation\"&gt;\n";
	if (empty($first_name)) echo "&lt;li&gt;First name not entered&lt;/li&gt;\n";
	if (empty($last_name)) echo "&lt;li&gt;Last name not entered&lt;/li&gt;\n";
	if (empty($e_mail) || !is_valid_email($email)) echo "&lt;li&gt;Email adress not entered&lt;/li&gt;\n";
	if (empty($text)) echo "&lt;li&gt;No message entered&lt;/li&gt;\n";
	echo "&lt;/ul&gt;\n";
} elseif (isset($_POST['email'])) {
	$content = "$first_name $last_name ($ip) write:\n\n$text";
	$sent = mail("example@example.org", "Message from Mars", $content, "From: $e_mail");
	if ($sent) {
		echo "&lt;ul class=\"success\"&gt;\n";
		echo "&lt;li&gt;Your message has been sent&lt;/li&gt;\n";
		echo "&lt;/ul&gt;\n";
	} else {
		echo "&lt;ul class=\"error\"&gt;\n";
		echo "&lt;li&gt;Your message could not be sent at this time. Please try again later.&lt;/li&gt;\n";
		echo "&lt;/ul&gt;\n";
	}
}
?&gt;
</code></pre>
<p>What this does is first check if the form has been submitted (if it has been submitted, all the variables will be set, so we can just check for one of them) and if it has, if it&#8217;s missing any one of the fields, then it will throw out an error message with a list of missing parts. You can style this how you like.</p>
<p>The next part checks that the form has been submitted, and since it passed the first test, everything has been filled in, so it sends an email off. The PHP mail() function takes arguments in the order: send-to address, subject, content, other headers and returns whether or not the message was sent. In the other headers, we specify the From address. Replace the email address with the one you want the emails sent to and the subject to your preferred subject. We then output a message telling the user if the message was sent.</p>
<p>Since the PHP segments only write out if the form has been submitted, only the form is shown. However, what if the person wrote a beautiful 5-page essay and put it in, but forgot to put in his name? Then his entire message will be gone! We can rectify this by echoing the posted variables into the form. If nothing&#8217;s been submitted, the variables will be empty and he won&#8217;t know any better. If it&#8217;s been submitted, the filled in elements will be retained.</p>
<pre><code>
	&lt;form id="input-form" name="input-form" method="post" action=""&gt;
		&lt;label for="first-name"&gt;First Name: &lt;/label&gt;
		&lt;input type="text" id="first-name" name="first-name" class="field" value="&lt;?php echo $first_name; ?&gt;" /&gt;
		&lt;label for="last-name"&gt;Last Name: &lt;/label&gt;
		&lt;input type="text" id="last-name" name="last-name" class="field" value="&lt;?php echo $last_name; ?&gt;" /&gt;
		&lt;label for="e-mail"&gt;E-mail: &lt;/label&gt;
		&lt;input type="text" id="e-mail" name="e-mail" class="field" value="&lt;?php echo $e_mail; ?&gt;" /&gt;
		&lt;label for="text"&gt;Message: &lt;/label&gt;
		&lt;textarea id="text" name="text" class="field"&gt;&lt;php echo $text; ?&gt;&lt;/textarea&gt;

		&lt;input type="submit" id="submit" name="submit" value="Submit" /&gt;
	&lt;/form&gt;
</code></pre>
<p>So, the final product:</p>
<pre><code>&lt;?php
	$first_name = isset($_POST['name']) ? $_POST['first-name'] : '';
	$last_name = isset($_POST['subject']) ? $_POST['last-name'] : '';
	$e_mail = isset($_POST['email']) ? $_POST['e-mail'] : '';
	$text = isset($_POST['content']) ? $_POST['text'] : '';

	$ip = $_SERVER['REMOTE_ADDR'];
?&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en" &gt;
&lt;head&gt;
	&lt;link rel="stylesheet" type="text/css" href="style.css" /&gt;
	&lt;title&gt;Form Styling!&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php
if (isset($_POST['email']) &#038;&#038; (empty($first_name) || empty($last_name) || empty($e_mail) || empty($text)) {
	echo "&lt;ul class=\"validation\"&gt;\n";
	if (empty($first_name)) echo "&lt;li&gt;First name not entered&lt;/li&gt;\n";
	if (empty($last_name)) echo "&lt;li&gt;Last name not entered&lt;/li&gt;\n";
	if (empty($e_mail) || !is_valid_email($email)) echo "&lt;li&gt;Email adress not entered&lt;/li&gt;\n";
	if (empty($text)) echo "&lt;li&gt;No message entered&lt;/li&gt;\n";
	echo "&lt;/ul&gt;\n";
} elseif (isset($_POST['email'])) {
	$content = "$first_name $last_name ($ip) writes:\n\n$text";
	$sent = mail("example@example.org", "Message from Mars", $content, "From: $e_mail");
	if ($sent) {
		echo "&lt;ul class=\"success\"&gt;\n";
		echo "&lt;li&gt;Your message has been sent&lt;/li&gt;\n";
		echo "&lt;/ul&gt;\n";
	} else {
		echo "&lt;ul class=\"error\"&gt;\n";
		echo "&lt;li&gt;Your message could not be sent at this time. Please try again later.&lt;/li&gt;\n";
		echo "&lt;/ul&gt;\n";
	}
}
?&gt;
	&lt;h2&gt;Input Form&lt;/h2&gt;
	&lt;form id="input-form" name="input-form" method="post" action=""&gt;
		&lt;label for="first-name"&gt;First Name: &lt;/label&gt;
		&lt;input type="text" id="first-name" name="first-name" class="field" value="&lt;?php echo $first_name; ?&gt;" /&gt;
		&lt;label for="last-name"&gt;Last Name: &lt;/label&gt;
		&lt;input type="text" id="last-name" name="last-name" class="field" value="&lt;?php echo $last_name; ?&gt;" /&gt;
		&lt;label for="e-mail"&gt;E-mail: &lt;/label&gt;
		&lt;input type="text" id="e-mail" name="e-mail" class="field" value="&lt;?php echo $e_mail; ?&gt;" /&gt;
		&lt;label for="text"&gt;Message: &lt;/label&gt;
		&lt;textarea id="text" name="text" class="field"&gt;&lt;php echo $text; ?&gt;&lt;/textarea&gt;

		&lt;input type="submit" id="submit" name="submit" value="Submit" /&gt;
	&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>And that&#8217;s it. Have fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/building-a-contact-form-with-html-and-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
