Archive for category Web design & development

CSS in PHP

The last time I tried to render CSS through PHP was many, many moons ago. I didn’t work and I couldn’t figure it out. Yesterday I tried again and found out why… the MIME type must be set as text/css. D’oh. Set MIME type like this:

< ?php
header("Content-Type: text/css");
?>

,

No Comments

Weird line-height in Chrome?

Specifying line-height on an <a> in a <li> will not work in your webkit based browsers. Line-height needs to be set on the containing <li> to work at all in Chrome or consistently in Firefox. Now you know.

No Comments

The CSS reset has been reset

The grandaddy of all CSS resets hits version 2.o beta: Eric Meyer’s Reset Revisited. See also the subsequent thoughts on how to handle :focus.

Update! Now at Beta 2.

,

No Comments

Image free CSS arrows/pointers/triangles

Great to finally see [forgive my split infinitive] a well documented walkthrough on how to create these little bit of magical CSS that add triangular pointers onto your navigation elements – or Talk Bubbles as Stubbornella OOCSS has them – without either images or extra markup (reintroduce the extra markup if you want IE6 & 7 support). It’s the lack of markup that had me confused. Thanks to Nate for explaining what I was missing – CSS psuedo elements, or any gernerated content is not part of the DOM – and hence you cant actually inspect it with any flavour of developer toolbar to see how it’s done.

Zero width and height plus big margins = polygon effects!

Like wow.

Read, straight for the horse’s mouth here: CSS Arrows and Shapes Without Markup .

No Comments

The IE9 hate starts here…

Made me grin/grimace….

A piece on how retarded Microsoft’s latest incarnation of Internet Explorer may turn out to be, despite the hype:

http://css3wizardry.com/2010/08/14/ie9-is-the-ie6-of-css3/

Oh dear.

No Comments

On CSS image replacement techniques and SEO

Having learnt that properly structuring headings is very important to SEO but wishing to be able to style and design pages beyond the limitations of HTML text I’ve often reverted to this old CSS hack to replace heading text with nice image substitutes:

.hide {visibility: hidden; display: block; line-height: 0; font-size: 0.1em; height: 0; margin: 0; padding: 0;}

I’ve been wondering about whether this is still good practice recently and found today that I’m not the only one… thanks to Laura Carlson’s [webdev] Web Design Update newsletter (subscribe already! HERE) I seem to have found a reasonable debate in this post and subsequent comments from Roger Johansson on his site at 456 Berea Street. In short:

  • Avoid using CSS techniques to hide text from your site. Especially avoid hiding text that contains keywords that are important to your site.
  • If you want to provide an accessible format of text that is in an image – use a regular image with alt text in preference to any CSS background image replacing actual text. CSS sprites may be very useful to reduce server requests and page load times but use sprites for pure graphic elements only – not text.

In a moment of clarity I realise that an image is valid within a heading tag… but whether alt text within an image within a heading tag is as strong for SEO as regular text in that same heading tag (whether or not hidden/positioned off-screen) is a question that could do with a clear answer. I suspect that alt text is not as strong: clear guidelines from those Google folks (I do love you) seem to be lacking again. SEO and graphically rich websites are not something that the engines of Google can cope with properly when faced with trying to be a sh*t umbrella (in gmail or the wider web) against the legions of spam pedlars out there who would love to stuff keywords into every corner of a page. In the meantime the life of a web designer remains tough.

Poor me.

,

No Comments

PHP web forms

Websites are a point of contact – and a contact form that sends an email is the way to normally handle enquiries. (Of course phone numbers/addresses must first be easy to find!) A contact form requires a web server to actually do something – ie send you an email – it’s not just displaying HTML code anymore. There’s options to get by without a script on your server – the excellent WuFoo online form builder is a great option here – but if you want a form as part of your page that you can style yourself it ain’t the ticket. So, knowing a little PHP, a PHP script is sought that:

  1. makes sure all input is cleaned and sanitized to avoid nasty things being done on/to your server
  2. checks for errors in the data without discarding the well formed data
  3. uses some form of CAPTCHA to keep those spam bots at bay
  4. sends email through an authorised SMTP email account (Gmail, for example, will either mark as spam or simply not accept mail that isn’t)

Other nice things to consider would be nice, cross-browser (HTML5) placeholder text (that doesn’t get submitted).

Finding a PHP web form framework

Last time I set up a form was a while ago – I’ve been doing mostly WordPress sites (or other CMS work) recently and have found the premium Gravity forms plugin for WordPress to work a treat. Anyway, cut to the chase already… the old script I had used  failed on points 3 & 4 above I’d like to say I can lean on PEAR PHP (which is already on my webserver) but I’m really not a programmer. I found a solution in the excellent PHP form “library” from Dagon Design. I’d never heard off it but it’s the first serious result for “PHP form script” in Google at the moment – so it  must at least be popular. More importantly it ticks all the boxes above (plus much more) and is well documented. Go get it. The only thing it doesn’t do is verify numerical input.

There’s no need for me to go into the setup at all – it is very well documented – just spend a half hour or so to read through it.

Adding placeholder text to the form framework

All I have to add is that I’ve edited the script a bit to set default text as HTML5 placeholder text (and remove default text from text inputs). The form is run in conjunction with Daniel Stocks’ HTML5 Placeholder Plugin for jQuery to make sure that the placeholder text works with IE etc.

To get the placeholder text working I changed the last few lines of the  below (from 754):

function ddfm_gen_text($item) {

	// type=text|class=|label=|fieldname=|max=|req=(TRUEFALSE)|[ver=]|[default=]

	global $form_submitted, $form_input, $show_required;

	$req_text = (($show_required) && ($item['req'] == 'true')) ? '<span class="required">' . DDFM_REQUIREDTAG . '</span> ' : '';

	$gen = "";
	$gen .= '<p class="fieldwrap"><label for="' . $item['fieldname'] . '">' . $req_text . $item['label'] . '</label>';
	$gen .= '<input class="' . $item['class'] . '" type="text" name="' . $item['fieldname'] . '" id="' . $item['fieldname'] . '" value="';

	if ($form_submitted) {
		$gen .= ddfm_bsafe($form_input[$item['fieldname']]);
	} else if (isset($item['default'])) {
		$gen .= ddfm_bsafe($item['default']);
	}

	$gen .= '" /></p>' . "\n\n";

	return $gen;
}

to:

	if ($form_submitted) {
		$gen .= ddfm_bsafe($form_input[$item['fieldname']]);
	}

	$gen .= '" placeholder="' . ddfm_bsafe($item['default']) . '" /></p>' . "\n\n";

	return $gen;

So what’s all the fuss about – well you can see the version I worked on, in action, as part of a website for this fancy (in the good sense) hair salon in Fuengirola

, ,

No Comments