<?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>Carpe Jugular Webmaster Resource &#187; HTML and CSS</title>
	<atom:link href="http://carpejugular.com/category/html-css/feed/" rel="self" type="application/rss+xml" />
	<link>http://carpejugular.com</link>
	<description>Articles about Wordpress, CSS and issues that concern commercial webmasters</description>
	<lastBuildDate>Sat, 19 May 2007 11:34:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>CSS Basic Page Structure</title>
		<link>http://carpejugular.com/css-basic-page-structure/</link>
		<comments>http://carpejugular.com/css-basic-page-structure/#comments</comments>
		<pubDate>Sat, 05 May 2007 22:50:11 +0000</pubDate>
		<dc:creator>John Foulds</dc:creator>
				<category><![CDATA[HTML and CSS]]></category>
<category>css basics</category><category>doctypes</category><category>page structure</category>
		<guid isPermaLink="false">http://carpejugular.com/css-basic-page-structure/</guid>
		<description><![CDATA[CSS separates content from design making your sites easier to maintain, faster loading and more search-engine friendly. And if you build basic templates for the layouts you commonly use, just open one up for every new page or site and part of your work is already done.

Certainly using CSS means learning some new code and looking at coding in a slightly different way. But instead of continuing to build sites using outdated code, a little time invested now will save you a lot later.]]></description>
			<content:encoded><![CDATA[<p>The concept of separating content from layout instructions was developed by document storage specialists decades before CSS came along. It is a logical concept which works best if approached logically. In the case of site design, that surely begins with basic page structure.</p>
<p>The first step towards having CSS behave predictably is to include a valid <strong>doctype</strong> and <strong>HTML</strong> tag as the first two lines of your HTML. A longer list of all the options is offered by <a href="http://www.w3.org/QA/2002/04/valid-dtd-list.html">W3C</a>, but the most common are:<br />
<pre class="tutor wide">
If you are coding in HTML:
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
...

If you are coding in XHTML:
&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"&gt;
...
</pre><br />
If you don&#8217;t use a <strong>doctype</strong>, use one which is incomplete or doesn&#8217;t match the rest of your code, browsers drop into what is know as <strong>&#8220;quirks mode&#8221;</strong> which means they assume you have written very old code. They will ignore recent additions to CSS and interpret others wrongly. This can totally destroy your layout.</p>
<p>A major pitfall when using CSS is the unwillingness of browser developers to adopt a consistent standard. There are solutions (hacks) to almost all these inconsistencies, but it is easier to avoid them where possible. To this end I recommend beginning every CSS file with some parameters for the whole page.<br />
<pre class="tutor narrow">
body {
	margin: 0;
	padding: 0;
	}
</pre><br />
These two properties define the space around the outside of an element (margin) and the space inside an element (padding). If we seem to be leaving logic behind already, think of the screen as the master container and the body (your HTML) as an element within it. It is necessary to set the padding to zero to counter the default padding set by Opera.</p>
<p>If you do want space around your design, just change the values for <strong>margin</strong>. You can either set a single value to be applied on all sides:<br />
<pre class="tutor narrow">
body {
	margin: 10px;
	padding: 0;
	}
</pre><br />
or different values for top, bottom and each side:<br />
<pre class="tutor narrow">
body {
	/* top, right, bottom, left */
	margin: 20px 50px 20px 50px;
	padding: 0;
	}
</pre></p>
<h2 class="tutor">Single Columns</h2>
<p>It isn&#8217;t necessary to create an overall division to contain the rest of your page, if the whole page is a single column. Nevertheless, something like this means you establish parameters for your page which don&#8217;t then need to be repeated several times:<br />
<pre class="tutor narrow">
/* in your CSS file */
#wrapper {
	width: 780px;
	/* "auto" will center the block */
	margin: 0 auto 0 auto;
	padding: 20px;
	}
	
	
/* your HTML */
&lt;div id="wrapper"&gt;
	All your content goes here
&lt;/div&gt;
</pre><br />
You can leave out the <strong>margin</strong> parameter if you want your content to show against the left of the screen. The <strong>padding</strong> parameter is also optional and of course the actual dimensions are up to you. Padding may not be useful if your content will appear on your overall background color, but if they are not the same, you probably would not want your content hard up against the edges of that center block:</p>
<p><img src="http://carpejugular.com/files/article00201.gif" width="500" height="164" alt="" /></p>
<h2 class="tutor">Double Columns</h2>
<p>I am going to use a double column layout to illustrate a complete typical page structure of header, content and footer:</p>
<p><img src="http://carpejugular.com/files/article00202.gif" width="500" height="266" alt="" /></p>
<p><pre class="tutor wide">
&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"&gt;
&lt;head&gt;

&lt;style type="text/css"&gt;
/*global settings */
body {
	margin: 0;
	padding: 0;
	}
	
/* basic structure */
#wrapper {
	width: 780px;
	margin: 0 auto;
	}
#header {
	}
#content {
	}
.left {
	float: left;
	width: 350px;
	}
.right {
	float: right;
	width: 350px;
	}
#footer {
	clear: both;
	}
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;div id="wrapper"&gt;

	&lt;div id="header"&gt;
		HEADER
	&lt;/div&gt;

	&lt;div id="content"&gt;
		&lt;div class="left"&gt;LEFT COLUMN&lt;/div&gt;
		&lt;div class="right"&gt;RIGHT COLUMN&lt;/div&gt;
	&lt;/div&gt;

	&lt;div id="footer"&gt;
		FOOTER
	&lt;/div&gt;

&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
Although we haven&#8217;t applied any styling yet to the header or content blocks, it makes sense to provide place-holders, since we have created the blocks in HTML. Making the total width of the left and right columns (350+350=700) less than the width of our &#8220;master&#8221; block (780-20-20=740), creates the space between the two columns. Note that otherwise no widths have been specified and 100% is implied by default. The <strong>float</strong> parameter, is what tells each block to place itself to the left or the right.</p>
<p>We haven&#8217;t styled the footer block but we did need to include <strong>clear: both</strong>. Without that parameter, the block would locate itself as high up the screen as possible, which in this case would be between the left and right blocks. Always include <strong>clear: both</strong> in a block which follows multiple to tell browsers to create it below the longest of the blocks above.</p>
<p>That covers basic page layout for one- and two-column designs. Three-column layouts are  slightly more tricky, so I shall cover them separately.</p>
<blockquote>HINT: It is a big timesaver to store code similar to that above as templates for all the basic layouts you commonly use: simply open a file and your page is already part made. I include a little more than shown above &#8211; basic fonts, header sizes, link treatment, etc &#8211; but only such elements as are always, or almost always used. Indenting code (and I usually leave an empty line between blocks) makes the flow of the code easier to follow, and if you indent every new block and close indents at the end, you will soon see (when your final block close instruction is away from the left of the screen) if you forgot to close a block along the way. Give ID&#8217;s and classes descriptive names so that your style file doesn&#8217;t become gibberish. Finally, always comment anything in your HTML or CSS which needed special treatment or might otherwise catch you out if you don&#8217;t look at the file(s) again for a year.</blockquote>
<h2 class="tutor">Update</h2>
<p>At the beginning of this article, I mentioned the value of including parameters in a style sheet to account for the differences between browser defaults. For those who are more familiar with the issues involved, here is the set of instructions which I use myself. It pretty much over-rides all the default styling in all the major browsers, leaving you to start with a clean sheet, as it were:</p>
<pre>
/* clear browser defaults */
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{margin:0;padding:0;}
abbr,acronym,fieldset,img{border:0;}
address,caption,cite,code,dfn,h1,h2,h3,h4,h5,h6,th,var{font-size:100%;font-style:normal;font-weight:normal;}
caption,th{text-align:left;}
div{overflow:hidden;}
h1,h2,h3,h4,li{white-space:nowrap;overflow:hidden;}
ol,ul{list-style:none;}
/* global hacks */
body{text-align:center;}
</pre>]]></content:encoded>
			<wfw:commentRss>http://carpejugular.com/css-basic-page-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TGP Makeover</title>
		<link>http://carpejugular.com/tgp-makeover/</link>
		<comments>http://carpejugular.com/tgp-makeover/#comments</comments>
		<pubDate>Fri, 20 Apr 2007 16:26:24 +0000</pubDate>
		<dc:creator>John Foulds</dc:creator>
				<category><![CDATA[HTML and CSS]]></category>
