Advanced tableless forms

XHTML/CSS 5 Comments »

I am always looking for easy ways to use less tables in my markup. When designing a website I always aim for no tables but in a web application I may cheat from time to time.

Some time ago, thanks to an article on quirksmode, I began creating tableless forms. This trick was great for simple forms but I kept using tables for really complicated forms.

For example, if I needed a 2 or 3 column form I would just use a table because figured it was easier. Well, after playing with the orginal code from quirksmode I have found a simple way to create multi column forms with little to no extra effort. It just requires you to think about it ahead of time.

Let’s take a look at a simple example based on the original tableless form.

<!-- ----------
HTML
---------- -->
<form>

	<label for="firstname">First Name:</label>
	<input type="text" name="firstname" id="firstname"/><br/>

	<label for="lastname">Last Name:</label>
	<input type="text" name="lastname" id="lastname"/><br/>

	<label for="emailaddress">Email Address:</label>
	<input type="text" name="emailaddress" id="emailaddress"/><br/>

</form>
/* ----------
CSS
---------- */
label, input {
	display: block;
	float: left;
	width: 150px;
	margin-bottom: 10px;
}
label {
	width: 110px;
	text-align: right;
	padding-right: 10px;
	margin-top: 2px;
}
br {
	clear: left;
}

That code would produce a form that looked like this:

simple tableless form

But what if you want to do something a bit more advanced, say, like this:


advanced tableless form

We have made the form 2 columns and thrown in a select box and a textarea. Normally I would be preparing to use tables in a situation like this until a stopped and realized how easy it would be to do without tables.

The CSS hardly changes.

/* ----------
CSS
---------- */
label, input, select, textarea {
	display: block;
	float: left;
	width: 150px;
	margin-bottom: 10px;
}
label {
	width: 110px;
	text-align: right;
	padding-right: 10px;
	margin-top: 2px;
}
textarea {
	height: 50px;
}
br {
	clear: left;
}

All I’ve done is add the select and textarea selectors to the first definition. I also added a specific definition to make the textarea 50 pixels high.

Now the HTML doesn’t change too much either. There is just more of it, obviously.

<!-- ----------
HTML
---------- -->
<form>

	<label for="firstname">First Name:</label>
	<input type="text" name="firstname" id="firstname" tabindex="1"/>

	<label for="address">Address:</label>
	<input type="text" name="address" id="address" tabindex="5"/><br/>

	<label for="lastname">Last Name:</label>
	<input type="text" name="lastname" id="lastname" tabindex="2"/>

	<label for="city">City:</label>
	<input type="text" name="city" id="city" tabindex="6"/><br/>

	<label for="emailaddress">Email Address:</label>
	<input type="text" name="emailaddress" id="emailaddress" tabindex="3"/>

	<label for="province">Province:</label>
	<select name="province" id="province" tabindex="7">
		<option value="0">--Select a Province--</option>
		<option value="AB">Alberta</option>
		<option value="BC">British Columbia</option>
		<option value="MB">Manitoba</option>
		<option value="NB">New Brunswick</option>
		<option value="NL">Newfoundland</option>
		<option value="NS">Nova Scotia</option>
		<option value="ON">Ontario</option>
		<option value="PE">Prince Edward Island</option>
		<option value="PQ">Quebec</option>
		<option value="SK">Saskatchewan</option>
	</select><br/>

	<label for="comments">Comments:</label>
	<textarea name="comments" id="comments" tabindex="4"></textarea>

	<label for="postalcode">Postal Code:</label>
	<input type="text" name="postalcode" id="postalcode" tabindex="8"/><br/>

</form>

What you should notice is that the markup creates the fields from left to right. I have also added a tabindex to each field so that you can tab through them from top to bottom. So, the tabbing would start on the First Name field tab to the bottom on the left hand side fields then move tot he top of the right side fields and tab to the bottom of that column, exactly how it would if I had created the form with tables.

So in the end we have nice clean markup for our more advanced form with hardly any extra CSS and no messy tables. Enjoy!

