Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!--------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------
- [site_center.html]
- A foolproof up-to-date way of centering your entire web site using nothing but a 'div' and CSS.
- (c) Damion 'Phr0z3n.dev' Tapper, 2014.
- Email: Phr0z3n.Dev@Gmail.com
- --------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------->
- <html>
- <head>
- <title>
- Phr0z3n.Dev's Centered Web Site
- </title>
- <style type="text/CSS">
- body{
- font-family: helvetica;
- font-size: 11pt;
- }
- h1{
- margin: 0px;
- font-family: verdana;
- font-size: 16pt;
- text-align: center;
- }
- /***************************************************************************************
- * Here we just dig into the matter without hesitation. Pretty much every attribute set
- * here is relevant to the process except for 'border' and 'border-radius'. The former
- * gives us an idea of the site's outline, and evidence that it is truly centered, when
- * we are done. The latter almost always make sense.
- ****************************************************************************************/
- #mainDiv{
- /**
- * Set the overall web site dimensions. This will vary depending on your site's
- * intended usage.
- **/
- width: 800px;
- height: 600px;
- /**
- * Without absolute positioning, the site could not be centered vertically using this
- * method.
- **/
- position: absolute;
- border: 2px solid rgb(0, 128, 0);
- border-radius: 20px;
- /**
- * Horizontal Centering:
- * Notice how the margin attributes are set to a fraction of the overall relative
- * dimensions.
- **/
- left: 50%;
- margin-left: -400px;
- /**
- * Vertical Centering:
- **/
- top: 50%;
- margin-top: -300px;
- /**
- * NOTE: even without deprecated alignment elements/attributes, it is quite evident
- * that this is more than just an interesting method to get the job done.
- **/
- }
- </style>
- </head>
- <body>
- <div id="mainDiv">
- <p>
- Voila, your site is officially centered. (<em>But not your text</em>) Now get on with the coding. ;)
- </p>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement