Blue Green Brown Orange

Change Background

Posts Tagged ‘Validation’

10

January
4

How to Create a Centered UL with Blocks of LI Links

Whether you are working with a CMS or creating a static page (which is logically the step before your custom CMS theme), you are often left to ponder the best way to display a navigational menu or pagination links so that they are centered and in blocks of equal size. You’d be surprised how easy that is, this short tutorial is to get you to create a list that looks as such:

We want blocks of equal sizes, each linking to a given page (without a gap between the edge of the box and start of the link). And we want the code to be perfectly valid, of course.

First, we’ll start with the markup, which is a very basic unordered list:

<ul class="navigation">
	<li><a href="#">Item 1</a></li>
	<li><a href="#">Item 2</a></li>
	<li><a href="#">Item 3</a></li>
	<li><a href="#">Item 4</a></li>
</ul>

This alone results in a standard list with bullets and links. Now we need to add the CSS that will give us the look that we’re after:

ul.navigation{
	list-style: none;
	text-align: center;
}
ul.navigation li {
	display: inline;
	font-size: 14px;
	margin: 0 10px;
}
ul.navigation li a{
	background-color: #e5f27b;
	border: 1px solid #d9e383;
	color: #666666;
	display: inline-block;
	padding: 2px 8px;
	text-decoration: none;
	width : 75px;
}
ul.navigation li a:hover{
	background-color: #fe8a61;
	border-color: #d78466;
	color: #ffffff;
}

As you can see, it’s very straight-forward and you can easily customize it according to your needs. It’s useful for navigational menus, as well as pagination links to be displayed at the top or bottom of a given page.

24

August
0

DOCTYPEs And Validation

When developing a website it is crucial to do so in the cleanest, most standards’ compliant way. After spending sleepless nights getting your website to render properly on IE6 (which I hope will be dieing soon), the next major task on the list is to validate your CSS, as well as the markup. In most cases, having a clean, organized code that is valid goes hand-in-hand with proper browser rendering. However, before we go further, we need to know what exactly are the different DOCTYPEs, and which one we should be using.

DOCTYPE is short for Document Type Declaration and it is the very first element that appears in any web page (preceding the <HTML> tag), and it basically indicates to the browser how to look at your code. If you do not declare a DOCTYPE at the start of your document, browsers become confused and act differently. Therefore, regardless of how professional you want to go around doing this, a DOCTYPE is absolutely vital. You can read more about why you should use a DOCTYPE at the A List Apart website.

Having said that, you know need to make the decision of which of the various types are you going to stick to. The most important types are for HTML and XHTML, and on three levels: Frameset, Transitional and Strict. This is how the line of code looks like:

HTML 4.01 Frameset

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

HTML 4.01 Transitional

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

HTML 4.01 Strict

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

XHTML 1.0 Frameset

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

XHTML 1.0 Transitional

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

XHTML 1.0 Strict

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

You can see the full list of DOCTYPEs at the W3C website.

Now you need to make the choice. If you are looking to become a professional web designer, then your goal is to stick to the XHTML 1.0 Strict DOCTYPE and produce valid CSS and code. This means your code is strictly organized and the syntax is perfect. However, this might be extremely difficult to reach at your first attempt. For that reason, you may want to use the Transitional, which is the same, but far looser and will let many little “errors” slip without making a big fuss about them. In all cases, you should not use the Frameset DOCTYPEs because we have successfully embarked the 21st century, and frames are a thing of the past.

You might want to start out with the XHTML Strict DOCTYPE and see how the validation goes. If your website is online, you can use the W3C Validation Service as you work to follow the errors that come up. If it’s not online, and you are developing from your local machine (via MAMP, for example, which I had talked about), you can use the Web Developer Firefox add-on (one of several that you should be using as a web designer) and click on Tools > Validate HTML. If you are getting 500 errors, that it might be too little too late. However, if you have 200, for example, you can work to fix them all. If that’s way too much work that you don’t think is worth the time, then you can go Transitional, and the error count should be significantly reduced, to eventually give you valid Transitional code.

Why Should I Validate My Code?

In theory, a proper DOCTYPE with validated CSS and XHTML will render properly across all browsers. However, since there are “browsers” such as Internet Explorer 6, a perfectly valid code could still lead to a perfectly disfunctional website. However, it will most probably render as you would want it to on the remaining browsers in the market. Over time, the issue with validation has moved from being essential for cross-browser compatibility, to being a prestigious title that is well worth striving for.

Therefore, as a professional web designer, you should put every effort into producing validated code to ensure that it is:

  1. Future-proof: Any new browsers will properly render it
  2. Cross-browser compatible: Will require less work to show up perfectly on all of the current browsers
  3. Professional: Having the “valid CSS” and “valid XHTML” on your website are indications of the value of your work – something to be proud of

The good news is that the huge majority of frameworks and scripts that are used as the base of any website (I had previously talked about the 960 Grid System, as well as Blueprint as CSS frameworks) are developed with valid code to allow the most uptight of designers and developers to rely on them. So if you start developing your website by declaring the XHTML 1.0 Strict DOCTYPE, using the 960 GS, on your Mac using MAMP, you can use the Web Developer Firefox add-on to keep track of the validity of your code. That would hopefully result in a sleek, professional, CSS and XHTML-valid website!