kick it on DotNetKicks.com

Popularity: 19% [?]

If you liked this article consider subscribing to my free rss article feed to automatically get new articles in your feed reader.

Friday roundup for April 25, 2008

ASP.Net, Browsers, JavaScript/Ajax, SQL, Silverlight, XHTML/CSS No Comments »

Here is what I liked this week. Enjoy!

Comparing Popular JavaScript/Ajax Frameworks
After four days of ASP.NET AJAX training with Stephen Walther I set out to learn more about my options in choosing a solution for a JavaScript/Ajax framework. If I realized days later I would be writing this comprehensive post on 7 of the most popular frameworks, I may have just went with the “Inny-Minny-Miney-Moe” method!

jQuery AJAX calls to a WCF REST Service
Since I’ve posted a few jQuery posts recently I’ve gotten a bunch of feedback to have more content on using jQuery in Ajax scenarios and showing some examples on how to use jQuery to cut out ASP.NET Ajax. In this post I’ll show how you can use jQuery to call a WCF REST service without requiring the ASP.NET AJAX ScriptManager and the client scripts that it loads by default. Note although I haven’t tried it recently the same approach should also work with ASMX style services.

SQL SERVER - Better Performance - LEFT JOIN or NOT IN?
First of all answer this question : Which method of T-SQL is better for performance LEFT JOIN or NOT IN when writing query? Answer is : It depends!

Video: Write Your First Silverlight Game
In this video, I demonstrate how to start writing your first Silverlight game. I show how to create a dramatic space scene, add a soundtrack, and associate movement with the mouse wheel. This is the first part of a two-part series.

Reading binary files using Ajax
But when it comes to binary files, helping hands from server-side technologies are often necessary.

So I googled around to see what I can do about binary files with Ajax and found this Marcus Granado’s post at http://mgran.blogspot.com/2006/08/downloading-binary-streams-with.html

What he posted there worked like a charm for FireFox and Safari but I couldn’t get it to work for IE.

But luckily, within the same page, someone had posted up a solution for IE as a comment, which is written in VBScript.

Safari CSS Masks
Webkit continues to impress with it’s early implementations of new standards. WebKit now supports alpha masks in CSS. Masks allow you to overlay the content of a box with a pattern that can be used to knock out portions of that box in the final display. In other words, you can clip to complex shapes based off the alpha of an image.

Popularity: 36% [?]

If you liked this article consider subscribing to my free rss article feed to automatically get new articles in your feed reader.

Friday roundup for April 4, 2008

ASP.Net, Browsers, JavaScript/Ajax, SEO/Marketing, XHTML/CSS No Comments »

Here are some interesting stories from this week.

IE 8 strict mode doesn’t allow for CSS opacity?
So the fact that this has been labeled as by design suggests that IE8 will be the only browser produced in the last 10 or so years that will not support opacity in its strictest mode. Thats rediculous.

Google Will Sell Performics, SEOs Exhale
Exciting news from The Official Google blog today that reveals Google will stop scaring SEOs everywhere and will sell off Performics, the search marketing company that they accidentally acquired when they bought DoubleClick last year. To avoid the conflict of interest that comes when you’re a search engine selling search engine optimization services, Google will split Performics into two companies – an affiliate marketing company and a search marketing company – and then sell the search marketing half.

Webforms is dead. Long live MVC!
Scott Hanselman’s fourth screencast *confirms* that the interfaces and abstractions made as part of the MVC (HttpContextBase, IHttpRequest, IHttpResponse, etc.) will not be put into the existing Webforms model. That means that once MVC is released, the old HttpContext object in WebForms will *not* inherit from HttpContextBase, nor will the WebForms versions of HttpRequest and HttpResponse objects implement the interfaces.

But I’m not moving my mouse!
The IE team reacted correctly: the bug has been solved in IE8b1. When the mouse does not move any more the mousemove event stops firing, as it should.

However, this same bug was recently introduced in Safari (Windows) and Opera!

Safari 3.0 and Opera 9.26 support mousemove correctly, but Safari 3.1 and Opera 9.5b have copied the IE bug.

Popularity: 40% [?]

If you liked this article consider subscribing to my free rss article feed to automatically get new articles in your feed reader.

Netscape Navigator the end of an era and Changes to the CSS Working Group

Browsers, News, XHTML/CSS No Comments »

Netscape Navigator Goes Quietly Into the Night
On New Year’s Eve, the news went out from AOL that the long life of the Netscape Browser was coming to an end.

Though this news will have little or no impact on the vast majority of web developers, those of us for whom Netscape was their first browser will give a wistful sigh of rememberance.

Coming Soon: Changes to the CSS Working Group?
On December 14th, one of the key members of the CSS Working Group, L. David Baron of the Mozilla Corporation made an announcement:

“I’ve informed the CSS working group that I am no longer participating in member-only mailing lists or meetings. I believe the member-confidential nature of the group hurts the future development of CSS by making the group:

* fail to accept the contributions of many who would like to contribute to CSS and
* get mired in debates and stalling tactics that companies would not be comfortable using in public.

“I still intend to participate in any discussions that take place on www-style, public-css-testsuite, and other public forums.

“I support rechartering the CSS working group as a public group.”

Although there have been few public follow-ups, representatives of Microsoft and Google expressed their support. It seems like change within the CSS Working Group is coming, but like everything the Group does, it may not happen quickly.

Popularity: 16% [?]

If you liked this article consider subscribing to my free rss article feed to automatically get new articles in your feed reader.

Why CSS Is Good For Your Web Site

XHTML/CSS No Comments »

Cascading Style Sheets (CSS) are used within the HTML behind your Web site as a way of controlling how each page is laid out and what elements on it look like. For instance, you can use CSS to make headings in your copy a standard size across the whole of your site.

CSS has been around for several years and is supported by all the major browsers available today, including Internet Explorer for the PC and Mac, Firefox, Safari and Opera.

Using CSS to control your Web site will give you several benefits:

Makes your Web pages snappier

By using CSS and writing your HTML code to match standards like ‘XHTML Transitional’ or ‘XHTML Strict’ you can decrease the ‘render time’ of your pages. This is the time it takes between downloading the page and actually showing it on screen to your Web site visitor.

When using tables for layout - the traditional alternative to using CSS - and ‘font’ tags to control how the text on the page looks, the browsers have a lot more work to do before they show the page. Using CSS and the proper DocType for the pages means the browser knows what to expect from the code and can display it much more quickly.

In practice, converting to a standards based CSS layout on one client’s Web site reduced the time it took the page to display by almost a quarter of a second. Although this is a very small amount of time, it is more than enough to make a Web site feel much more snappy and responsive, helping it give a good impression to your potential customers.

Makes your Web site quicker to update

As well as making your pages display quicker, CSS makes it easier to make global updates to your Web site. Say you’re having a minor change in corporate image and want all your page headings changed from blue to green. With CSS controlling how your headings look, that means changing the colour in one file and the whole site shows the change - a two minute job rather than having to edit every page on the site.

This flexibility gives you the opportunity to do more with your Web site. Want to show your support for Red Nose Day? Again, one file change can put a little red nose next to all of your headers, turn the text red and even make them display in a silly typeface. Turning them back to normal for the next day is, once again, a single file change.

Good for Search Engine Optimisation

Because using CSS removes lots of HTML from your pages as layout and the look of text is controlled through the CSS file, it makes your textual content much more prominent within your HTML. This means the search engine spiders can easily find your textual content, and that your content is generally displayed in one block, rather than being split up into less readable chunks by HTML just to fit it in to your design.

Using ’semantically correct XHTML’ - ie heading tags around the headings and sub-headings in your copy, and bold or strong tags around content you wish to highlight - tells the search engines those words are the most important on the page. This helps give the page a boost for searches which match the words which are marked as more important in this way.

