472,353 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

div positioning and margins

Hello. I tried making a div a2 inside a div a1.

I wanted to place div a2 at bottom right of the div a1. Here's the code
(it's only a test & experimental page that's why I don't post a url)

<style type="text/css">
#a1 {width:300px;height:400px; position:relative;background-color:#ccc;}
#a2 {
width:100px;
height:150px;
bottom:0;right:0;
position:absolute;
background-color:#fff;
}
</style>
[..snip]

<div id="a1">
<div id="a2">
hello
</div>
lalala
</div>
It works well. I still can't find where in the w3c specs says why a1
SHOULD be position:relative (if omitted a2 acts as the container is the
viewport).

No what if I want to position div a2 at the bottom and center of a1?
Usually to center a div I use margin: 0 auto 0 auto;

If I have
#a2 {
width:100px;
height:150px;
bottom:0;
margin: 0 auto 0 auto;
position:absolute;
background-color:#fff;
}
the desired effect isn't happening. Seems margin:auto works when
position is relative right? any way to center the a2 at the bottom of a1?

Thanks
Harris
Jul 20 '07 #1
1 1806
On 2007-07-20, Harris Kosmidhs <hk******@remove.me.softnet.tuc.grwrote:
Hello. I tried making a div a2 inside a div a1.

I wanted to place div a2 at bottom right of the div a1. Here's the code
(it's only a test & experimental page that's why I don't post a url)

<style type="text/css">
#a1 {width:300px;height:400px; position:relative;background-color:#ccc;}
#a2 {
width:100px;
height:150px;
bottom:0;right:0;
position:absolute;
background-color:#fff;
}
</style>
[..snip]

<div id="a1">
<div id="a2">
hello
</div>
lalala
</div>
It works well. I still can't find where in the w3c specs says why a1
SHOULD be position:relative (if omitted a2 acts as the container is the
viewport).
CSS 2.1 Section 10.1.4
No what if I want to position div a2 at the bottom and center of a1?
Usually to center a div I use margin: 0 auto 0 auto;

If I have
#a2 {
width:100px;
height:150px;
bottom:0;
margin: 0 auto 0 auto;
position:absolute;
background-color:#fff;
}
the desired effect isn't happening. Seems margin:auto works when
position is relative right? any way to center the a2 at the bottom of a1?
You need to give it

left: 0
right: 0

as well

This is explained in 10.3.8 of the spec although it's a bit of a
mouthful.
Jul 20 '07 #2

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

Similar topics

12
by: Tom Szabo | last post by:
Hi, Just wondering if there are any disadvantage in absolute positioning controls on a page? In example instead of putting the text fields...
9
by: Bryan R. Meyer | last post by:
Hello Everyone, The problem of browser resizing has become an issue for me. While redesigning my webpage, I set the left and right margins to be...
16
by: Vincent | last post by:
First, here is a page to help you figure out what I'm talking about: http://relinquiere.free.fr/test.html As you can see in the source of this...
8
by: Bryan R. Meyer | last post by:
Hello Everyone, I am in the process of redesigning my web page and I ran into a problem while using CSS. I have laid out my web page with auto...
1
by: FDYocum | last post by:
I'm writing up notes from Eric Meyer's book, explaining CSS here they are: ---------------------------- CSS Positioning Static: The element's...
12
by: Secret Guy | last post by:
I'm trying to understand generally how to make a grid of variously sized boxes using CSS. The first idea I had was to make a box where I can see...
1
by: David Dorward | last post by:
I'm trying to come up with a list of uses for relative positioning. Can anybody think of any I've missed? * Establishing a local positioning...
11
by: clintonG | last post by:
Hello, I use small 15x15 images as 'bullets' in the list. The vertical center of each image is well above the vertical center of the link item...
4
by: Alan Silver | last post by:
Hello, Having been a light reader of this ng for a few months now (after several years absence), I have noticed that absolute positioning seems...
3
by: Jason | last post by:
I don't usually use CSS positioning very much, but I thought that I understood the concept until I got into this one. The site is using a mixture...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.