473,657 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to centre a div container regardless of browser resolution?

23 New Member
hi guys .. I was wondering if someone could offer some guidance with regards to a web page positioning?

I would like to position my web page or main div container to appear in the middle of a browser regardless of the end user's chosen resolution.. is this possible?

below is my html

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.  
  4. <head>
  5.  
  6. <title>Creative Developments</title>
  7. <link rel="stylesheet" href="creativestylesheet.css">
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. </head>
  10.  
  11. <body>
  12.  
  13. <div id="root">
  14.  
  15.     <div id="header"></div>
  16.  
  17.  
  18.              <div id="menu">
  19.             <a href="http://creativedevelopments.net/CV/">Home</a>
  20.             &nbsp;|&nbsp;
  21.             <a href="http://creativedevelopments.net/CV/">CV</a>
  22.             &nbsp;|&nbsp;
  23.             <a href="http://creativedevelopments.net/Portfolio/">Portfolio</a>
  24.             &nbsp;|&nbsp;
  25.             <a href="http://creativedevelopments.net/Interest/">Interests</a>
  26.             &nbsp;|&nbsp;
  27.             <a href="http://creativedevelopments.net/Contactme/">Contact me</a>
  28.                   </div>
  29.  
  30.  
  31.         <div id="main">
  32.         <h1> Home </h1>
  33.            <p> I'm a freelance web developer with over five years' experience in the industry. </p><br />
  34.  
  35.         <p> general text goes here
  36.          </div>
  37.  
  38.             <div id="sidebar">
  39.           </div>
  40.  
  41.  
  42.  
  43.             <div id="footer">
  44.                <a class="text1" href="http://creativedevelopments.net">Home</a>
  45.             &nbsp;|&nbsp;
  46.             <a class="text1" href="http://creativedevelopments.net/CV/">CV</a>
  47.             &nbsp;|&nbsp;
  48.             <a class="text1" href="http://creativedevelopments.net/Portfolio/">Portfolio</a>
  49.             &nbsp;|&nbsp;
  50.             <a class="text1" href="http://creativedevelopments.net/Interest/">Interests</a>
  51.             &nbsp;|&nbsp;
  52.             <a class="text1" href="http://creativedevelopments.net/Contactme/">Contact me</a>
  53.                 <div id="rightcontent">
  54.             <a class="text2" href="http://www.creativedevelopments.net">Powered by Creative Developments</a></div>
  55.                 </div>
  56.  
  57.  
  58. </div> 
  59.  
  60.  
  61. </body>
  62. </html>
  63.  
  64.  
below is my css