<category>tgp</category><category>thumb preview</category><category>xhtml</category>
		<guid isPermaLink="false">http://carpejugular.com/tgp-makeover/</guid>
		<description><![CDATA[Using tables to code text-based TGP's undermines a lot of the SEO potential edge these otherwise content-rich sites might have, by leaving them with a high code to content ratio. And if a little clever CSS isn't used, they can also suffer from that familiar lag before the whole page pops into view. The advantages of going table-free are not as great for thumb-preview TGP's, but as this article shows, the code for even a simple site can be reduced by 25%.]]></description>
			<content:encoded><![CDATA[<p>This exercise illustrates how to approach the job of converting a typical thumb-preview TGP page into table-less XHTML with all the styling being done in CSS. <a href="http://www.carpejugular.com/files/original.html" target="_blank">The original</a> (this is just a sample including the main elements only once) is coded in HTML, uses tables and some CSS and this is <a href="http://www.carpejugular.com/files/revised.html" target="_blank">the end product</a>. Compare the source code from these two links, just note that to make this exercise easier to follow, the styles are included in the documents. In use they might be stored separately and referenced by <strong>&lt;link rel=&#8221;stylesheet&#8221; href=&#8221;/path_to/style.css&#8221; type=&#8221;text/css&#8221; media=&#8221;screen&#8221; /&gt;</strong>.</p>
<p>The first step in a &#8220;makeover&#8221; like this should be to validate the document in its present form. This one had only a few errors:
<ol>
<li>Two title tags.</li>
<li>Character-set meta tag appears twice.</li>
<li>The header image has no alt tag.</li>
<li>In the full version of the original, a div id (largelinks) was used multiple times. <strong>ID&#8217;s must be unique</strong>: use &#8220;class&#8221; where a style is going to be repeated.</li>
</ol></p>
<p>Although not directly related to this exercise, I changed the document&#8217;s character set to <strong>UTF-8</strong> (Unicode). I don&#8217;t want to go off at a lengthy tangent (you can read more about Unicode <a href="http://en.wikipedia.org/wiki/Unicode">here</a>), enough to say that ASCII, Latin 1 (ISO 8859-1), etc., are deprecated these days. Use this instead (note the space and oblique used to close the tag):
<pre class="tutor wide">
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
</pre></p>
<p>Another change I made not directly related to the main point of this exercise, was to remove the bookmark javascript script into its own file, because it is search engine friendly to keep your head section to a minimum. That is one reason for creating a separate stylesheet file, the other being that if it is read in separately, the file will be cached, which makes subsequent pages of multipage sites load faster.</p>
<p>The value of converting to XHTML as part of a makeover is debatable. XHTML fans argue that you are future-proofing your work and since CSS behaves slightly differently, why be forced to learn these differences later and perhaps have to change some of your code? My view is that several scripts these days (notably blogs) default to XHTML, thus whatever the future may hold, it is easier to tackle a single HTML/CSS combo for everything. Fortunately, very few coding changes are required for XHTML:
<ol>
<li>Change your doctype and html tag to:
<pre>
&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"&gt;
</pre>
Here is an <a href="http://alistapart.com/stories/doctype/">in-depth discussion of doctypes</a>.</li>
<li>All tags must be in lower case. I changed the case of the keyword and description metas and also applied the space+oblique to close the tags properly (compare the two source codes). I also had to convert the p (paragraph) tags to lower case.</li>
<li>The target tag in the head must also be closed with space+oblique (be aware this tag works but is not part of the XHTML convention).</li>
<li>Search and replace all &lt;br&gt; tags making them &lt;br /&gt;.</li>
<li>Change all image tags to end with that space+oblique.</li>
<li>All dimensions and tag parameters must be enclosed in quotation marks.</li>
<li>Although some HTML editors allow it, putting actual symbols (such as the copyright mark) into your code is a no-no because they may not display correctly (the copyright symbol of the original showed as a question mark in my browser). Use entities instead such as <strong>&#38;&#35;38;</strong> for ampersand: this page at <a href="http://www.pemberley.com/janeinfo/latin1tb.html">Pemberley</a> includes an entity table.</li>
</ol></p>
<p>Now the CSS. Here is the new file with comments:
<pre class="tutor wide">
/* 18sweeties */
/* There may be nothing in a style file to remind you to what it
belongs, so give it a title */

/* Some will tell you to lay out your CSS file strictly separating structure and fonts/colors. That can be very confusing for CSS novices, so here I have placed the page-wide parameters first and the rest in page order */

/* globals */
body {
	/* for cross-browser compatibility always state the overall margin */
	margin: 0; 
	 /* include MAC fonts */
	font: 16px Verdana, Geneva, Arial, Helvetica, sans-serif;
	background: #fffee8;
	color: #000; /* set a font color to be safe */
	}
img {
	/* use this and you don't need border="0" in any of your image tags */
	border: 0; 
	}
a {
	font-weight: bold;
	/* when colors are represented by 3 pairs, 0000ff, they can be shortened */
	color: #00f;
	text-decoration: underline;
	}
a:hover {
	/* it is not necessary to repeat parameters which will be inherited so only a color change is needed here*/
	color: #5454ff; 
	}
	
/* I always include this fix for a problem Explorer has with short divs. It is sometimes necessary to name the div, but this avoids that a lot of the time and if it isn't needed, (usually) doesn't hurt */
* html div {
	height: 1%;
	}
	
/* in page order for ease */
/* div align=center was used in the original document but is not compliant with current standards so this div was used instead */
#header {
	/* 17px represents top/bottom and auto left/right. There is no need to specify all four measurements when the pairs are the same */
	margin: 17px auto;
	text-align: center;
	}
.wrapper {
	width: 769px;
	margin: 0 auto;
	/* no need to specify left, top, etc borders when all are the same */
	border: #c103ff 2px solid; 
	background: #f9e6ff;
	}
/* check out the source code: all that was needed to replace the table holding the thumbs was a width-restricted container (wrapper, above) and a margin around the images */
.thumbtable img {
	/* replaces the cell-padding used in the original file */
	margin: 2px; 
	/* placing image dimensions here means no need to include them in HTML */
	width: 120px;
	height: 160px;
	}
/* when different style class have the same parameters, save code by combining them in a comma-separated list */
a:link img, a:visited img { 
	border: #cc0033 2px solid;
	}
a:hover img, a:active img {
	border: #cc0033 2px dashed;
	}
/* technically we could have given a class to the paragraph tag used originally but using a div here is more semantically correct */
.bookmark { 
	margin: 15px auto;
	text-align: center;
	}
.largelinks {
	font: 16px Arial, Helverica, sans-serif;
	font-weight: bold;
	letter-spacing: -1px;
	}
.largelinks a {
	font-size: 24px;
	color: #ed145b;
	line-height: 28px;
	}
.largelinks a:hover {
	color: #00497e
	}
/* lists such as trade links need not be displayed vertically and can be given specific widths */
ul.largelinks {
  	width: 769px;
  	margin: 15px auto;
  	padding: 0;
	list-style: none;
	}
ul.largelinks li {
  	float: left;
  	width: 33%;
  	margin: 0;
  	padding: 0;
	text-align: center;
	}
/* these next lines cleaned up a mix of paragraph tags and spaces */
/* after multiple columns, in this case the inline list displaying trade links you must tell browsers when you want to begin a new block or they will try to create an extra column */
#footer {
	clear: both; /* that is what this line does */
	text-align: center;
	padding: 50px 0;
	}
/* Mozilla browsers and Explorer do not handle "clear" the same way, so we end up with more space than we want in Explorer. The following instruction which can only be read by Explorer and is ignored by Firefox etc., corrects that */
*html #footer {
	padding: 35px 0;
	}
#footer img {
	margin-top: 50px;
	}