Helps in passing the Disability Discrimination Act

Using good CSS and XHTML makes it easy for people with disabilities to change your pages the way they may need to for easy reading. This may be through increasing or decreasing the font size, or having it read to them through a screen reader. The clean page coding that goes along with using CSS means screen readers can easily navigate through your page and find the content, giving a good experience to visually impaired users.

Using CSS and XHTML also helps you comply with the UK Disability Discrimination Act rules for accessible Web sites. This is a valuable side-effect of using this kind of coding and takes no extra development time to be compliant.

Helps browsing from different devices

As well as helping screen readers, using CSS means alternative devices like mobile phones and PDAs can show your content effectively and easily. Although the current market in the West for browsing the Web through mobiles is small, it is growing and by using CSS you can create a Web site which is easily viewable on these devices with little extra effort,. So as more people use them it will be simple to convert your site to work with current or future devices..

Downsides

Currently, Web browsers treat CSS slightly differently, so when your Web site is created you may need slightly more cross-browser testing, and you will need to find a Web designer who understands how to build a site in CSS correctly. Most professional designers and developers are now seeing the benefits of creating standards based CSS sites, but it is worth ensuring that anyone you hire to make your Web site does know CSS before starting a project.

But the downsides are small when compared to the immediate and ongoing benefits of a CSS-based Web site.

Author Info:

