Expression Web help

Join our community

Visit our Expression Web Forum

Centring pages in the browser.

If you want to web site to be a fixed width, you will most likely want to have the web site in the centre of the browser, when viewed in a larger browser view port.

Layers or divs?

A layer, is an absolutely positioned div. Position is taken from the top left of the browser window. You will never get a layer made site to centre in a browser window!

<div>'s require you to tell them what to do via your styles and can be centred in a browser window.

Copy and paste the codes below.

CSS

<style type="text/css">
<!--
body { text-align:center; }
#container { text-align:left; width:760px; margin:0 auto;position:relative;
background-color: #CCCCCC;
 }
-->
</style>

XHTML

<body>

<div id="container">
<p>this is content<br />
And some more content</p>
<p>and just some more</p>
</div>

</body>

An example of the above code in action can be seen here.

The container div holds your other divs that make up the layout of your site.

Microsoft MVP

RSS Icon  RSS

Our forum feed can be found here

Add RSS to Yahoo

Add to Google

Reader not listed? Click here for more options

Expression Web Help RSS
Expression Web Help. Tips and Tricks and tutorials Get our feed now