Expand|Select|Wrap|Line Numbers
  1. #body               {background-color:#009933}
  2. #root                {margin-left: auto; margin-right: auto; margin-top: 0px; height: 705px; width: 900px; font-family: tahoma}
  3.  
  4. #header                {height: 90px; width: 898px;background-color: #CD2626;  border-width: 1px;   border-color: #8B8989;  border-style: solid;}
  5. #menu                {text-align: center; padding-top:10px; padding-bottom:10px; background-color: white; height: 30px; width: 898px; margin-top: 4px;font-family: Tahoma, Helvetica, sans-serif;font-size: 14px; font-weight: bold; color: black;  border-width: 1px;   border-color: #8B8989;  border-style: solid;}
  6. #menu a:link       {border-style: solid; border-width : 1px 4px 4px 1px; text-decoration : none; padding : 4px;  border-color : #69f #00f #00f #69f;color: black; }
  7. #menu a:visited    {font-family: Tahoma, Helvetica, sans-serif; font-size: 14px; font-weight: bold; color: black; text-decoration: none; }
  8. #menu a:hover      {border-color: #ccc; text-decoration: underline;color: black; }
  9.  
  10. #main               {margin-top: 4px;float:left; width: 674px; height: 500px; background-color: white; border-width: 1px;   border-color: #8B8989;  border-style: solid}
  11. #sidebar            {margin-top: 4px;margin-left: 4px;float:right; width: 218px; height: 500px; background-color: white;border-width: 1px;   border-color: #8B8989;  border-style: solid} 
  12.  
  13. #footer             {margin-top: 4px;margin-bottom: 4px;float: left; height: 45px; width: 898px; background-color: #CD2626;border-width: 1px;   border-color: #8B8989;  border-style: solid}                   
  14. #rightcontent       {float: right; padding: 5px; font-family: Tahoma; font-size: 11px; color: white}
  15.  
  16. #text1 a:link       {font-family: Tahoma, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: white; text-decoration: underline;}
  17. #text1 a:visited    {color: #00611C; font-weight:bold;text-decoration: none}
  18. #text1 a:hover      {color: #00611C;font-weight:bold;text-decoration: underline}
  19.  
  20. a                   {font-size: 12px; font-weight: bold; color: white;text-decoration: none}
  21.  
  22. b                    {position: relative; top: 117px; left: 50px; margin-top: 0; font-size: 14px; font-family: Tahoma; color: #white;}
  23. h1                     {padding: 18px 20px; margin-top: 0; font-size: 22px; font-family: Tahoma; color: #800080;}
  24. h2                  {padding: 0px 24px; margin-top: 0; font-size: 16px; font-family: Tahoma; color: #800080;}
  25. h3                  {padding: 0px 24px; font-size: 12px; font-weight: bold; font-family: Tahoma; color: #000000;}
  26. h4                  {padding: 0px 24px; font-size: 11px; font-family: Tahoma; font-weight: normal; color: #000000;}
  27. h5                  {margin-right: 6px; margin-left: 6px; margin-top: 5px; margin-bottom: 5px; font-size: 11px; font-family: Tahoma; font-weight: bold; color: #FFFFFF;}
  28. h6                  {margin-right: 6px; margin-left: 6px; margin-top: 5px; margin-bottom: 5px; font-size: 11px; font-family: Tahoma; font-weight: bold; color: #800080;}
  29.  
Jul 21 '08 #1
4 4096
drhowarddrfine
7,435 Recognized Expert Expert
A centered div remains centered regardless of resolution. If you mean sizing of the browser window, then what you have should keep it centered by using 'auto' on root.
Jul 21 '08 #2
studentofknowledge
23 New Member
hi there thanks for your reply

what i would like to do is have the root div to display vertically and horizontally in the middle of a browser page regardless to resolution

iv tried to amend my code but not having any luck... please advise

thanks in advance : )
Jul 21 '08 #3
gits
5,390 Recognized Expert Moderator Expert
hi ...

have a look at this thread and see whether it helps or not :)

kind regards
Jul 22 '08 #4
studentofknowledge
23 New Member
thanks for your reply - that was a wonderful example. got my web page to display nicely in the middle

thanks for your help : )
Jul 24 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1852
by: Robster | last post by:
I'd to postion a pop up windown to appear in a position relevtive to the centre of the screen, rather than top=200, left=200. Is there any way i can do this? Alternatively i need a script that will position the popup in the same place irellevent of browser window and resolution.... Any ideas?
2
2872
by: Ney André de Mello Zunino | last post by:
Hello. The issue is quite known: you have a block-level container holding a set of floated elements and you need that the container's content height take the floated elements' dimensions into consideration. E.g.: <div class="images"> <div class="image"><img src="example1.png" width="160" height="120" alt=""></div> <div class="image"><img src="example2.png" width="160" height="120"
7
8410
by: Don G | last post by:
Is it possible to lock the aspect ratio of container using CSS? For example, have a <div> that is resized according to the size of the browser window, but remains square, regardless of it's size. In the sample code that follows, I have set the width and height of the <div> to be 75%, however the height of the height does not vary with the size of the content window. If it did vary, it probably wouldn't give the desired results because...
8
1910
by: Andrew Crook | last post by:
I placed the following code in my html file window.resizeTo(1000,700) window.moveTo((screen.availWidth/2)-(1000/2),(availHeight/2)-(700/2)); The resize seems to work fine, however, the move does not seem to work. Tested under IE6 and firefox. I wish the browser to resize and centre on screen when the user goes to my site.
10
11599
by: santiago538 | last post by:
Hi, Is there any way to specify which monitor a Window.open() will launch a new browser window in on systems with more than one display. It would only need to work with Mozilla browsers, and not IE. Thanks!
2
1593
by: balabing79 | last post by:
Hi all I am running internet explorer 7 at a resolution of 1024 768 the problem i am having with my page is that when it is viewed on resolutions such as 1280 1024 or higher the page appears on the upper left of the screen and a yukky white border all around. theres actuall 2 things i need to be able to do and believe both done in css the first is to make the page appear centre in larger browsers so if someone can tell me how to do that it...
1
4146
by: Grzegorz Klimsa | last post by:
Hi ! I have a problem wiht detecting resolution of client web browser I prepare several files of css style for different browsers and different resolutions, (such as : Style_1024x768.css ; Styleff_1024x768.css; Style_1280x1024.css ; Styleff_1280x1024.css ) I want to set css style file depends on resolution browser I wrote this script to detect type of browsers, but i don't have any idea
5
4109
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like to wrap the control in the proper control type - which is also a container. At design time I want to be able to turn this : <my:container> <asp:textbox />
0
8402
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5633
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.