</pre></p>
<p>The result looks the same in both Explorer and Firefox and just as it did originally. The combined size of the HTML and (uncommented) CSS for the revised version is 5.01KB compared to 6.54KB for the same section in its original form. That is <strong>almost a 25% saving</strong>, providing obvious speed and bandwidth benefits. Perhaps more importantly, had this been a text-based site, the content to code ratio would have improved dramatically, giving a distinct edge with the search engines.</p>]]></content:encoded>
			<wfw:commentRss>http://carpejugular.com/tgp-makeover/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Troubleshooting CSS</title>
		<link>http://carpejugular.com/troubleshooting-css/</link>
		<comments>http://carpejugular.com/troubleshooting-css/#comments</comments>
		<pubDate>Sat, 14 Apr 2007 12:48:58 +0000</pubDate>
		<dc:creator>John Foulds</dc:creator>
				<category><![CDATA[HTML and CSS]]></category>
<category>trouble shooting</category><category>validate</category><category>validation services</category>
		<guid isPermaLink="false">http://carpejugular.com/troubleshooting-css/</guid>
		<description><![CDATA[Even experienced CSS coders will face a page which doesn't come out looking as it was supposed to. More often, a page will look fine in one browser but not another. Whether writing HTML and CSS or debugging them, a methodical approach and attention to a few guidelines will make your life a lot easier.]]></description>
			<content:encoded><![CDATA[<p>If you are fairly new to CSS (and sometimes even when you are experienced) you are going to be faced with a page which just doesn&#8217;t look the way that you expected. Or perhaps it looks fine in one browser but not in another. Certain things are handled differently by the various browsers, but don&#8217;t be in too much of a hurry to assume that is what is going on: there really are not too many areas which require &#8220;hacks&#8221;. As in building a page, a methodical approach is what you need for problem solving whenever the answer isn&#8217;t immediately obvious.</p>
<ul class="tutor">
<li>Validate your <a href="http://validator.w3.org/">HTML</a> and your <a href="http://jigsaw.w3.org/css-validator/">CSS</a>. These validation services may spot your problem(s) for you, but in any case, attempting to solve visible problems will be much harder if hidden problems exist.</li>
<li>You may not see the results of changes (because of cacheing), so while troubleshooting, revert to placing your CSS in the &lt;head&gt; section of your page. Just be sure to remember to creare an external style sheet again once your problems are resolved.</li>
<li>Always troubleshoot (and test while building) with an advanced/compliant browser such as FireFox. It is far easier to hack, if necessary, to make CSS work for Explorer than to fix your broken code for a broken browser and then almost certainly have problems as soon as you do test in other browsers.</li>
<li>Give all your main structural elements (different) colored backgrounds, to help you spot gaps, overlaps, and just plain wrong positioning. If you still have problems, give apply colored backgrounds to all the elements in the problem area(s) and look for stray padding or margins.</li>
<li>Make sure you aren&#8217;t including images or unbroken text which is wider than the block within which it/they appear/s.</li>
<li>Don&#8217;t assume the problem is related to the code in the area where the problem seems to be on-screen. Comment out half your style-sheet at a time (/* at the beginning, */ at the end) to isolate which half is causing the problem. Then within the problem half, comment out sections of the styling until you isolate which is/are the culprits.</li>
<li>If a troublesome element includes something like margins or padding, apply some really big values, to be sure they are being picked up at all.</li>
<li>Browsers can do strange things with measurements, so try reducing your widths. Instead of columns totalling 100% of the available width, reduce one or more so they total only 99% or even 98%.</li>
<li>Identify a block around the troubled area which itself appears to be behaving and comment out (in your HTML) all the child elements within it. Then uncomment them one at a time until the problem reappears.</li>
<li>Add <strong>margin: 0;</strong> to all the elements in the troubled area. If that fixes the problem and you want to clean up your code, remove the new settings one at a time, watching for the error to return. That/those you do not want to remove!</li>
</ul>
<h2 class="tutor">Avoid trouble!</h2>
<p>I know we think, read and write linearly, but if you want to avoid unnecessary troubleshooting headaches, don&#8217;t code your pages that way.</p>
<ul class="tutor">
<li>Begin by coding the broad structure of your page (using colored backgrounds). Test. Then add the detailed but still only structural elements. If you need some text to identify or stretch an element, add just a few lines that emulate the real content: do not fill your page with content at this point, because it just obscures the details you need to see during debugging.</li>
<li>As noted above, always test first in a standards-aware browser and when everything is okay, then add any hacks needed to accomodate Explorer. But if you can code in a way which minimises the need for hacks, so much the better.</li>
<li>Be careful when pasting a block of code from one file to another. Saving snippets of code which you use frequently can be a great timesaver, but if they can be acted upon by something else on the page, they can be a source of problems.</li>
<li>Some hacks use javascript. Check what your page will look like to visitors who do not have javascript enabled.</li>
<li><strong>Floats</strong> can be a thorough pain in the *ss. If your floats are showing up in the wrong place, margins haywire or the content within is doing strange things, the answer might be <a href="http://www.tizag.com/cssT/float.php">here</a>.</li>
<li>Margins, in particular bottom margins, simply vanish. If you cannot apply a border (which resolves this problem) padding might be a better option.</li>
<li>BUT unless you are willing to do some math and apply hacks, avoid borders and padding with fixed-width elements, because Explorer really screws up the way that combination is handled. There are <a href="http://www.thenoodleincident.com/tutorials/box_lesson/boxes.html">workarounds</a>. It is almost always better to add padding to parent elements than to child elements.</li>
<li>Never include code you don&#8217;t really need.</li>
<li>Set element margins to 0 (unless specific values are needed) to allow for browser differences.</li>
<li>Zero values and line-heights do not need units of measurement, otherwise all none-zero values must be qualified by %, em, px, or pt.</li>
<li>Browsers are case-sensitive, so if you refer to a class as left<strong>c</strong>ol in HTML it must not be left<strong>C</strong>ol in CSS.</li>
<li>If you are using floats and want to avoid your content sometimes disappearing entirely or formatting unpredictably in Explorer, you should read up on <a href="http://www.communitymx.com/content/article.cfm?page=2&#038;cid=C37E0">The Peekaboo and Escaping Floats bugs</a>.</li>
<li>Be aware there are (mainly Explorer-specific) extensions which don&#8217;t work at all in other browsers (validation normally points these up).</li>
<li><strong>TEST every step of the way</strong>: it is far easier than trying to isolate problems in a complete page.</li>
</ul>
<blockquote><h2 class="tutor">Why Validate?</h2>
<p>Checking your HTML and CSS is a lot like spell-checking a letter or email. The difference is that as long as your pages look okay, you may be the only person who knows whether your code is valid or not. You are certainly likely to be the only person who cares.</p>
<p>You could argue that writing invalid code is like a mechanic not tightening a nut to the correct torque. Either you do a fully professional job or you do not. There are occasions when it is necessary to deliberately write invalid code &#8211; for example to workaround browser incompatibilities &#8211; but that is not the same as simply making mistakes. From the purely practical point of view, although many mistakes will stay harmless, some have the potential, when combined with something you may add to your page later, to break the page. It also seems illogical to complain about lack of common standards and then ignore the standards which exist.</p>
</blockquote>]]></content:encoded>
			<wfw:commentRss>http://carpejugular.com/troubleshooting-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Boxes</title>
		<link>http://carpejugular.com/css-boxes/</link>
		<comments>http://carpejugular.com/css-boxes/#comments</comments>
		<pubDate>Tue, 03 Apr 2007 04:16:35 +0000</pubDate>
		<dc:creator>John Foulds</dc:creator>
				<category><![CDATA[HTML and CSS]]></category>
<category>css basics</category><category>float</category><category>padding</category>
		<guid isPermaLink="false">http://carpejugular.com/css-boxes/</guid>
		<description><![CDATA[Incompatibilities in the way that different browsers render the same code are infamous and sometimes quite dramatic. Here one such is illustrated... and solved.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s some simple CSS and HTML, just a square box with some padding to keep the text away from the edge, a border for decoration, and then a margin to space it from the box next-door.</p>
<pre class="tutor">
&lt;style>
#example {
	float: left;
	width: 200px;
	height: 200px;
	background: #F00;
	border: 10px solid #FF0;
	padding: 20px;
	margin: 30px;
	}
html>body #example {
	width: 140px;
	height: 140px;
	}
#next {
	float: left;
	width: 200px;
	height: 200px;
	background: #00F;
	border: 1px solid #FF0;
	margin: 30px 0;
	}
&lt;/style&gt;
&lt;div id="example"&gt;
	top left
&lt;/div&gt;
&lt;div id="next"&gt;next&lt;/div&gt;
</pre>
<p>But look at these two illustrations. The top pair shows how IE6 interprets the code and the lower one how Firefox sees it.</p>
<p><img src="http://carpejugular.com/files/article01401.gif" width="430" height="200" alt="" /></p>
<p><img src="http://carpejugular.com/files/article01402.gif" width="490" height="260" alt="" /></p>
<p>Both handle the margin correctly, leaving 30 pixels between the two boxes. The difference is that Mozilla browsers ADD the padding and border to the height and width of the box, while Explorer INCLUDES their dimensions within the height and width settings. Thus the box which Explorer shows 200 pixels square displays as 260 pixels square in Firefox (200px + 20px*2 padding + 10px*2 border = 260px).</p>
<p>The solution is to place this piece of code, which is in a format Explorer cannot read but Mozilla browsers can, after the CSS for #example, thus:</p>
<pre class="tutor">
html>body #example {
	width: 140px; /* desired width - 2*padding - 2*border */
	height: 140px;
	}
