| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Can anyone help me:
I am trying to make my web page automatically centre to an individual's monitor. i.e. whatever resolution the moniter, my web site will always centre itself, so that when viewed in larger resolutions that it was designed in, it does not get lost in the left hand corner. I know this is possible, because I have used many sites that do it....but how?! |
|
#2
|
||||
|
||||
|
You can either use an IFRAME or for a simpler solution wrap the content in another TABLE and set the vertical and horizontal alignment of the TD to be centered
__________________
selwonk If I've posted some code above, you might think it looks a bit simplistic. It might be. I'd rather people tried the next step themselves rather than getting a full solution on a plate. That way they learn more! |
|
#3
|
|||
|
|||
|
Not sure how you're laying out your page but this works for CSS styling.
<html> <head> <style type="text/css"> body { text-align:center; } #container { border:1px solid #000; width:600px; margin:0 auto; text-align:left; } </style> </head> <body> <div id="container"> My content </div> </body> </html> |
|
#4
|
||||
|
||||
|
There is no "real" way of making things vertically center using XHTML1.1 and CSS2
Horizontal centering can be achieved by using margin-right: auto; margin-left: auto; According to the W3C, the XHTML canvas is considered to have finite width, but infinite height One workaround, is to use negative margins, this is fine if your box has a fixed height, otherwise, you'll need to use Javascript to update the margins: Code:
#box { margin-left: auto; margin-right: auto; width: 500px; height: 300px; margin-top: -150px; position: absolute; top: 50%;}
<div id="box">
<p>Your content</p>
</div>
|
|
#5
|
||||
|
||||
|
very true comment about the vertical centering in XHTML 1.1 (which is strict). What I would do maybe, depending on what you need this for, is have a javascript popup that automatically centers vertically and horizontally. That poses a ton of new issues that you may not want to deal with but that's the only way i can think of to do it.
__________________
If you found a post of mine helpful, please click on the on my post to add to my reputation.
|
|
#6
|
|||
|
|||
|
i have no idea what you guys are talking about.. but if you want the site to be centered in a simple way.. without using CSS
after your body tag <body background=yadda text=color alink=color vlink=color> <center> content of the page, or the main table </center> </body> OR if you wanted to center the content vertically and horizontally... <body background=yadda text=color alink=color vlink=color> <table width="100%" height="100% border=0 cellpadding=0 cellspacing=0> <tr> <td> content centered vertically and horizontally. can also have a main table/design in here (nested tables) </td> </tr> </table> </body> |
|
#7
|
||||
|
||||
|
using <center> has been deprecated and is not supported in the current versions of XHTML so..... if you want your website to be functional once browsers end support for HTML4 and before, use CSS.
If you want a table to be completely centered use the following. I included a dark border so you can see that it is centered and I made the width 770px which is the standard width for websites that do (and should) support 800x600 resolution. Code:
<head>
<style type="text/css">
body {
font-size : 12px ;
font-family : Verdana, Arial, Helvetica, sans-serif ;
color : #000000 ;
margin : 0;
padding : 0;
}
.blackBorder {
border : 1px solid #000000 ;
text-align : center ;
margin-right : auto ;
margin-left : auto ;
}
</style>
</head>
<body>
<div style="margin-right:auto;margin-left:auto;text-align:center;">
<table style="width:770px;" cellpadding="0" cellspacing="0" class="blackBorder">
<tr>
<td style="text-align:left;">text</td>
</tr>
</table>
</div>
</body>
Horizontal centering is not supported by XHTML so you can expect less-than-adequate support for vertical centering in the future. |
|
#8
|
||||
|
||||
|
TECHNICALLY the use of the STYLE attribute has been deprecated but for the purpose of this example it helps to give you an idea of what goes and where.
|
![]() |
| Viewing: ASP Free Forums > Web Design > Web Layout > Centreing a web page |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|