473,792 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Centering a layer in the window with CSS

is there some way to make the positioning of a layer (div) so that it
is centered in the window. so even when you resize the window it stays
centered? i would like to do this with CSS just like you can with
tables.

thanks,
~peter
Jul 21 '05 #1
10 8796
Hi,
is there some way to make the positioning of a layer (div) so that it
is centered in the window. so even when you resize the window it stays
centered? i would like to do this with CSS just like you can with
tables.


First, a layer is not a div. (There once was a layer-element, so don't
mix them up).

Centering a div should work like this:
<div style="margin-left:auto;margi n-right:auto;">[...]</div>

Chris
Jul 21 '05 #2
Els
Chris Leipold wrote:
Hi,
is there some way to make the positioning of a layer (div)
so that it is centered in the window. so even when you
resize the window it stays centered? i would like to do
this with CSS just like you can with tables.


First, a layer is not a div. (There once was a
layer-element, so don't mix them up).

Centering a div should work like this:
<div
style="margin-left:auto;margi n-right:auto;">[...]</div>


That doesn't work in IE5 for Windows.
http://locusmeus.com/html-css/centeringpage.html

--
Els
http://locusmeus.com/
Sonhos vem. Sonhos vão. O resto é imperfeito.
- Renato Russo -
Jul 21 '05 #3
Hi,
That doesn't work in IE5 for Windows.
http://locusmeus.com/html-css/centeringpage.html

omg. Kick IE5 for windows. Use Conditional Comments to kick IE5-users to
www.getfirefox.com
Jul 21 '05 #4
Els
Chris Leipold wrote:
Hi,
That doesn't work in IE5 for Windows.
http://locusmeus.com/html-css/centeringpage.html


omg. Kick IE5 for windows. Use Conditional Comments to kick
IE5-users to www.getfirefox.com


Conditional Comments? As in: Opera being kicked too, just cause
it identifies as IE? Nah, I prefer to make a simple adjustment
to include those users :-)

--
Els
http://locusmeus.com/
Sonhos vem. Sonhos vão. O resto é imperfeito.
- Renato Russo -
Jul 21 '05 #5
Hi Els,
Conditional Comments? As in: Opera being kicked too, just cause
it identifies as IE? Nah, I prefer to make a simple adjustment
to include those users :-)

Opera does not recognize CCs. You can therefore use them savely. And you
should read what they are and what they do.

Chris
Jul 21 '05 #6
Chris Leipold wrote:
omg. Kick IE5 for windows. Use Conditional Comments to kick IE5-users
to www.getfirefox.com


Telling users that they're using the wrong software is rather rude,
isn't it? Especially after they were kind enough to invite you into
their web "browser". Oh, and btw, some users -- e.g. those at work --
are stuck with MS software.

--
Brian (remove "invalid" to email me)
Jul 21 '05 #7
Peter Altenberg napisał(a):
is there some way to make the positioning of a layer (div) so that it
is centered in the window. so even when you resize the window it stays
centered? i would like to do this with CSS just like you can with
tables.


This may help You:
http://css-discuss.incutio.com/?page...ngBlockElement

--
Regards,
Cezar
Jul 21 '05 #8
On Fri, 19 Nov 2004 09:48:28 +0100, Chris Leipold <cl******@dietz k.de>
wrote in message <30************ *@uni-berlin.de>:
Hi,
That doesn't work in IE5 for Windows.
http://locusmeus.com/html-css/centeringpage.html

omg. Kick IE5 for windows. Use Conditional Comments to kick IE5-users to
www.getfirefox.com


:-)

Or something more polite like "You are using an out-dated browser. It is
recommended you download the latest patches and updates for a better
browsing experience and greater security and stability.
Alternatively, have you considered <insert-favourite-browser-name-here>?"

--
FZS600 - Silver/Black
GS125 - Black/Rust
Ford 100E Prefect - Black, naturally
Whisky - Aberlour Cask Strength
Jul 21 '05 #9
Peter Altenberg wrote:
is there some way to make the positioning of a layer (div) so that it
is centered in the window. so even when you resize the window it stays
centered? i would like to do this with CSS just like you can with
tables.


