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

Positioning context - does it work?

I posted a similar question yesterday, but didn't get an answer that
resolved the issue. (Thanks to those who tried though.)

The background: I've read in books and online that if you have one
element with "relative" positioning, such as a <div>, it creates a
"positioning context" for element within it. E.g., if you have a <p>
inside your <div> you can give it absolute positioning and position it
(right, left, top, bottom) in terms of the <div> -- not in terms of the
browser window. So in this scenario...

<div style="position:relative;">

<p style="position:absolute;
top:20px;
left:20px;">

Some text

</p>

</div>

.... the <p> will not be positioned 20 by 20 pixels from the window upper
left (assume the <div> is somewhere lower down in the page). It will be
located those dimensions in relation to the upper left corner of the
<div>. And that's supposed to work in all up-to-date browsers from what
I've read.

However, I can't get it to work.

Here is some code from a page I'm trying to design:

[...]

<div style="position: relative;
background-color:#003399;
padding:3px;
margin: 12px 0 0 0;">
<h1 style="margin: 0;
padding: 0;
color:#ffffff;
font:Arial, Helvetica, sans-serif;
font-size: 12px;">
ASA Notes
</h1>
<p style="color:#ffffff;
font:Arial, Helvetica, sans-serif;
font-size: 12px;
position:absolute;
right:4px;">
<a href="/meetingnotes/index.htm">Home</a>

</p>
</div>

[...]

And the resulting output in IE and Mozilla is here:

http://www.somerandomcrap.com/temp/cssscreenshots.htm

Note that the word "Home" is OUTSIDE of the <div> and not located where
intended: inside the <div> near the right edge, lined up at the same
vertical level as the <h1> element with "ASA Notes" in it.

So do the supposed CSS positioning "rules" have any validity? Or is the
problem that I'm not understanding them correctly? Or have I made some
syntax error?

By the way, I also tried achieving the desired effect using the "float"
property, but that didn't work either.

I checked that the document is valid XHTML 1.0 strict.

Any help would be greatly appreciated.
Jul 20 '05 #1
6 2652
rajek wrote:
And the resulting output in IE and Mozilla is here:
http://www.somerandomcrap.com/temp/cssscreenshots.htm


In this case it just looks like you've triggered an IE bug (there are
many). You could probably acheive the desired effect using
text-align:right instead.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Now Playing ~ ./white_town_-_your_woman.ogg

Jul 20 '05 #2
Toby Inkster wrote:
rajek wrote:

And the resulting output in IE and Mozilla is here:
http://www.somerandomcrap.com/temp/cssscreenshots.htm

In this case it just looks like you've triggered an IE bug (there are
many). You could probably acheive the desired effect using
text-align:right instead.


Thanks for the reply. However, note that the problem occurs in Mozilla
as well -- not just IE. Also, the desired effect (refer to my original
post for a description of that) would not be achieved using "text-align:
right".
Jul 20 '05 #3
follow-up set to c.i.w.a.stylesheets

rajek wrote:

<div style="position: relative; [...]
<h1 [...] >
<p style="
position:absolute;
right:4px;">
<a href="/meetingnotes/index.htm">Home</a>
</p>
</div>

http://www.somerandomcrap.com/temp/cssscreenshots.htm

Note that the word "Home" is OUTSIDE of the <div>


You have not set a top position for that paragraph. It's probably
defaulting to the same position as static, which is below the <h1>
element. The paragraph is just overflowing the <div> container.

--
Reply email address is a bottomless spam bucket.
Please reply to the group so everyone can share.
Jul 20 '05 #4
rajek wrote:
Toby Inkster wrote:
> rajek wrote:
>
>
>>And the resulting output in IE and Mozilla is here:
>>http://www.somerandomcrap.com/temp/cssscreenshots.htm

>
>
> In this case it just looks like you've triggered an IE bug (there are
> many). You could probably acheive the desired effect using
> text-align:right instead.
>


Thanks for the reply. However, note that the problem occurs in Mozilla
as well -- not just IE. Also, the desired effect (refer to my original
post for a description of that) would not be achieved using "text-align:
right".


<style type="text/css">
#wrapper {
background-color:#039;
padding:2px 8px 0 4px;
height:26px;
margin-top: 30px;}
#left {
float:left;
font:bold 100% Arial, Helvetica, sans-serif;
margin-top:2px;
color:#fff;}
#right {
float: right;
color:#fff;
font:bold 100% Arial, Helvetica, sans-serif;}
</style>

<div id="wrapper">
<div id="left">ASA Notes</div>
<div id="right"><a href="/meetingnotes/index.htm">Home</a></div>
</div>

--
Gus
Jul 20 '05 #5
rajek wrote:
Also, the desired effect would not be achieved using "text-align: right".


What about floating?
http://examples.tobyinkster.co.uk/floatyfloaty.strict

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jul 20 '05 #6
DM
Toby Inkster wrote:
rajek wrote:
Also, the desired effect would not be achieved using "text-align: right".

What about floating?
http://examples.tobyinkster.co.uk/floatyfloaty.strict


Finally it works. Thanks a lot for the help.
Jul 20 '05 #7

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

Similar topics

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. ...
4
by: Jane Withnolastname | last post by:
I am trying to re-work an old site by replacing the html with css. On the main page, I have a logo image which I needed centred on the initial screen. I found the solution here:...
7
by: Griff Miller | last post by:
Please see http://home.houston.rr.com/gmiller15/css/vertprob.html . In mozilla 1.6/1.7 it looks the way I want it, with a thin separation between the two boxes. In IE6, the two boxes touch, which...
1
by: Frances Del Rio | last post by:
don't know if I'll succeed, have spent a lot of time already trying to figure this out: I would like to position a footer (co. name, address, etc..) at the bottom of browser page, in such a way...
3
by: DM | last post by:
I'm trying to use a relatively positioned <div> to create a positioning context for a <p> such that the <p> will render within the <div> near the right edge. I'm using XHTML 1.0 strict. My page...
17
by: George Hester | last post by:
http://tinyurl.com/5uj6w The lower middle icon the "block" should not drop down when the mouse is over it. How can I stop that? Also the navigation divs both top and bottom should follow the...
5
by: rajek | last post by:
I posted a similar question yesterday, but didn't get an answer that resolved the issue. (Thanks to those who tried though.) The background: I've read in books and online that if you have one...
2
by: TheCruelPanda | last post by:
Hey there. My name is Rowan, and it's been three weeks since I last used tables for an HTML design. Okay, I'm rather new to CSS and I have a big positioning problem here. It might not be a...
3
by: mikewse | last post by:
I have a strange problem where it seems IE is doing the correct layout but Firefox and Safari isn't. I think I'm probably wrong, and there is something in the standards that say behaviour should be...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.