Forum Moderators: open
I have a layer that I need to auto-center on the page. This is easy-peasy and is a subject that is covered elsewhere. This code will achieve it:
<style type="text/css" media="screen">
body {
background-color:#fff;
}
#content {
position:absolute;
left:50%;
top:50%;
width:300px;
height:300px;
/* the width/2 */
margin-left:-150px;
/* the height/2 */
margin-top:-150px;
border:1px dashed #333;
background-color:#eee;
text-align:left;
font:11px verdana;
padding:10px;
}
body>#content {
margin-left:-160px; /* Correct value. */
margin-top:-160px; /* Correct value. */
}
</style>
The way to do it with CSS totally within the Dreamweaver GUI is as follows:
1. Create your style sheet
2. Edit the body tag style
>> Block >> Text Align = center
>> Box >> Margin = set all to 0 pixels
3. Create a Layer and note its pixel width (e.g. 500)
4. Create a new style, e.g. 'centerLayer'
>> Box >> Margin >> Top = 10 (whatever suits you)
>> Box >> Margin >> Left = -250 (i.e. half of 500)
>> Positioning >> Placement >> Left = 50%
It displays identically, and auto centres, in IE6 and Fireworks on PCWin2k, Safari and IE5 on MacOSX. Not tested in any other browser.
I hope it helps somebody.
Frank