Categories
Code Tech Web

CSS3: Rounded Table Corners (No images)

You cannot give a whole table (<table>) rounded corners using CSS, browsers will ignore it, you must round the corners of the cells (<td>) inside.

The following uses CSS2 selectors (:first-child etc) and CSS3’s corner-rounding border-radius to selectively round the outer corners of the cells in the corners.
This will work for any size table.

table.rounded-corners tr:first-child td:first-child {
	border-top-left-radius: 5px;
}
table.rounded-corners tr:first-child td:last-child {
	border-top-right-radius: 5px;
}
table.rounded-corners tr:last-child td:first-child {
	border-bottom-left-radius: 5px;
}
table.rounded-corners tr:last-child td:last-child {
	border-bottom-right-radius: 5px;
}
Categories
Code Tech Web

PHP Bug: json_encode() misleading warning on object with private properties

I have found a peculiar issue with PHP’s json_encode() function.

If you have an instance object with private properties and use json_encode() it will give you a very misleading warning.

class ExampleObject {
    private $privateProperty;
    ...
}
$obj = new ExampleObject();
json_encode($obj);

results in

Warning: json_encode() … recursion detected …

There are two workarounds in the comments for the function at php.net but this is simply a PHP bug as far as I am concerned.

Categories
Code Musings Opinion Personal Tech Web

BBC Homepage Beta Using jQuery

The BBC Beta Homepage is using jQuery, but unfortunately it’s ugly.

I should qualify that – I think it’s a good move to make the homepage more personalisable, but does it have to look so Web2.0?
Big text was a fad a year ago, but it’s too informal for an internationally recognised and respected news source, and it makes it look so childish – I dread to think what the new CBBC sites would look like!

I realise this is only a beta, and may well change considerably, but without a bit of a shrink I won’t be likely to use it as a homepage tab.

Categories
Code Tech Tips Web

JavaScript Bug – Modulo of small numbers

It seems that there is a problem with the modulo function, ‘%’, in JavaScript.

For example: 10 % 0.1 should equate to zero but comes out as 0.09999999999999945 probably due to some internal floating-point rounding errors.

Easy solution (a hack really): Multiply both numbers by 1000 before using the modulo function.

Categories
Code

JS: Clear Default Value onFocus

Simply add the following to the the onFocus attribute of any HTML form input tag.
[code lang=”JavaScript”]if (this.value == this.defaultValue) this.value = ”;[/code]
this.defaultValue is automatically given the value in the HTML.