</pre>
<p>Et voil&#224;, the boxes now appear the same in both browsers. This bit of hackery will come in useful whenever such differences rear their heads.</p>
<blockquote>
<h2 class="tutor">Update</h2>
<p>The purpose of this article was to explain something you might experience and to provide a direct workaround. It is a better plan to avoid such problems in the first place:</p>
<ul>
	<li>For vertical spacing, <em>margin-top</em> performs fairly consistently but <em>margin-bottom</em> less so, since margins underneath blocks may be collapsed into the margin above the following block. You will suffer less grief if you try to stick with margin-top or with padding.</li>
	<li>IE6 does several strange things when you combine floats with margins. Try to use widths and float directions in a way which makes it possible to avoid margins. For example, if two columns 500 pixels and 200 pixels wide are floated left and right within a 720 pixel block, a 20 pixel space will be created between them with no need for a margin declaration.</li>
	<li>Although it involves a little more thought and typing, nested blocks often make for more certain cross-browser compatibility. A block 400 pixels wide, given a margin of 20 pixels and set inside an outer block of 440 pixels, will appear as you intend in any browser, more reliably than giving the 440 pixel block padding of 20 pixels.</li>
</ul>
</blockquote>]]></content:encoded>
			<wfw:commentRss>http://carpejugular.com/css-boxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Image Alignment</title>
		<link>http://carpejugular.com/image-alignment/</link>
		<comments>http://carpejugular.com/image-alignment/#comments</comments>
		<pubDate>Sat, 31 Mar 2007 02:33:36 +0000</pubDate>
		<dc:creator>John Foulds</dc:creator>
				<category><![CDATA[HTML and CSS]]></category>
