473,837 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;he ight:400px; position:relati ve;background-color:#ccc;}
#a2 {
width:100px;
height:150px;
bottom:0;right: 0;
position:absolu te;
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:relati ve (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:absolu te;
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 1861
On 2007-07-20, Harris Kosmidhs <hk******@remov e.me.softnet.tu c.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;he ight:400px; position:relati ve;background-color:#ccc;}
#a2 {
width:100px;
height:150px;
bottom:0;right: 0;
position:absolu te;
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:relati ve (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:absolu te;
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
2350
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 position them. I understand the issue with resize, that is not a problem.
9
32073
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. However, there are images that I used absolute positioning in order to place them in the appropriate location on my page. When I do a browser resize, these images do not move (obviously). However, the rest of my content is auto centered as...
16
3465
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 - a skip-to-navigation-links div - a main div with : - a div with content - navigation links in a single ul - a footer
8
5406
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 that this will enable the content to be centered in any resolution which the viewer may be using. I then tried to position some navigation images on my web page (using absolute positioning). When the browser is resized, the images stay in the...
1
1471
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 - rectangular box that is part of the doc flow Inline - rectangular boxes in the context of lne boxes flowing in parent element.
12
2462
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 understand why they have the areas that they do. And I'm having trouble... I read in the 2.1 spec, that the height and width properties specify the height and width of boxes generated by applicable elements, and that a percentage value is taken...
1
1725
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 absolutely positioned descendents. * Overlapping a nearby element (but why not just use negative margins?) * Cute, but probably useless, animations involving an element flying into and/or out of its normal position with JavaScript.
11
24348
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 align on center. Does anybody have any tips? <%= Clinton Gallagher METROmilwaukee (sm) "A Regional Information Service"
4
2113
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. Generally, when someone posts a question about a design that uses it, they are told not to. Now, in my ignorance, I don't see what's wrong with it, when used sensibly. Let me say straight off that I am *not* talking about trying to produce...
3
2319
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 older browsers; CSS is mainly used for fine-tuning), and I'm trying to get an image to overlap a table. The main table is centered on the screen, though. Here's the simplified layout that I'm using:
0
10864
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...
0
10562
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10615
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
10263
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
9390
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...
0
6989
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
5842
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4469
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3122
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.