473,406 Members | 2,208 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,406 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 1840
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 into a table to align properly, one would absolute...
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 auto so that my content would be centered. ...
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 page, the structure is the following : - a banner...
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 margins so that the content is centered. I assume...
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 box is generated as normal. Block level -...
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 the margin, padding, border and content edges, and...
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 context on an element for the benefit of its...
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 text. Damn if I can't figure out how vertically...
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 to be considered a Very Bad Thing around here....
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 of tables and CSS (to make sure it works well on...
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: 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?
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
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
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...
0
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,...
0
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...

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.