473,399 Members | 3,888 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,399 software developers and data experts.

Overlapping divs, scrolling and fragment anchors

I'm looking for some advice here.

Using a browser that supports fixed positioning (not IE), take a look at:

http://tranchant.plus.com/guitar/chord-tutorial/

The page consists of a fixed header and menu, with scrolling content.
The content goes under the header - in Firefox/Mozilla, and allegedly
Safari, you can see this due to the slight transparency of the header.

I've assigned an appropriate (50px) margin-top to the content so that it
starts below the header when the page is loaded.

OK, now click on the "Chords on the guitar" link in the Contents list.
*If* you have Javascript enabled, your browser should do what you
expect, leaving the appropriate <h2> just below the header bar.

Now reload the page - and notice how the <h2> is at the top of the
viewport, underneath the header bar.

In the first case, some Javascript detects if you're clicking a fragment
link, jumps to it, and then scrolls up 55px to compensate.

Can anyone think of a better way to ensure that links to fragment
anchors, whether from the current page or a different one, are aligned
as I want? I'm after some sort of viewport-margin, but don't want to
resort to assigning a scrollbar to the content div separately.

--
Mark.
http://tranchant.plus.com/
Jul 20 '05 #1
4 5157
Mark Tranchant wrote:
OK, now click on the "Chords on the guitar" link in the Contents list.
*If* you have Javascript enabled, your browser should do what you
expect, leaving the appropriate <h2> just below the header bar. ... some Javascript detects if you're clicking a fragment
link, jumps to it, and then scrolls up 55px to compensate.


Follow-up - this doesn't appear to work in Opera.

--
Mark.
Jul 20 '05 #2
Mark Tranchant <ma**@tranchant.plus.com> wrote:
In the first case, some Javascript detects if you're clicking a fragment
link, jumps to it, and then scrolls up 55px to compensate.


Ouch, ugly. I once constructed a solution for this problem, from memory:

a[id]{padding-top:55px}

<h2><a id="foobar"></a>Header</h2>

It's been a while since I used it, play with the idea a bit if it
doesn't work immediately.

--
Spartanicus
Jul 20 '05 #3
*Spartanicus* <me@privacy.net>:
Mark Tranchant <ma**@tranchant.plus.com> wrote:
In the first case, some Javascript detects if you're clicking a fragment
link, jumps to it, and then scrolls up 55px to compensate.
a[id]{padding-top:55px}


:target {padding-top: 55px}

Of course that is a CSS3 selector and thus hardly supported yet. On that
site I don't see the reason for that fixed header anyway: most browsers,
that support fixed positioning, do support the 'rel' and 'rev' attributes
of the 'link' element, some even for the 'a' element.
<h2><a id="foobar"></a>Header</h2>


<h2><a name="foobar"></a>Header</h2>

or rather

<h2><a name="foobar">Header</a></h2>

make sense as does

<h2 id="foobar">Header</h2>

but your code doesn't. Browsers (like NS4) that don't support a target
link to an 'id' in an 'h2' don't support it for 'a' either.

--
"You can only find truth with logic
if you have already found truth without it."
G.K. Chesterton
Jul 20 '05 #4
Christoph Paeper <ch**************@nurfuerspam.de> wrote:
a[id]{padding-top:55px}
:target {padding-top: 55px}

Of course that is a CSS3 selector and thus hardly supported yet.


Why mention it then?
<h2><a id="foobar"></a>Header</h2>


<h2><a name="foobar"></a>Header</h2>

or rather

<h2><a name="foobar">Header</a></h2>

make sense as does

<h2 id="foobar">Header</h2>

but your code doesn't.


A deliberate construct. The reason is that although the padding does not
affect the positioning of adjacent boxes in the vertical stack, the
padded area still exists and since it's higher in the z-index stack it
can obscure content, for example if there's a link located under that
padded area it becomes unclickable.

Demo of this effect that uses the more logical <h2><a
id="foobar">Header</a></h2> construct:
http://www.pan-europe.utvinternet.ie...tm#stop_switch
(use a proper browser to see the phenomena)

Scroll down the page a bit, hover over the "RIGHT HANDLEBAR CONTROLS"
link to see the effect.
Browsers (like NS4) that don't support a target
link to an 'id' in an 'h2' don't support it for 'a' either.


It's up to the OP if he wants to dumb down his code to support fragment
identifiers that are compatible with NS4. I've stopped doing so some
time ago, I'm sure many have done likewise.

--
Spartanicus
Jul 20 '05 #5

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

Similar topics

0
by: Jochen Eisinger | last post by:
Hi, I'm trying to arange the following layout with css (see http://c0ffee.org/test/index.html & /test/style.css): On the one hand, I have a (red) main div and a (green) "float: left;" menu....
8
by: gpbmike | last post by:
I'm wondering if anyone else has had this problem before. Every now and then a div on my page will overlap with another. Thi only happens in firefox (vs. IE and Safari) and it corrects itself whe...
2
by: Daphne Tregear | last post by:
Is there every anything other than woe with IE...? I'm working on a redesign for my hobby pages in my personal home space before re-exporting them back to where they belong. I've based the...
3
by: michelle koen | last post by:
Hi Folks, on <a href="http://donbrice.com/new/page.php?section=schools">this page</a> and for all the sections I can't get Safari(2.02) or Firefox-PC(1.5) or the latest vers. of Opera-Mac to...
8
by: knoxautoguy | last post by:
This problem has consumed a lot of my time, and I'm aftraid someone will tell me that my whole approach to this objective is wrong; however, I would like to know if there is a way to do this. I...
2
by: Jakub Ɓukomski | last post by:
hi. i've got a problem as follows, to which i can't find a solution to: i've got two divs, which are completely independent of each other (neither is a parent of child of another). they're...
1
by: spolsky | last post by:
hi, i have the following html. if padding given for the span it overlaps the divs within IE 6, FireFox 1.5 and Opera 9.01. i don't want to give sizes manually. how could i prevent this...
2
by: Liam Gibbs | last post by:
Hello everyone. I'm having a problem with a web page. What I have is one DIV (a header) overlapping the border around another DIV (a menu block). I want this, because I want to put this header...
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: 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
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
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...
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,...

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.