2

August
1

Sharing Blog Posts With Sociable

It’s refreshing to see scores of blogs and micro-sites on the Internet that are using WordPress. Not only is it the clear leader when it comes to creating personal or professional blogs, but it has also stepped into the realm of CMS-driven websites, and is in many cases the best choice. The free, open-source web application prides itself in how powerful, yet simple, it is, and it can only become even more successful.

Suffice to say, with thousands of plugins available out there, it is not always ease to take full advantage of the features that are brought to you by the extensions developed by the WordPress community. Some users go overboard with numerous plugins that are not bringing added value, and are therefore inefficient. Meanwhile, others are missing out on the basics. When you’ve gone online with a blog, it is absolutely vital to attempt to attract the largest crowd possible, and there are various methods at hand. Besides some quality Search Engine Optimization, sitemap submissions, and permalinks (explained here), it is crucial to facilitate the way in which the website visitors can share your posts with friends and family.

Any user can simply copy the URL and past it in an IM chat or email. But let’s not kid ourselves: users of the Web are lazy, and that’s not going to change anytime soon. If it’s not sorted out in two clicks, at most, then no one will be bothered. For that reason, you’d be crazy to skip integrating a plugin that allows users to share your posts via social network websites and the likes. There are a handful of post-sharing plugins out there, the most prominent of which, is Sociable.

By installing and activating Sociable, you will have automatically placed a row of icons at the end of each post that makes the visitor a click away from publishing a link to your post from sites such as Twitter, Facebook, Technorati, Digg and many more. In fact, the complete list of websites available boasts over 60 options:

Sociable Options

Sociable Options

Using the settings page integrated into the WordPress administrative menu, you can configure which ones you would like to appear, and in what order. Moreover, you can opt to place your own icons, as oppose to the standard ones that ship with the plugin. It is as simple as creating a directory, placing the icons in the proper names (follow the standard set by the original icons pack), and enter the URL to the image folder via the settings page. With a wealth of options within reach on all corners of the internet, even if you are not willing to design your own icons, you can download any of the free packs available with an appropriate license.

As a result, any user who finds your post of interest, can easily choose his or her website/service of choice, and spread the word. The downside of the Sociable plugin is a bizarre problem, with a very easy fix.

XHTML Validation

A recent update to the plugin changed the classes associated with each icon displayed to an id. That is plain blasphemy as it means that on the main posts’ page, for example, a given id is repeated ten times (once with each post), which causes the XHTML validation to go out the window. You might’ve spent endless hours and sleepless nights on end to get your website to validate correctly, and with a simple plugin such as Sociable, all your efforts will have gone down the toilet. Interestingly, the plugin originally used classes, and then switched to ids, and then there have been two more updates since, but the plugin remained XHTML invalid!

Not to worry, though, the solution is very simple:

  1. From the WordPress control panel menu, click on “Plugins”
  2. Find the Sociable plugin, and click “edit” underneath
  3. Choose the file sociable.php, and scroll down to the following segment:
    /**
     * Start building the link, nofollow it to make sure Search engines don't follow it,
     * and optionally add target=_blank to open in a new window if that option is set in the
     * backend.
     */
     $link .= '&lt;a rel=&quot;nofollow&quot;';
     $link .= ' id=&quot;'.esc_attr(strtolower($sitename)).'&quot;';
     if (get_option('sociable_usetargetblank')) {
     $link .= &quot; target=\&quot;_blank\&quot;&quot;;
     }
     $link .= &quot; href=\&quot;javascript:window.location='&quot;.urlencode($url).&quot;';\&quot; title=\&quot;$description\&quot;&gt;&quot;;
    

    And replace the “id” with “class” as such:

    /**
     * Start building the link, nofollow it to make sure Search engines don't follow it,
     * and optionally add target=_blank to open in a new window if that option is set in the
     * backend.
     */
     $link .= '&lt;a rel=&quot;nofollow&quot;';
     $link .= ' class=&quot;'.esc_attr(strtolower($sitename)).'&quot;';
     if (get_option('sociable_usetargetblank')) {
     $link .= &quot; target=\&quot;_blank\&quot;&quot;;
     }
     $link .= &quot; href=\&quot;javascript:window.location='&quot;.urlencode($url).&quot;';\&quot; title=\&quot;$description\&quot;&gt;&quot;;
    
  4. From the settings page, uncheck the “use Sociable stylesheet” and use your own classes to make the icons look the way you want. Or you can simply dig into the sociable.css file and change the “#” of the links’ names to “.” in order to turn them into classes and not ids. However, it is recommended to add the CSS classes to the stylesheet you are already using in order to assure that the icons integrates seamlessly into your design

Remember that after a plugin update, if the author has not fixed the problem himself, you would needt to make the change again. Even though it might seem like a bit of a hassle, the “fix” is done in a couple of minutes, and is well worth the effort. Providing users with the ability to share your posts is an absolute must, and Sociable is by far one of the best plugins to do so.