Skip to main content

Liquid resizing page elements

Many times I am told that using tables to layout a web page is a sin.  But, when I try to resize a DIV, it's hard to get it to resize when the window has been resized.  Setting 100% does not seem to work.

So far we have the 3 column liquid layout, but it is not enough when the web pages (or applications for that matter) are more complicated.  When searching on the Internet to resize a DIV in response to a window resize, I am mostly presented with JavaScript solutions. Yeuch.

This is not very accessible for users of other browsers. Luckily, there is an undocumented feature of CSS that helps with this: table layout.

Firstly, create the element in the HTML:

<div id="pageBlock">Content comes in here...</div>

And then in the CSS we set our display:

#pageBlock {
  display: table;
  height:100%;
  width: 100%;
  table-layout: fixed;
}


Although this works with Firefox, it still likes to show a scrollbar for some reason, so you add the following to your CSS, to hide it:

body {
  overflow: hidden;
}


There you go.  This DIV will resize to according to what the browser window size is set to.  To try this out copy and paste the coding from below:


<html>
    <head>
        <title>Resizing Div</title>
    </head>
    <style type="text/css">
        body {
            /* Firefox tends to show the scrollbar without reason
             * so this command hides the scrollbar.  Doesn't matter
             * with IE */
            overflow:hidden;
           
            /* Set the font */
            font-family: Arial, Helvetica;
            font-size:10pt;
        }
        #pageBlock {
            /* Set the presentation style */
            background-color: #ffffe0;
            border:1px solid #add8e6;
       
            /* Produce the liquid layout for the DIV */
            display: table;
            height: 100%;
            width: 100%;
            table-layout:fixed;
        }
    </style>
    <body>
        <div id="pageBlock">
            <p>This DIV resizes to the window size without any JavaScript.</p>
           
            <p>Works by setting the display to table rather than block.</p>
        </div>
    </body>
</html>

Blogged with Flock

Comments

Popular posts from this blog

Open Source alternatives to Adobe Creative Suite

With the take over of Macromedia by Adobe, they have increased their arsenal of design packages, as well as the price. No-one can do pretty much without the popular package of Photoshop for their images, and Dreamweaver for websites, especially aspiring design students who do not have much money.

Nevertheless, open source software has come to save the day. What is open source software? In a nutshell it is free software with its source-code freely available to those who would like to expand or improve on the software. To expand further, anyone who’s tinkered with the source code such as optimisation or additional functionality can resubmit it back to the holders and let others enjoy the fruits of your labour.

I have trawled through the World Wide Web to find out how everyone can benefit from Open Source to build up their own studio and compete against Adobe Creative Suite. All this for free, apart from the cost of the Internet. I am planning to have a facility where you can purchase th…

Open Source alternatives to Adobe Creative Suite update

Oh yes, an update to an earlier post about getting hold of free or Open Source alternatives to Adobe Creative Suite.

I actually forgot to mention about Adobe ImageReady, which gets bundled with Photoshop. There are a number of basic animation tools, but none provide flexibility similar to ImageReady. Fortunately, Open Source lovers are in for a surprise in the form of GIMP Animation Package. This link will take you to the Windows download site as I cannot find any references to this for the Mac OS. Chances are that it could be part of the Gimp.app download, but I haven't had time to inspect this.

The Creative Suite package includes Adobe Bridge, which is a thumbnail viewer to convert images and open them up in any Adobe application for editing. No matter how they would try to trump up its name, it is still a thumbnail viewer. The best free application out there for this is IrfanView. Need I say more?

Are there any pixel pushers out there, who prefer to simply draw their own pics? Why…

ASP Reverse For Loop

It's kind of interesting of how reverse linking does not seem so obvious in classic ASP.  You would think that it would be along the lines of:

dim i
for i = 30 to 2
  'code comes here
next

but it's not.  To have a reverse For loop it's:

dim i
for i = 30 to 2 Step-1
  'code comes here
next

That's right that small bit (Step-1) makes all the difference.  I stumbled upon this by chance and thought that someone would benefit from this.

Happy coding.Blogged with Flock