473,386 Members | 1,812 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,386 software developers and data experts.

Center two side-by-side divs within a container?

I'd like to get a couple of divs centered in a container (let's say
the container is a td, but it could also be a div).

Here's what I have now (div2 and div3 are floated left):
+---------------------------+
|+----+ +-------+ |
||div2| | div3 | |
|| | | | |
|| | | | |
|| | | | |
|| | | | |
|| | | | |
|| | | | |
|+----+ | | |
| +-------+ |
+---------------------------+

I'd like to know how to center them within their container, instead:
+---------------------------+
| +----+ +-------+ |
| |div2| | div3 | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| +----+ | | |
| +-------+ |
+---------------------------+

It would also be nice to know (if it is even possible) how to
automatically distribute them:
+---------------------------+
| +----+ +-------+ |
| |div2| | div3 | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| +----+ | | |
| +-------+ |
+---------------------------+

Pointers, please?

Thanks,
Jamie
Jul 21 '05 #1
2 6047
Jamie Jackson <ju*****@hotmail.com> wrote:
I'd like to get a couple of divs centered in a container (let's say
the container is a td, but it could also be a div).

I'd like to know how to center them within their container, instead:
display:inline-block (CSS 2.1 not supported by IE, Mozilla etc.)
display:inline-table (CSS 2.0 not supported by IE, Mozilla)

Several methods exists to get IE to play ball, none exist to get Mozilla
into line.
It would also be nice to know (if it is even possible) how to
automatically distribute them:


Not an option unless by specifying the widths of the divs and the
margins as percentages of the width of the containing block.

--
Spartanicus
Jul 21 '05 #2
Hi,
I'd like to know how to center them within their container, instead:
[...] If div2 and div3 have known widths put another div around them with
{margin-left:auto;margin-right:auto;}.
It would also be nice to know (if it is even possible) how to
automatically distribute them:
[...]

This could work with #div2, #div3 {margin-left:auto;margin-right:auto;}
but I'm not sure, try it...
Jul 21 '05 #3

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

Similar topics

2
by: The Plankmeister | last post by:
Hi... What's an equivalent of doing: <center>hello!</center> in 4.01 strict? I'm using stylesheets and am telling the various selectors I want to be centred to "text-align : center;" but...
6
by: Franco Lombardo | last post by:
Hi all, I'm running DB2 8.1.5 on Windows 2000 professional SP4. When I try to start Control Center, I see the splash screen for a while, then it closes and nothing else happens. It happens...
2
by: Claude Shea | last post by:
Is DB2 Development Center an addon product that I have to download or purchase separately? I can't seem to find it in any of my downloads or on any of my CDs. Is it available for all versions of...
3
by: Henry Reardon | last post by:
Can someone remind me how to re-install the Development Center? I was playing with the Environment Settings a bit the other day and, ever since, it hasn't worked right. I can create a new Project...
3
by: VB Programmer | last post by:
I cant 'align center' a text box. First of all, all the justifications (left, center, right) on the toolbar are dimmed. Why? Also, when I try to do it through HTML (wrapping the control in a...
5
by: kdfake | last post by:
I cant figure out how to do it... Any clues? R -- --------------------------------- --- -- -
5
Gregos
by: Gregos | last post by:
Remember I'm new at this... My webpage: http://www.geocities.com/gregos_39/gregos/gregpage.html My code: <html> <head> <title>Gregos Apple/Mac Help Page</title> <link href="home_style.css"...
11
by: Mel | last post by:
Does anyone know a way to center the info. on a webpage? I want my web site to work like MySpace.com where the page content remains centered when I resize the browser window. For the life of me I...
2
by: yangtono | last post by:
Hi, I am creating a table to list some data. The table is using a sorting and highlight function that I found from the net. I can't attach image here, basically html will wrap the heading,...
4
by: DiamondEagle | last post by:
Is there a way to center the following div without using the <center> tags? <body bgcolor="#FFFFFF"> <center> <div id="Test" style="background-color:#000000; color:#ffffff; width: 80%;...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.