Wickham's XHTML & CSS tutorial
View in Firefox, Safari, Opera and IE but IE6 often needs different solutions. In general IE7 and IE8 display like Firefox apart from the HTML5 and CSS3 features. The IE9 updates are mainly related to HTML 5 and CSS3 issues and it displays to a large extent like other main browsers. Google Chrome is based on the same WebKit engine as Safari.
Some of the examples are provided just to show problems, others show solutions that work in most major browsers. Use the example that suits you.
problems
warning: works in some situations or some browsers or needs care to display as you wish
OK in Firefox, Safari, Opera, Google Chrome and IE6 to IE9
1
Look at php.net for the various date format characters.
You can use the date format characters in variables like this:-
The output of the four echo statements is:-
where the first is for the current date in the y-m-d format (y-m-d and y/m/d are default formats) and the second is based on the current date, adding 10 days onto the string value of the date (ie onto y-m-d as text, ie 10 days onto a text date in the format 09-10-29) and changing the format.
The same future date can also be expressed as 10 days added on to the current date string in variable $date0:-
2
The example below has a simple form which displays the date 10 days in the future in a format which is not the default accepted by a MySQL database; it then formats the date into a default style and sends data to a database; the table below the MySQL setup shows the data extracted from the database in another date and time format and ordered by date and time.
Time formats can be coded in the same way as dates. In this example the time in the form has been shown as a fixed value in the format 09:15 instead of the current time and the output in the bottom table has had the format changed because the field type is Time and the database recognises the form value.
You could use this principle where you wanted to show a preferred date and time for a future delivery or appointment, and the viewer can edit the date and time (although if he edits them incorrectly it will show a date of 1970-01-01 and time of 0000:00:00 in the database, but you will have the Timestamp in the database to see the date and time submitted and you can then verify by email).
The form above has been disabled.
The code for the form and its PHP and MySQL link is:-
See PHP Form to MySQL for details on setting up a MySQL database. The MySQL set up for this example is as follows:-
| Field | Type | Length/ Values | Collation | Attributes | Null | Default | Extra | Action |
|---|---|---|---|---|---|---|---|---|
| ID | int | 5 | No | auto_ increment | Primary | |||
| date1 | Date | Yes | NULL | |||||
| time1 | Time | Yes | NULL | |||||
| place1 | Text | utf8_unicode_ci | Yes | NULL | ||||
| email1 | Text | utf8_unicode_ci | Yes | NULL | ||||
| timestamp | Timestamp | ON UPDATE CURRENT_ TIMESTAMP | No | CURRENT_ TIMESTAMP |
The table below shows all the data that has dates after the current date (which was 10 November 2009 when I prepared this example but I have disabled $today in this example to continue to show the data) with the Timestamp which is automatically added by the database when the entries are submitted; ordered by the date and time entered by the viewer.
| ID | Date | Time | Address | Timestamp |
| 3 | 15 Nov 2009 | 5:45pm | 15 Apple Lane | jon-sparks@supanet.com | 2009-11-10 07:46:08 |
| 6 | 16 Nov 2009 | 9:00am | 34 Plum Lane | will-parks@hotmail.com | 2009-11-10 08:08:13 |
| 1 | 20 Nov 2009 | 9:15am | 32 Cherry Close | fred-smith@hotmail.com | 2009-11-10 07:44:13 |
| 4 | 29 Nov 2009 | 8:45am | 23 Lilac Road | dave-roberts@hotmail.com | 2009-11-10 07:47:44 |
| 2 | 29 Nov 2009 | 11:35am | 42 Peartree Avenue | harry-jones@gmail.com.com | 2009-11-10 07:45:16 |
| 5 | 01 Dec 2009 | 3:50pm | 2 Damson Street | sue-king@gmail.com | 2009-11-10 07:49:46 |
The code for the table and its PHP and MySQL link is:-
Notes
View/Source or View/Page Source in browser menu to see all html code.
The body of this page has margin: 20px. The examples above are in a containing div with width: 730px; and margin: auto; so that the page centralises at large screen resolutions.
A lot of codes have been put in html tags in my examples rather than in a stylesheet or in a style in the head. I have done this for the convenience of the viewer so that most (but not all) codes are in one place and the stylesheet does not always have to be viewed in addition. When coding your own page you should try to put as much as possible in a stylesheet and link with id or class to the html tag.
Remember that when a Doctype is included above the head before the html tag (as it should be) then the overall width of a div is its defined width plus borders, margins and padding widths.
If there are differences between Firefox and IE6 that cannot be overcome with one code, code first to get a satisfactory solution in Firefox then create a conditional comment which will only apply to IE6:-
for instance, if margin-top: 20px; in Firefox needs to be margin-top: 30px; in IE6 then put the following in the head of the html/xhtml page:-
<!--[if ie 6]>
<style type="text/css"> div { margin-top: 30px; } </style>
<![endif]-->
or if there are many different styles, create a separate stylesheet:-
<!--[if ie 6]>
<link rel="stylesheet" href="ie6.css" type="text/css">
<![endif]-->
IE6 will contain just the amended styles such as div { margin-top: 30px; } and others (no head or body tags or Doctype).
When looking at a page source for this site you may see code like <p>Little Egret</p> instead of <p>Little Egret</p>. The code < is because in that instance the code is to be displayed on the screen as text. If the < symbol was placed in the code a browser would activate the code and it would not display as text. Such code is not normally required when writing xhtml code tags which are to be activated.
© Wickham 2009