Showing posts with label HTML. Show all posts
Showing posts with label HTML. Show all posts

17 July 2009

position:fixed

Well well, I have learnt something new this morning. I think this new thing comes under the category of "how did I not already know this" but equally there is always the category of "kill IE6, please!".

I suspect that had IE6 dies off a good few years ago, I would already know this new technique as it is not supported in IE6. But I am very much of the opinion that we no longer need to support IE6 perfectly. I do not want to go into detail about browser support, I have spoken often enough about my thoughts on the matter.

So, onto the interesting part. Have you ever wanted to create a layout with an element which has a height of 100% minus some pixels? Or an equivalent for the width of an element? I know that I have on many occasions. Each time, I have had to either accept it cant be done or utilise some seemingly clever JavaScript to achieve my goal.

But, no more! position:fixed can now be our saviour. Picture the situation where you have a two column layout with your navigation in the left column and content in the right column. You want the left column to have a solid background colour and be 100% in height but leave a 50 pixel space at the top of the column. You might use the following markup:

<!DOCTYPE html>
<html>
<body>
 
<div id="LeftNavigation">
    <ul>
        ....a series of links
    </ul>
</div>
 
<div id="Content">
    ....some content
</div>
 
</body>
</html>


Now if you apply the following CSS:

#LeftNavigation {
    position:fixed;
    top:50px;
    bottom:0;
    background:#cccccc;
    overflow:scroll;
}
#Content {
    margin-left:310px;
}


You should see things exactly as I described above. The key styles are on the LeftNavigation DIV, the position, top and bottom styles. You should be aware that this is not supported in IE6 but I have found it works in all the browsers I have tried.

If this is also new to you, have a little play - it has certainly brightened my day!

16 March 2009

Standards - again

As if to reinforce what I was saying 4 months, the unique and unparalleled Douglas Crockford has articulated in part my own thoughts about HTML 5 in this blog post.

As I said back in November:
I want to see greater interoperability between the various browsers and as such I believe simplification would be better.

4 February 2008

HTML 5 and Web Standards

With the recent publishing of the W3C HTML 5 Working Draft, and the debacle which is IE versioning through meta tags, I have been having some thoughts about web standards.

It so happens that I am not the only one! Molly E. Holzschlag has also been thinking. Whilst her thoughts are somewhat more drastic than mine, I felt it time to put forward my thoughts on the next generation of HTML on the web.

HTML 5 is a massive specification introducing many new tags and attributes of which without a doubt my favourite is the irrelevant attribute. I would personally be quite happy to wrap large parts of the spec in such a tag!

I believe strongly in simplification and I do not believe HTML 5 simplifies HTML. What I think we need is less not more. There is one very specific point which grates. HTML should enforce an XML syntax - tags should have to be closed and have to be well formed. HTML 5 allows unclosed tags and this to my mind is a step backwards. Indeed, I see the spec contains code a bit like this:

<dl>

<dt>Radius: <dd> <meter min=0 max=20 value=12>12cm</meter>

<dt>Height: <dd> <meter min=0 max=10 value=2>2cm</meter>

</dl>


This is some ugly stuff!

I believe HTML 5 should actually be XHTML 5 (or version 2 or whatever version you like!). It should contain a small set of semantic tags including paragraph, emphasis, lists, audio, video, anchors, images, divisions (or sections) amongst others, creating a small set of recognised tags with well defined default rendering for each. As an author, I should be allowed to create ANY OTHER TAG I LIKE as long as it is well formed XML. The default rendering for each unrecognised tag should be as an inline element and they should offer no semantic meaning.

The tags I "create" should be able to be styled through CSS and accessible as DOM nodes via JavaScript.

Its simple. Or is it too simple?