473,654 Members | 3,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

div always centered horizontally in browser window

Hi folks

I built up a small website which is designed for 800x600 display. Runs just
fine in this resolution but if you have a system in 1024 or 1280 pixels
wide, the site just "sticks" in the upper-left corner of the browser window.
So I'm trying to keep it horizontally centered whatever screen resolution
you are set in. I do not want to deal with table cells, just CSS.

I think that I must have a three column DIV layout with the center one set
to 800px fixed width. But I cannot find how to set the left and the right
one to -let's say- "the remaining width divided by 2".

I struggle since a while with google now and I cannot find a way to the
solution. Perhaps I'm a bit tired and fed up now and I'm not searching the
right way.

Any help would be greatly appreciated

Regards !

--
Seb
Metal extrême, gothique et atmosphérique
http://www.metal-extreme.com
The Unholy Black Metal Songtitle-O-Matic
http://metalseb.free.fr
Jul 20 '05 #1
4 7948
On Fri, 2 Apr 2004 16:05:55 +0200, metalseb <me******@free. fr> wrote:
Hi folks

I built up a small website which is designed for 800x600 display. Runs
just
fine in this resolution but if you have a system in 1024 or 1280 pixels
wide, the site just "sticks" in the upper-left corner of the browser
window.
So I'm trying to keep it horizontally centered whatever screen resolution
you are set in. I do not want to deal with table cells, just CSS.

I think that I must have a three column DIV layout with the center one
set
to 800px fixed width. But I cannot find how to set the left and the right
one to -let's say- "the remaining width divided by 2".

I struggle since a while with google now and I cannot find a way to the
solution. Perhaps I'm a bit tired and fed up now and I'm not searching
the
right way.


There are a few solutions to your dilemma.

One is to center the 800px (actually less, since you need to leave a bit
of room for browser frame and scrollbar) div inside a wrapping div. Style
the inside div margin: 0 auto;

Another is to allow the design to fluidly flex to the size of the
viewport. This is preferred by many, as it takes advantage of screen real
estate. In most cases this is easier and yields better results. Just
remove the width: 800px completely, by default divs will take up all
available width.
Jul 20 '05 #2
"metalseb" <me******@free. fr> wrote:
I built up a small website which is designed for 800x600 display.
Oh dear.
Runs just fine in this resolution
Presuming I have my browser window maximised and no sidebars open,
right?
but if you have a system in 1024 or 1280 pixels
wide, the site just "sticks" in the upper-left corner of the browser window.
Yup, that's one of the problems with such a design. Another one is the
horizontal scrolling encountered by anyone who has browser window
narrower than 800 pixels wide.
So I'm trying to keep it horizontally centered whatever screen resolution
you are set in.
Why not make the design use the available space rather than waste it?
I do not want to deal with table cells, just CSS.
Okay.
I think that I must have a three column DIV layout with the center one set
to 800px fixed width. But I cannot find how to set the left and the right
one to -let's say- "the remaining width divided by 2".


No.

body {text-align: center;} /* for IE */
div.everything {
margin-left: auto; /* for better browsers */
margin-right: auto;
width: 800px;
text-align: left; /* so the content itself isn't centered
within the div */
}

<body>
<div class="everythi ng">
your whole fixed width site
</div>
</body>

But better still would be to use a liquid design that adapts itself to
the available space.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net > <http://steve.pugh.net/>
Jul 20 '05 #3
metalseb wrote:
Hi folks

I built up a small website which is designed for 800x600 display.
Runs just fine in this resolution but if you have a system in 1024 or
1280 pixels wide, the site just "sticks" in the upper-left corner of
the browser window. So I'm trying to keep it horizontally centered
whatever screen resolution you are set in. I do not want to deal with
table cells, just CSS.

I think that I must have a three column DIV layout with the center
one set to 800px fixed width. But I cannot find how to set the left
and the right one to -let's say- "the remaining width divided by 2".

[snip]

Are you saying that you want the page to fill the width of the viewport? Or
are you saying that you want a fixed-width layout (or a maximum-width layout)
which is centred if the viewport is wider than the layout?