I know some people will yell and scream that this is not orthodox way to
do it, but this is what I do when I need to center a div and it always
works (IE and Netscape anyway..) it does involve tables, but it's the
only sure way I have found to center divs, take it or leave it:

http://www.francesdelrio.com/index_center_div.html

this is what I do:

<div id="stuff" style="position :absolute; top:80px; left:0px">
<table border=1 cellpadding=0 cellspacing=0 width="100%">
<tr><td align=center>

content of div goes here...
(which can be another table with whatever width you want.. and it
will be centered..)

</td></tr></table>
</div>

I left table borders on so you better see what I did.. I'm afraid it
doesn't work in Opera b/c Opera does not respect table wdth of 100% (so
if I do want my pg to work in Opera I do a diff. version where div is
not strictly centered (or do it w/tables-only for Opera) and direct pg
to diff. version with a browser-detection script..

if (navigator.user Agent.indexOf(' Opera') != -1 ) {
location = "version_of_pg_ for_Opera.html"
}

good luck..... HTH... Frances

Jul 21 '05 #10

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

Similar topics

7
2590
by: Erik Schulp | last post by:
Hi all, I am trying to get a CSS defined layout to center on the page, have tried doing this with the <center></center> tags but than everything is centered, including text etc etc. What should I put into the stylesheet so that, no matter what resolution the viewer's screen is set to, the layout is always displayed centered ? Erik Schulp
15
13507
by: red | last post by:
How do I center two side by side divs ? I've been writing css pages for a while but there's one thing tha still eludes me. I can center a div with margin auto. I can place two divs side by side with float. But I can't center two side by side divs. If I float them and give them auto margins, the auto margins are ignored. If I wrap the two floated divs in another div, the two divs have no
2
2613
by: kevinC | last post by:
Hello, I know most of you are probably going seeing positioning:absolute; and centering in the title and saying, oh no! not again! Do a google search! Actually, I've found many helpful resources online and realize that my case may be a bit more challenging. I'm trying to create a table-less layout that looks something like:
6
1920
by: news.versatel.de | last post by:
Hello NG, I am using javascript to open a new window like this: printpreview=window.open('printview.php','printprev','width=600,height=600'); The new window has a layer called preview: <div id="preview"></div>
17
2516
by: Applebrownbetty | last post by:
Hi, I'd like to append/amend the following code from the Dreamweaver extension "Open Picture Window Fever" for the ability to center the PopUp window: By default, it allows the window to be offset on the left and top, but does not include a centering option. I'm thinking it would include something like (screen.width-imageWidth)/2; somewhere but not sure how do go about doing this.
1
7031
by: vince.guzman | last post by:
Need help with showing Layer 4 after menu times out onmouseout _______________________________________________ <html> <head> <script language="JavaScript"> <!-- function mmLoadMenus() { if (window.mm_menu_0422101100_0) return;
4
1606
by: Paolo | last post by:
I would like to have it so that my webpages, which are built using MasterPages, always appear in the center of the browser of the user, even if he resizes the browser window. As a starting point, when creating the Masterpage, this is the generated html: <body> <form id="form1" runat="server"> <div>
3
4213
by: John Pote | last post by:
1. Horizontal centering a <divin browser window. The current trend seems to be to place page content in a fixed width area in the middle of the browser window. How is this achieved? If I use a top level <divthen I can place it with CSS attribute 'left:', but this is a fixed offset. Is it possible to have a <divcentered in the browser window? 2. Verticle centering in <div>
0
1030
by: Steve | last post by:
Hi... This code appears to work on the development box when centering and sizing a word application in front of the form that triggered the automation. But on the target boxes, it skews down and to the right. And the size of the word window is bigger than the form window that I'm calculating against (the word window should be .9 as wide and .8 as high). I think it may have something to do with the target box resolution or font size...
0
9670
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
10430
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10159
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
10000
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
9033
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
7538
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
6776
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
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2917
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.