Paul Silver and David Rosam are Head of Technical SEO and Head of SEO Copywriting at Web Positioning Centre (http://webpositioningcentre.co.uk). Paul has been involved with the Web commercially since 1996 and David has been writing marketing copy for 20 years, and writing for the Web for a decade.

Popularity: 14% [?]

If you liked this article consider subscribing to my free rss article feed to automatically get new articles in your feed reader.

Invisible Captcha

ASP.Net, JavaScript/Ajax, XHTML/CSS No Comments »

Phil Haack has suggested a great alternative to the captcha. Personally I hate captchas because they are annoying and hard to read a lot of the time. Phil’s idea would block spam just effectively and doesn’t involve an action by the user in fact the user doesn’t even know it is there (the way it should be).

The Invisible Captcha control plays upon the fact that most comment spam bots don’t evaluate javascript. However there’s another particular behavioral trait that bots have that can be exploited due to the bots inability to support another browser facility.

You see, comment spam bots love form fields. When they encounter a form field, they go into a berserker frenzy (+2 to strength, +2 hp per level, etc…) trying to fill out each and every field. It’s like watching someone toss meat to piranhas.

At the same time, spam bots tend to ignore CSS. For example, if you use CSS to hide a form field (especially via CSS in a separate file), they have a really hard time knowing that the field is not supposed to be visible.

Popularity: 20% [?]

If you liked this article consider subscribing to my free rss article feed to automatically get new articles in your feed reader.

Combine CSS with JS and make it into a single download!

ASP.Net, JavaScript/Ajax, XHTML/CSS 3 Comments »

The following example is a hack to combine CSS and JavaScript into a single file thus reducing page load speeds. This technique is based on the way current browsers react in certain situations and should be used cautiously.

Now, if you have by any chance worked on page load optimizations, you would know how costly each resource download is. The more the number of external resources that you refer to, the more the time it takes for the page load to complete.

Typically, web pages refer to many external CSS and JS files and hence incur many resource downloads. The advice from the PLT (page load time) gurus is to combine all the CSS files into one and all the JS files into one so as to reduce the number of resource downloads to just two. This, without any doubt, would help boost your PLT.

If you feel that two downloads still isn’t the best, I concur. In this post, we’ll look at a technique to combine CSS with JS and get the resource download count to one! I discovered this technique while desperately trying to improve the page load time for the pages in Microsoft Office Live. Read on…

The technique relies on how CSS and JS parser behaves in IE and Firefox.

* When the CSS parser encounters a HTML comment token (<!–) in CSS content, the token gets ignored.
* When the JS parser encounters a HTML comment token (<!–) in JS content, the token is treated similar to the line comment (//) and hence the rest of the line following the HTML comment token gets ignored

Look at the below JS+CSS code snippet…

<!– /*
function t(){}
<!– */
<!– body { background-color: Aqua; }

When the CSS parser parses the above content, the HTML comment tokens would be dropped and the snippet would become equivalent to the one below…

/*
function t(){}
*/
body { background-color: Aqua; }

As you can see above, the CSS parser will get to see only the CSS code and the script code would appear to be within the comments (/* … */).

In similar lines, when the JS parser parses the content, the HTML comment tokens would be treated as line comments (//) and hence the code snippet would become equivalent to the one below…

// /*
function t(){}
// */
// body { background-color: Aqua; }

As you can see above, the JS parser will get to see only the script code and the rest of the contents would look like comments.

You can refer to the above content in both the SCRIPT and LINK tags in your HTML page. For e.g.,

<link type=”text/css” rel=”stylesheet” href=”test.jscss” />
<script type=”text/javascript” language=”javascript” src=”test.jscss”></script>

Note above that both the tags refer to the same source and hence it would be downloaded once and used as appropriate (as CSS and SCRIPT).

To round it off, there is just one more thing that you need to take care of - the response content type - it needs to be set to */* in order to affirm to Firefox that the contents can be treated as anything as appropriate.

Popularity: 21% [?]

If you liked this article consider subscribing to my free rss article feed to automatically get new articles in your feed reader.

Ensure that JavaScript files or CSS files are refreshed for each new version

ASP.Net, JavaScript/Ajax, PHP, Ruby/Rails, XHTML/CSS 2 Comments »

I found a nice article explaining how to ensure that the newest version of your javascript or css is always loaded and not using old cached versions. The example shows how to accomplish this in ASP.Net but this technique can easily be applied to any server side code.

<script type=”text/JavaScript ” src=”FileName.js?v=<%=AssemblyVersionNumber()%>”>

The attribute does nothing other than trick the browser into thinking that the .js file must be retrieved from server for new version instead of cached .

Popularity: 28% [?]

If you liked this article consider subscribing to my free rss article feed to automatically get new articles in your feed reader.

CSS - Styling File Inputs With CSS And The DOM

JavaScript/Ajax, XHTML/CSS No Comments »

Shaun Inman has demonstrated in a great article how to customize file inputs. Thought to be impossible to style, Shaun proves that with a little imagination anything is possible.

We start with a simple replacement. The custom button image is set as the background-image of our wrapper element and dimensions are set to match.

Next we set the opacity of the file input itself to zero, effectively making it invisible but still clickable (something that can’t be achieved with display: none; or visibility: hidden;).

Finally, the JavaScript keeps the button portion of the the file input underneath the pointer whenever the mouse enters the wrapper element. A class of SI-FILES-STYLIZED (also configurable) is applied to the html element of the page for use as a styling context for compatible browsers.

Custom file input

Popularity: 16% [?]

If you liked this article consider subscribing to my free rss article feed to automatically get new articles in your feed reader.

CSS At An End?

XHTML/CSS No Comments »

Ajaxian.com has posted and article regarding frustrations with CSS and the slow rate of adoption by browser vendors. Some comments question the W3C’s effectiveness and the future of the Open Web.

have all been frustrated with CSS over the years. The implementation has been spotty across the browsers, and it has all but died off. IE 7 stepped up and fixed a lot, even if some weren’t happy with how far they got. CSS 3 has been out there for quite some time, but apart from Opera, other browsers have selectively implemented their pet features. Some have done interesting non-standard work too: -mypetfeature-foo-bar.

It sounds like CSS 3 as The Big Unit is basically dead, and small modules are the way forward. We should see good support for CSS 3 selectors, media queries, and who knows what else. Hopefully that new layout manager!

Popularity: 14% [?]

If you liked this article consider subscribing to my free rss article feed to automatically get new articles in your feed reader.
WP Theme & Icons by N.Design Studio
Entries RSS Login