I think you want to fill the width of the viewport. In which case, perhaps a
better way of thinking of it is to choose widths (numbers of pixels, or
percents) for the side-columns, and let the centre column use whatever it
left. That is a much-used layout, and there are sound (and simple) ways of
doing it. (At the moment, I can't think of a way to solve your "fixed centre
column plus 2 equal side columns" layout).

Suppose you want (for a bit of variety) a 200px left column and a 20% right
column. Then you can position those, using floats or absolute positioning.
Then don't attempt to position the centre column, just let it flow into place.
Give it large left and right margins, of (say) 210px & 21%, and its content
will avoid clashing with the side columns. If you choose 2 fixed sized side
columns, or 2 percent sized side columns, the change to the above is obvious.

If you want a "maximum-width" effect, where the whole display occupies the
width of the viewport until that becomes greater than X, then the layout
remains at X but centred, the easiest method I know is to use a single-cell
table. Give the cell (not the table) a width (not a max-width), and it will
act, even in IE, like max-width.

(I'm assuming you don't want a fixed-width but centred layout. That is easy,
but there is a trick needed for IE 5, involving { text-align: center } in the
body rule).

--
Barry Pearson
http://www.Barry.Pearson.name/photography/
http://www.BirdsAndAnimals.info/
http://www.ChildSupportAnalysis.co.uk/
Jul 20 '05 #4
Neal, Steve, Barry

Thanks for you help and remarks. This helped me to think about the site
layout in a different way. I think that I will head forward to a liquid
layout in a few days but for the moment, il will stick up to the (yukky)
"centered 800x600 popup way" because the original design, as wanted by the
customer, is a bit hard to "liquidify" and will need some extra graphic work

Kind regards

--
Seb
Metal extrême, gothique et atmosphérique
http://www.metal-extreme.com
The Unholy Black Metal Songtitle-O-Matic
http://metalseb.free.fr
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1940
by: VRandy | last post by:
Example: http://pages.prodigy.net/randyv/centerprb.htm The desired effect is a fixed width left margin with a fixed width div centered in the right side. If the browser is resized to become very narrow (less than 640px in this example), the right side centered div should stop at the margin and horizontal scroll bar appear as the window gets extremely narrow. IE6 and Opera 4.11 display all the examples the same way. The top row is a...
27
3039
by: KiwiBrian | last post by:
If I want to horizontally center a div on a page, but have the div of undefined width, so that it contains whatever is within it, as a table cell does, how do I code this in CSS? Brian Tozer
4
9727
by: Mimo Zus | last post by:
I'm hoping that someone can explain what's going on; better yet provide a workaround. I'm designing a centered CSS site based on a 550 pixel wide vertical background image. Onto this background I built a two column layout with nested navigation and content divs. The background image is centered via "background: ... center;", the divs are centered over it via "margin: 0 auto 0 auto;". The problem I'm having in IE6 is inconsistent...
17
6881
by: No One | last post by:
Is there a way to keep a control centered inside a form without having to recalculate everytime the form is resized?
12
2764
by: deko | last post by:
I'm trying to get a 1px border around the content section of this page: http://www.clearpointsystems.com As you will see, I have a header/nav bar (looks correct), but the border around the content is not centered and does not resize properly as the browser window is resized. The goal is a 1px border around the content (div id="page") with about 30px (or 2%) margin all around and the border/content should resize as the browser
2
4702
by: sachjn | last post by:
Hi, I need to have a table along with other UI items in page which resizes horizontally and vertically with the browser window. That means table should accoupy the remaining available space in the browser window and should display horizontal and vertical scroll bars if content of table is more than available width & height. I can do similer to this by enclosing table in a <DIV> with style as : overflow:auto; height:200px etc. But things...
9
1960
by: alice | last post by:
I've been slowly learning CSS, but wanting to jump ahead and get a page to have 4 columns of text that are centered on the page, no matter how big the monitor/browser/window, I'd like each one to resize and take up 25% of the screen space. Strange things have been happening since trying to do this- First, I can't figure out how to center any of this except by putting them all in a <centertag, which I've heard is not what one is supposed...
1
5633
by: Maxime | last post by:
Hello, I want to make a button that automatically resizes according to the text length and the font size (which can be changed in firefox pretty easily with the browser). The button already works for resizing horizontally, the problem is when I enlarge the text using firefox, the text doesnt stay aligned with the button. If the text is larger, the text is not centered vertically in the button.
16
3566
by: Stan The Man | last post by:
I'm a CSS novice trying unsuccessfully to make three thumbnail images display horizontally instead of vertically. I suspect I'm missing something really stupid but I'll take the flak if someone could kindly point me in the right direction (using words that the vicar's wife would understand). The vertical thumbnails can be seen at the bottom of this page: http://www.zen86793.zen.co.uk/gmga2008/index.html ... the first image is in the right...
0
8375
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
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8482
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
8593
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
7306
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
6161
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
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1593
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.