<category>cross browser compatibility</category><category>float</category><category>overflow</category>
		<guid isPermaLink="false">http://carpejugular.com/image-alignment/</guid>
		<description><![CDATA[Default image positioning in WordPress is left aligned with text following in a new paragraph underneath. Of course this is not the only option, but there are some cross-browser pitfalls lurking for those who seek to be more adventurous.]]></description>
			<content:encoded><![CDATA[<p>By default, images in WordPress posts are justified left, with text following (in a new paragraph) underneath. Which is fine a lot of the time, but obviously there are occasions when you would like to center an image, perhaps with text underneath, wrap text around the image or do that together with aligning the image to the right.</p>
<p><img src="http://carpejugular.com/files/article01501.jpg" width="500" height="643" alt="" /></p>
<p>No problem, the HTML and CSS for all these requirements are quite simple:</p>
<pre>
HTML:
&lt;div class="centered"&gt;&lt;img src="http://carpejugular.com/files/pendle.jpg" width="230" height="167" alt="" /&gt;Pendle Hill&lt;/div&gt;
&lt;div class="alignright"&gt;&lt;img src="http://carpejugular.com/files/pendle.jpg" width="230" height="167" alt="" /&gt;Pendle Hill&lt;/div&gt;
&lt;div class="alignleft"&gt;&lt;img src="http://carpejugular.com/files/pendle.jpg" width="230" height="167" alt="" /&gt;Pendle Hill&lt;/div&gt;

CSS:
.centered {
	text-align: center;
	}
.centered img {
	display: block;
	margin: 0 auto 5px auto;
	}
.alignright img {
	padding: 4px;
	margin: 0 0 2px 7px;
	display: inline;
	float: right;
	}
.alignleft img {
	padding: 4px;
	margin: 0 7px 2px 0;
	display: inline;
	float: left;
	}
</pre>
<p>Unfortunately, the illustration showing how well this all works only applies to Explorer. The result in Mozilla browsers, such as Firefox and Netscape, is somewhat different:</p>
<p><img src="http://carpejugular.com/files/article01502.jpg" width="500" height="590" alt="" /></p>
<p>This mess happens because floated entities (see float:left; &#38; float:right; in the CSS code) are supposed to be able to expand beyond their container. They are, after all, &#8220;floating&#8221;, ie not tethered to a container. Although the result in this instance looks horrible in fully-compliant browsers, such browsers are actually handling the parameter correctly.</p>	
<p>All very interesting, but right now we want to know how to block this behaviour, and fortunately someone discovered this hack. Just add this code to the CSS above, and Mozilla browsers will show the same as Explorer:</p>
<pre>
.alignright:after, .alignleft:after {
	content: ".";
	display: block;
	line-height: 1px;
	font-size: 1px;
	clear: both;
	}
</pre>
<p>BTW I have added borders here to clarify the illustration, but they are not necessary to the structure, therefore I have omitted their codes to keep the example clean.</p>
<blockquote>
<h2 class="tutor">Update</h2>
<p>Whenever you float blocks alongside each other, within a holding block, the problem illustrated above is likely to occur. Sometimes it is enough to add a <em>clear:both;</em> to the styling of the next block, but a consistent approach more quickly becomes instinctive.</p>
<pre>
/* add this to every css file that you use */
.clearfix:after,.clear{content:".";display:block;height:0;line-height:0;clear:both;visibility:hidden;}

Now you have two options which will always be available without further preparation:

&lt;div class="holder clearfix"&gt;
	&lt;div class="left-float"&gt;content&lt;/div&gt;
	&lt;div class="right-float"&gt;content&lt;/div&gt;
&lt;/div&gt;

or

&lt;div class="holder"&gt;
	&lt;div class="left-float"&gt;content&lt;/div&gt;
	&lt;div class="right-float"&gt;content&lt;/div&gt;
	&lt;div class="clear"&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://carpejugular.com/image-alignment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS and the Humble List</title>
		<link>http://carpejugular.com/humble-list/</link>
		<comments>http://carpejugular.com/humble-list/#comments</comments>
		<pubDate>Tue, 27 Mar 2007 17:14:36 +0000</pubDate>
		<dc:creator>John Foulds</dc:creator>
				<category><![CDATA[HTML and CSS]]></category>
<category>css basics</category><category>lists</category><category>list items</category>
		<guid isPermaLink="false">http://carpejugular.com/humble-list/</guid>
		<description><![CDATA[The humble list offers a rich variety of options for CSS-savvy webmasters and as much as any HTML element, illustrates the potential power of CSS. This article touches on just a few of those options to suggest directions for further experimentation.]]></description>
			<content:encoded><![CDATA[<p>We are all familiar with standard ordered and unordered lists:</p>
<p><img src="http://carpejugular.com/files/article01601.gif" alt="" width="88" height="130" /></p>
<p>But there is a whole lot more which can be done with them. For example, if you want to replace the regular symbols with an image, you can get much more consistent and controllable results by using a background image than with list-style-image:</p>
<p><img src="http://carpejugular.com/files/article01602.gif" alt="" width="79" height="56" /></p>
<pre class="tutor">
CSS:
.navlist {
	margin-left: 0;
	padding-left: 0;
	list-style: none;
}
.navlist li {
	padding-left: 16px;
	background: url(files/redarrow.png) left center no-repeat;
}

HTML:
&lt;ul class="navlist"&gt;
&lt;li&gt;&lt;a href="#"&gt;Item one&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#"&gt;Item two&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#"&gt;Item three&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>But with the exact same HTML, we could also produce these three-dimensional rollover buttons:</p>
<p><img src="http://carpejugular.com/files/article01603.gif" alt="" width="190" height="94" /></p>
<pre class="tutor">
.navlist {
	background: #732BB0;
	padding: 2px 4px;
	margin: 0;
	width: 180px;
	font: 12px Verdana, sans-serif;
	}
.navlist li {
	list-style: none;
	margin: 0;
	}
.navlist a {
	display: block;
	color: #FFF;
	text-decoration: none;
	margin: 4px 0;
	background: #CC3399;
	border-width: 1px 1px 1px 8px;
	border-style: solid;
	border-color: #E085C2 #732BB0 #732BB0 #AFCE26;
	padding: 4px 6px 4px 12px;
	/* for IE */
	width: 99%;
	}
html>body .navlist a {
	/* hack for Mozilla browsers */
	width: auto;
	}
.navlist a:active, .navlist a:hover {
	background: #A4297B;
	border-color: #732BB0 #E085C2 #E085C2 #AFCE26;
	}
</pre>
<p>Another change of CSS, but still the same HTML, and instead of vertical navigation, we have horizontal:</p>
<p><img src="http://carpejugular.com/files/article01604.gif" alt="" width="233" height="26" /></p>
<pre class="tutor">
.navlist {
	margin: 0;
	padding: 0;
	font: 12px Verdana, sans-serif;
.	}
.navlist li {
	display: inline;
	list-style: none;
	margin: 0;
	}
.navlist a {
	color: #FFF;
	text-decoration: none;
	margin: 4px 0;
	background: #CC3399;
	border-width: 1px;
	border-style: solid;
	border-color: #E085C2 #732BB0 #732BB0 #E085C2;
	padding: 4px 6px;
	}
.navlist a:active, .navlist a:hover {
	background: #A4297B;
	border-color: #732BB0 #E085C2 #E085C2 #732BB0;
	}
</pre>
<p>To turn this into a full-width navigation bar, does require a small HTML change, namely, wrapping the list into a div, plus a few more CSS changes:</p>
<p><img src="http://carpejugular.com/files/article01605.gif" alt="" width="500" height="35" /></p>
<pre class="tutor">
CSS:
.navlist {
	margin: 0;
	padding: 10px 4px;
	font: 12px Verdana, sans-serif;
	width: 100%;
	background: #732BB0;
	}
.navlist ul {
	margin: 0;
	padding: 0;
	}
.navlist ul li {
	display: inline;
	list-style: none;
	margin: 0;
	}
.navlist ul li a {
	color: #FFF;
	text-decoration: none;
	margin: 4px 0;
	background: #CC3399;
	border-width: 1px;
	border-style: solid;
	border-color: #E085C2 #732BB0 #732BB0 #E085C2;
	padding: 4px 6px;
	}
.navlist ul li a:active, .navlist ul li a:hover {
	background: #A4297B;
	border-color: #732BB0 #E085C2 #E085C2 #732BB0;
	}

HTML:
&lt;div class="navlist"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#"&gt;Item one&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#"&gt;Item two&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#"&gt;Item three&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</pre>
<p>All of which, I hope, gives you some idea of the possibilities offered by the humble list. And believe me, this barely scratches the surface. Take a look at <a href="http://css.maxdesign.com.au/listamatic/">Listamatic</a> for literally dozens more variants.</p>
]]></content:encoded>
			<wfw:commentRss>http://carpejugular.com/humble-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why Tables are Bad</title>
		<link>http://carpejugular.com/why-tables-are-bad/</link>
		<comments>http://carpejugular.com/why-tables-are-bad/#comments</comments>
		<pubDate>Wed, 21 Mar 2007 19:41:17 +0000</pubDate>
		<dc:creator>John Foulds</dc:creator>
				<category><![CDATA[HTML and CSS]]></category>
<category>creating killer web sites</category><category>search engine optimization</category><category>stylesheet</category>
		<guid isPermaLink="false">http://carpejugular.com/why-tables-are-bad/</guid>
		<description><![CDATA[Tables were intended as a way to present data which is more comprehensible in tabular form. They became a design tool at a time when there were no better options. But now there is no excuse to be delivering flabby, overweight pages which are expensive to maintain and that cost points with the search engines.]]></description>
			<content:encoded><![CDATA[<p>In 1997 David Siegel wrote a book called &#8220;Creating Killer Web Sites&#8221; in which he revealed many ways by which web designers could bend HTML to their will. Brilliant &#8211; and necessary &#8211; in their day, these tricks are 10 years old and within the context of such a fast-changing medium, that alone should tell you something. In practical terms, this dated approach to site coding mixes presentational code together with content in way which is no longer necessary:</p>
<ul>
<li>A site&#8217;s pages are bigger, therefore slower loading and more expensive to deliver, because most, often all that code has to be included in every single one. The combination of HTML file plus stylesheet is invariably smaller than the original HTML, but the advantage doesn&#8217;t stop there. Stylesheets are cached and need be loaded only once to serve a multi-page site.</li>
<li>Site changes and redesigns involve more labor &#8211; and therefore cost &#8211; to the extent that many site operators live with poor or outdated designs.</li>
<li>Webmasters put a lot of effort into search engine optimization, yet many of the techniques are less effective than simply stripping out all the display formatting code to produce a higher content to code ratio.</li>
<li>With tables, it is much harder to maintain visual consistency throughout a site, but if you do not pay for the extra work needed to ensure that, your site will be less user-friendly and cost you sales.</li>
<li>Table-based pages are less accessible, not only to visitors with disabilities, but also to the increasing number of people using cell-phones and PDA&#8217;s to browse the web.</li>
</ul>
<p>Of course no-one wants to go back to school when it is easy to keep doing things the way you already understand. Why spend a few days learning something new instead of getting right to work each morning on projects which will earn money? The answer is that using HTML for both styling and content is costing you money, each and every day you resist the change.</p>
<p><a href="http://www.csszengarden.com/">Zen Garden</a> is an amazing site for showing how CSS alone &#8211; with no changes at all to the underlying HTML &#8211; can transform the way a site is displayed. But what practical value is there in that virtue?</p>
<ul>
<li>It means that at best you can totally change the appearance of your whole site by making changes to just one file, and at worst that and some new graphics. You don&#8217;t need to touch the HTML (which <em>should</em> be a major job if your site has the depth which search engines like).</li>
<li>Which in turn means you could afford to change your design frequently if you feel it worthwhile. You could drop in seasonal designs cheaply and easily. If you have gone for a magazine-style format as some adult sites have in their member areas, it would take only minutes to change your color scheme to reflect the current magazine. You could even offer a variety of designs via a style switcher.</li>
<li>You have the opportunity, not only to improve your content to code ratio, but to lay out your HTML in a way which brings your content to the top of your files. With search engines that do not spider whole pages, the advantage is obvious, but that structure also makes your pages more accessible to people visiting your site with non-graphical viewers.</li>
</ul>
<h2 class="tutor">Blogs &#38; CSS</h2>
<p>I&#8217;m not naturally an evangelist for geekdom. This article was prompted by the number of people claiming to be adult blog designers, of whom not a single one was producing table-less design. Nine months after the original article, valid themes are still the exception.</p>
<p>Which is ridiculous, because blogging software hands its users an automated way to produce modern, user-friendly, search engine-friendly, webmaster-friendly code. Most such software even provides one or two themes, posts, comments, links and templates to show how it all hangs together. All of which is enough to allow hundreds of mainstream designers, amateurs as well as professionals, to stay true to that model and get the maximum advantage from it. Yet the majority of adult designers immediately revert to using code from the 90&#8242;s. It is irrelevant that the sites may display as intended: especially when the appeal of blogs is their reputed attractiveness to search engines, it makes no sense to throw a big part of that appeal away through sloppy coding</p>]]></content:encoded>
			<wfw:commentRss>http://carpejugular.com/why-tables-are-bad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Toplists via CSS</title>
		<link>http://carpejugular.com/toplists-via-css/</link>
		<comments>http://carpejugular.com/toplists-via-css/#comments</comments>
		<pubDate>Mon, 12 Mar 2007 05:02:20 +0000</pubDate>
		<dc:creator>John Foulds</dc:creator>
				<category><![CDATA[HTML and CSS]]></category>
<category>css basics</category><category>list items</category><category>toplist</category>
		<guid isPermaLink="false">http://carpejugular.com/toplists-via-css/</guid>
		<description><![CDATA[Here are the HTML and CSS you can customize and use to replace tables if that's how you are currently displaying multi-column toplists.]]></description>
			<content:encoded><![CDATA[<p>A very simple article today: a toplist courtesy of CSS.</p>
<p><img src="http://carpejugular.com/files/article02101.gif" width="500" height="120" alt="" /></p>
<p>The HTML is very straightforward. You want more or fewer columns, no problem and vertically you can use as few or as many links as you wish. Nor does it matter if there are the same number of links in each column.</p>
<pre class="tutor">
&lt;div class="toplist"&gt;
  &lt;div class="tl-column"&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;div class="tl-column"&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;div class="tl-column"&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;div class="tl-column"&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;A Trade Link&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
&lt;/div&gt;
</pre>
<p>There are a couple of potential pitfalls in the CSS. The first is that Firefox will not place the content which follows the toplist beneath it, unless you include the &#8220;hack&#8221; shown below. The second is that to avoid falling victim to Explorer&#8217;s buggy way of handling floats, the total width of the columns should never be more than 99% of the width of the containing div. Otherwise the CSS is also straightforward and can be customized to taste.</p>
<pre class="tutor">
.toplist {
  /* if you want a margin above and below the toplist, replace the zero, thus */
  /* margin: 20px auto; */
  margin: 0 auto;
  /* the width may be fixed or a percentage */
  /*width: 99%; */
  width: 500px;
  }
/* Firefox hack */
/* keep this otherwise following content will appear alongside the toplist */
.toplist:after {
  content: ".";
  display: block;
  line-height: 1px;
  font-size: 1px;
  clear: both;
  }
.toplist ul {
  /* adjust the margin to suit */
  margin: 10px;
  padding: 0;
  list-style: none;
  /* text-alignment is left by default but can be changed */
  /* text-align: center; */
  }
.tl-column {
  /* IMPORTANT: the total width of the columns should be 98%-99% of the available width */
  width: 24.7%;
  float: left;
  }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://carpejugular.com/toplists-via-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doctypes</title>
		<link>http://carpejugular.com/doctypes/</link>
		<comments>http://carpejugular.com/doctypes/#comments</comments>
		<pubDate>Sat, 10 Mar 2007 04:44:28 +0000</pubDate>
		<dc:creator>John Foulds</dc:creator>
				<category><![CDATA[HTML and CSS]]></category>
<category>css2</category><category>doctype</category><category>document type declarations</category>
		<guid isPermaLink="false">http://carpejugular.com/doctypes/</guid>
		<description><![CDATA[If you think you have coded everything correctly and your page doesn't look the way you expected in every browser you use for testing, your doctype declaration - you did use one of course - could be the culprit.]]></description>
			<content:encoded><![CDATA[<p>Be warned, this is &#8220;here be dragons&#8221; territory&#8230;</p>
<p>To cope with both old (and badly written) code and well-formed up-to-date code, modern browsers have two modes: <strong>Quirks</strong> mode for dealing with the former, allowing non-compliant code to be displayed without (usually) too much ill effect, and <strong>Standards</strong> mode for displaying compliant documents according to current standards. There is a third mode called <strong>Almost Standards</strong> which is used by Mozilla, Safari and Opera 7.5 with certain doctypes and in this mode some vertical sizing is handled by pre-CSS2 standards. Standards mode in IE6 and older versions of Opera could really be called Almost Standards because these browsers do not comply fully with CSS2 anyway as regards vertical sizing. Towards the bottom of <a href="http://www.quirksmode.org/css/quirksmode.html">this page</a> is a chart which explains the other differences between the behaviour of the various browsers according to mode.</p>
<p>XHTML documents are worth an aside to note that they really should not be delivered as mime-type text/html at all, but as application/xhtml_xml and when they are delivered that way, doctypes are redundant. Unfortunately, no-one using IE6 would then be able to read your pages at all, so when delivered as text/html, they get treated as regular HTML documents. That reality makes a nonsense of many of the claims made by XHTML evangelists.</p>
<p>Ironically, since the point of <strong>Document Type Declarations</strong> (doctypes) is to reduce the need for hacks, they are in themselves arguably hacks. Their job is to tell browsers according to which mode the documents they are reading should be interpreted. Hacks or not, they are vital because if you have coded for one doctype but fail to identify it correctly to your visitors&#8217; browsers, your carefully crafted pages could end up looking very different from the way you intended.</p>
<p>All modern browsers use doctype <strong>sniffing</strong> (aka <strong>switching</strong>) and look to the very first line of an (X)HTML document for a doctype. You may put some php code (for example) that will be interpreted server side ahead of this declaration, but any code which will remain visible in the source, must follow the doctype. Fail to do that and all browsers will revert to quirks mode, ignoring any CSS2 coding you may have used.</p>
<p>Doctypes have two components. The first is compulsory, it is an identifier, much as the numbers attached to versions of PHP are. The second (optional) part is a URL pointing to a document which contains information and rules which apply to this identifier. The two components must be matched if you use both. You can leave the URL out, but &#8211; depending on the level of HTML you have coded for &#8211; doing so will cause some browsers to drop from Standards to Almost Standards or Quirks mode, even if you have declared a Strict doctype.</p>
<p>Oops. Another term to identify!</p>
<p>In the context of browsers, we talk about Quirks, Standards and Almost Standards modes. When we are dealing with HTML documents, the relevant terms are <strong>Strict</strong> and <strong>Transitional</strong>. When we declare that a document conforms to Strict standards, we are telling browsers to interpret it according to the latest (currently CSS2) standards. Any code which is non-CSS2 compliant will be ignored and if we attempt to <a href="http://validator.w3.org/">validate</a> a document which is declared as Strict which includes non-CSS2 compliant code, it will fail. A Transitional document will not fail validation only because it includes older code, modern browsers will (usually) recognize any CSS2 code which is included while also accomodating older code, and older browsers, providing they are not too old, will mostly feel right at home.</p>
<p>At first glance there are good reasons to declare a Transitional doctype, but Strict DTD&#8217;s do encourage the complete separation of structure and presentation which you must have in order to get the full benefit from CSS. And, as some people are about to learn with IE7 which is dropping support for the star html hack in Standards mode, you adopt non-compliant techniques at your own risk.</p>
<p>If you want to dig into this further, there is a detailed chart of browser behavior relative to doctypes <a href="http://gutfeldt.ch/matthias/articles/doctypeswitch/table.html">here</a> and  W3C has a list of <a href="http://www.w3.org/QA/2002/04/valid-dtd-list.html">all the currently valid doctypes</a>. These are the most relevant from which to make your choice:</p>
<p><strong>HTML 4.01 &#8211; Strict, Transitional, Frameset</strong></p>

<pre class="tutor">
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
   "http://www.w3.org/TR/html4/frameset.dtd"&gt;
</pre>
<p><strong>XHTML 1.0 &#8211; Strict, Transitional, Frameset</strong></p>
<pre class="tutor">
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"&gt;
</pre>
<p>And I guess we now need an explanation of how to choose between plain old HTML and <strong>X</strong>HTML (e<strong>x</strong>tensible hypertext markup language). There are several potential advantages in using XHTML, primarily that it is easier to read and write than HTML and that the &#8220;extensible&#8221; part of the name refers to the ability to mix in other XML elements (from MathML for example). But because XHTML cannot be properly served up to some browsers (and not at all to IE6), XHTML ends up being treated by browsers exactly as if it were as regular HTML. Thus any advantages it has remain theoretical at the present time, except to authors working in very specific areas. <strong>Never use XHTML 1.1</strong> because it is not fully compatible with HTML and if you have read further on your own and come across XML declarations for XHTML, be aware that prefacing an XHTML doctype with an XML declaration will force IE6 into Quirks mode, regardless of the doctype you use.</p>
<p>One parting note before I go take some aspirins, is that there are elements which are not valid for Strict doctypes. These include center, font, strike, u and &#8211; the one which might affect more webmasters &#8211; iframe, popular in the delivery of geo promos and live webcam promos. If you want Strict documents to validate, in place of iframes you should use objects:</p>
<pre class="tutor">
&lt;iframe src="page.html" width="400" height="300"&gt;Alternative text in case the iframe cannot be displayed&lt;/iframe&gt;

becomes

&lt;object type="text/html" data="page.html" width="400" height="300"&gt;Alternative text in case the object cannot be displayed&lt;/object&gt;
</pre>
<p>There is a fairly long list of attributes which are also not permitted with Strict doctypes. That list can be found <a href="http://24ways.org/advent/transitional-vs-strict-markup">here</a> and the one many will want to be aware of is that the <strong>target</strong> tag is among the no-no&#8217;s. To use target and still validate, <a href="http://www.sitepoint.com/article/standards-compliant-world/3">this piece of javascript</a> will solve the problem.</p>
<blockquote>Although browsers <em>may</em> read the URL you have included in your doctype, they are not required to do so. Since the treatment of entities such as &#38;nbsp; is defined in that DTD, it is therefore safer to use the numeric equivalents in your code. A full list is <a href="http://www.w3.org/TR/html401/sgml/entities.html">here</a>.</blockquote>]]></content:encoded>
			<wfw:commentRss>http://carpejugular.com/doctypes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flexible SE Friendly TGP Layout</title>
		<link>http://carpejugular.com/a-flexible-se-friendly-tgp-layout/</link>
		<comments>http://carpejugular.com/a-flexible-se-friendly-tgp-layout/#comments</comments>
		<pubDate>Wed, 07 Mar 2007 04:59:09 +0000</pubDate>
		<dc:creator>John Foulds</dc:creator>
				<category><![CDATA[HTML and CSS]]></category>
<category>text layout</category><category>tgp</category><category>thumb preview</category>
		<guid isPermaLink="false">http://carpejugular.com/a-flexible-se-friendly-tgp-layout/</guid>
		<description><![CDATA[This is an attempt to produce a thumb-preview layout which is both search engine and surfer friendly. It inevitably becomes a hybrid in the process, but some elements can be retained even if you want thumbs only. And did you know that if you size images in em's instead of pixels, your visitors can make them shrink or grow to suit their screen size and resolution?]]></description>
			<content:encoded><![CDATA[<p>I jokingly made a suggestion to something who had just completed the conversion of a thumb-preview design to table-less. Namely, that he try to find a way of placing some text links, as a bit of SE bait, high in his HTML, but have them appear low on the page as he would obviously want for such a site.</p>
<p>And it actually can be done without too much difficulty, although oddly it is trickier to achieve that effect with a single-column design, than with two- or three-column layouts. But it involves the use of absolute positioning.</p>
<p>At first glance, absolute positioning is a designer&#8217;s dream. You can place all the components of a page with pixel-perfect precision. Providing you know exactly how big each block is, and the use of text if at all, is limited, absolute positioning works well. But TGP&#8217;s may get an extra-long description which wraps onto the next line and as soon as something like that happens, that perfect design can be spoiled. Worse, Firefox users, even when you have set what you might believe &#8211; pts for example &#8211; is an absolute font size, can wreck such a design just by rolling their mouse wheel to make the text on your page bigger.</p>
<p>So <strong><a href="http://www.carpejugular.com/files/carpethumbs.html" target="_blank">what we have here</a></strong> is a page which, instead of fearing that possibility, exploits it. At the same time, it is a hybrid thumb-preview plus text layout which attempts to be reasonably search-engine friendly. In deference to a suggestion from another visitor, this page is coded in HTML 4.01 Strict.</p>
<p>The first thing to notice is that if you hold down your control key while rolling the wheel on your mouse, you can make the text bigger or smaller. It doesn&#8217;t degrade as well if you decrease the font-size in Explorer, because a single click has twice the effect it would in Firefox. However it deals with larger fonts equally well in both. What might also catch your eye is that the thumbnails themselves also get larger or smaller. Not only do the horizontal dimensions change, but text and images remain aligned vertically too (until very small sizes force word-wrapping).</p>
<p>The main purpose of making this layout in this way was to enable flexible sizing in Explorer the way that Firefox allows, because it isn&#8217;t only a way surfers can mess up your pages. Used positively, it is a way to make your pages more user-friendly for a wider variety of monitor sizes and screen resolutions. Admittedly you can only allow image resizing if you have good quality images, and even then some distortion creeps in as the size moves too far from the original. But the payoff may be worth it against someone seeing only postage stamp sized thumbs at high resolutions.</p>
<p>You are welcome to <strong><a href="http://www.carpejugular.com/files/carpethumbs.html" target="_blank">hack the source about</a></strong> and for convenience I have left the styles in the HTML document. In action, you would save the styles into their own file and link to it as I have indicated.</p>
<p>Okay, to recap. What we have here is an attempt to make a thumb-preview page which is more search-engine friendly than usual, and a page which accomodates users&#8217; font-size preferences. And bear in mind, to make this layout work in fixed sizes, it is only necessary to switch to pixel (px) dimensions to suit your own tastes, thumb sizes, etc.</p>
<h2 class="tutor">Search Engine Friendly</h2>
<p>I have annotated the usual meta tags &#8211; title, description and keywords &#8211; plus h1, h2, and h3 tags. When you are selecting your keyword phrases, bear in mind that almost one search in three is done on 2-word phrases. Another quarter of all search use three words. You might try for two such phrases in your title, adding two more in your description. Unless you are creative enough to write something new, it is reasonable to combine both your title and description for your h1 tag. Mix the keyword phrases up some for the h2 and h3 tags. And of course try to find a happy medium between fiercely competitive keyword combinations and ones which will rarely be used.</p>
<p>This layout &#8211; at least for a page with lots of images and links &#8211; is quite search engine friendly. Unless you do add a promo at the top (and even then it could be a text-rich promo), the HTML goes straight into h1 and h2 tags and then the text links to galleries. This is a very good thing because some search engines only read the first few hundred words of a page. BTW if they don&#8217;t find your keywords in the early part of your content, you could at worst be penalized for attempting keyword spamming.</p>
<p>I have suggested that for image alt tags you use the gallery description. Link title tags are a little more tricky, because they should not duplicate the alt tags or the text links. If you have sub-categories on your TGP, use them for link-titles, otherwise I would be inclined to leave link-title tags out. The general consensus appears to be that alt and link-title tags do not count much these days towards SE placement, so if they cannot be handled automatically &#8211; <em>without the risk of spamming</em> &#8211; they are probably best ignored. Most trade scripts allow you to include descriptions these days: you can choose between displaying them or, with your own keywords mixed in, use them as link-title tags in your toplist.</p>
<p>You should of course increase your site depth by adding archives, faqs, link pages, reviews, a site-map and anything else which is relevant and you have time for. And if you really have the patience, go through your gallery descriptions and make sure they are generously sprinkled through with your keyword phrases.</p>
<h2 class="tutor">The CSS</h2>
<p>As it should be with the presentation code removed, the HTML for this page is very simple and I don&#8217;t believe it needs any explanation. The CSS is also straightforward but some comments are in order</p>
<pre class="tutor">
body {
	background: #FC0;
	font: 0.8em/1.8em Verdana, Geneva, sans-serif;
	}
#outer {
	margin: 0 auto;
	width: 70em;
	background: #FCE5FC;
	border-right: 0.3em solid #F6F;
	border-left: 0.3em solid #F6F;
	}
#header {
	background: url(files/article02301.gif) center 30px no-repeat;
	}		
#header h1 {
	font-size: 0.8em;
	font-weight: bold;
	text-align: center;
	height: 13em;
	min-height: 140px; /* min- and max-height do not work for IE6 */
	max-height: 155px;
	}
</pre>
<p>Before most of us ever heard of CSS, we were used to quoting image sizes in pixels. Perhaps because of that, but also because it is the best way of ensuring browser-independent identical sizing, we most commonly express dimensions for CSS in pixels (px). However, the purists don&#8217;t like that when it comes to font sizes and I agree with them. If you select an absolute font size &#8211; say 14px or 11pt &#8211; it may look great on your screen, but on a smaller one or a much bigger one? By declaring a relative font size &#8211; in this case <strong>em</strong> although <strong>%</strong> works as well &#8211; you are only modifying the font which your visitor is using by default (0.8em = 80%). The strength of this layout (and it is only a layout, not a design exercise), is that the whole page changes to suit. An &#8220;em&#8221; BTW is an old-school printing term for the space occupied by the capital letter &#8220;M&#8221;. Here the line which begins <strong>font: 0.8em/1.8em</strong> means that the page&#8217;s default font size will be 80% of the surfer&#8217;s default size and that the line height will be 1.8 times the height which would normally be applied to that size of font (I am a great believer in the liberal use of white space).</p>
<p>To not divert the search engines with a logo, it is inserted as a background image (note that when calling an image you <em>NEVER</em> put quote marks around the URL). By default a background image will begin at the top left and repeat, but you can position it anywhere you like and instruct it to show only once. Top, left, center, right, bottom &#8211; as well as pixels as used here &#8211; are all valid descriptors. This is the only place on the page I have reverted, partly, to the use of pixels, because the one thing you cannot do with a background image is declare its size. And if you cannot declare its size, you cannot change it. Which is also why &#8211; at least for those browsers which recognize them &#8211; I have used min- and max-height to restrain the font-size related expansion of the header.</p>
<pre class="tutor">
.right {
	display: inline; /* required for Explorers double-margin bug */
	width: 43.8em;
	float: right;
	line-height: 1px; /* prevents extra vertical spacing in Firefox */
</pre>
<p>Anyone who has been reading other articles here is going to be familiar with <strong>float</strong>. For those who are not, if you want two or more columns to appear side by side, you &#8220;float&#8221; them. Explorer however has an odd bug when you combine margins with floats: it doubles their size. Fortunately, the <strong>display: inline;</strong> statement takes care of that. The other &#8220;feature&#8221; dealt with in this part of the CSS is that when you flow a bunch of images into a div as we have done here, Firefox inserts a couple of extra pixels vertical spacing between the rows. Reducing the line-height to a very small dimension is the answer to that.</p>
<p>The only other item of note in this CSS is the use of <strong>clear: both;</strong> in the styling of every div which follows a multi-column section. Any of three things may happen if you leave that out: the first that the block may try to climb up the screen if the columns above have any space between them; the block may place itself at the end of the shortest block above or alongside the rightmost block; and if there is a background, as here, it may not extend all the way down the screen.</p>
<p>Oh sizing. If you want to convert pixels to em&#8217;s, the calculation is easy. More or less. Our default setting of 0.8em works out on my monitor as 13px, so if I want to translate a width of say 260px (pixels) into em&#8217;s, I simply divide by 13. Thus the images which in more traditional terms are originally 180&#215;135 pixels, became 13.85&#215;10.38em&#8217;s.</p>
<h2 class="tutor">Verification</h2>
<p>Both to avoid problems for you and your visitors and to maximize search-engine friendliness, you should <a href="http://validator.w3.org/">verify your code</a>. One unfortunate consequence of using a Strict doctype (see an earlier article here for explanations of doctypes) is that target=&#8221;_blank&#8221;, so beloved of TGP designers for cutting out duplicate code, is not allowed. There are three possible solutions. The first would be javascript, but not everyone has javascript enabled. The second would be to create a custom doctype, which browsers may or may not read. So I suggest that you get your code validated and once happy all is well, add the offending instruction to your page. That is not an elegant solution, but it is the most practical.</p>
<blockquote>
<h2>Try this at home!</h2>
<p>Reading through this article to see if it needed revision, it occurred to me that there might be a way to achieve the commonly desired object of having text higher in the HTML but thumbs showing first on-screen, <em>without</em> needing to resort to absolute positioning and its potential headaches.</p>
<p>You would do something like this:</p>
<pre>
&lt;div id="holder"&gt;
	&lt;div id="text"&gt;link link link&lt;/div&gt;
	&lt;div id="thumbs"&gt;img img img&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>All quite normal, but the trick is to make the thumb block float left, while at the same time declaring its width to be the same as that of the holder. Float the text block right and it would be forced to appear below the thumbs&#8230;</p>
</blockquote>]]></content:encoded>
			<wfw:commentRss>http://carpejugular.com/a-flexible-se-friendly-tgp-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

