473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Centering a DIV within a DIV?

Hello,

me again. This time I'd like to align a DIV both horizontally and
vertically centered within a larger DIV.

The only alignment-relevant CSS property I could think of was
text-align, and that didn't work.

Of course I could put the DIV into a one-cell table and use the td's
align and vertical-align attributes, but let's assume I don't want to
use tables for that type of stuff.

Thanks,
robert
Oct 27 '05 #1
3 6549
On 27 Oct 2005 14:31:41 GMT,
Robert Latest <bo*******@yahoo.com> wrote
in Msg. <3s************@individual.net>
me again. This time I'd like to align a DIV both horizontally and
vertically centered within a larger DIV.


I just found the negative-margin trick. Kinda ugly, but works well
enough.

Thanks,
robert

Oct 27 '05 #2
Els
Robert Latest wrote:
On 27 Oct 2005 14:31:41 GMT,
Robert Latest <bo*******@yahoo.com> wrote
in Msg. <3s************@individual.net>
me again. This time I'd like to align a DIV both horizontally and
vertically centered within a larger DIV.


I just found the negative-margin trick. Kinda ugly, but works well
enough.


Only until the viewport becomes smaller than the inner div.

--
Els http://locusmeus.com/
Sonhos vem. Sonhos vão. O resto é imperfeito.
- Renato Russo -
Oct 27 '05 #3
Robert Latest wrote:

Hello,

me again. This time I'd like to align a DIV both horizontally and
vertically centered within a larger DIV.

The only alignment-relevant CSS property I could think of was
text-align, and that didn't work.

Of course I could put the DIV into a one-cell table and use the td's
align and vertical-align attributes, but let's assume I don't want to
use tables for that type of stuff.


For horizontal centering, the inner DIV should have the following
style:
margin-left: auto;
margin-right: auto;
width: nn%;
where nn is the desired width as a percentage of the width of the
outer DIV. I do this all the time.

For vertical centering, try doing the same with margin-top,
margin-bottom, and height. I have never done this, so I'm not sure
of the results.

--

David E. Ross
<URL:http://www.rossde.com/>

I use Mozilla as my Web browser because I want a browser that
complies with Web standards. See <URL:http://www.mozilla.org/>.
Oct 28 '05 #4

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

Similar topics

19
by: George Ziniewicz | last post by:
.. I try to use CSS when possible, though I am still learning and don't maximize its use. In particular, I still use a table to provide for a centered image in a few slideshows (though table...
3
by: Jonah Bishop | last post by:
I have a puzzling problem with centering text, and I'm hoping that someone here can help me out. First of all, let me state that I am using XHTML 1.0 Strict and CSS for all layout purposes (no...
18
by: Heath | last post by:
Is it proper to center images in a <div> by using the text-align: center property? Or is there a better way?
4
by: Justin Archie | last post by:
The subject says it all my friends. I have searched google to death about centering problems and for some reason no one seems to have the error I have. For the past few days I have been working on...
3
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...
5
by: Markus Ernst | last post by:
Hello This is a test example: http://www.markusernst.ch/anthracite/ http://www.markusernst.ch/anthracite/living_divani.html After googling and experimenting for several hours, I ended up...
2
by: rudicheow | last post by:
SHORT VERSION ============= I have a bunch of identical fixed-size single-celled tables that rest against each other horizontally thanks to "float:left". These tables are dynamically generated...
4
by: SAL | last post by:
Hello, is there a way to menu control dynamically center itself horizontally on a page? I have placed a menu control in a panel control (no ajax) and would like it to center itself. Depending on...
4
by: harryusa | last post by:
I am trying to center 2 images concentrically which are z-indexed to lay on top of each other making an image with a border from another image that has a transparent center. I need the images to be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.