My inquiry is closely tied to a previously resolved issue discussed on this page. Specifically, the solution offered by @harpo in the top-rated answer's comments partially addressed my concern. Nonetheless, I've discovered that it doesn't effectively work on certain elements, particularly those with borders.
For context: I'm utilizing Bootstrap for my website, featuring a fixed navigation bar at the top, followed by a layout filled with unstyled divs
and .panel
divs within them. The body has a 60px top padding to accommodate the navbar. However, when navigating to a link with an offset (e.g., example.com#div2-1
), the top of the div remains obscured by the navbar.
To address this issue, I applied the solution outlined in the aforementioned answer by adding 60px negative padding on the :before
element, then compensating by setting the height to 60px. While this adjustment didn't cause a visual change (as intended), it expanded the calculated height of the div by 60px, shifting the starting point upwards and aligning content correctly. Unfortunately, border-clad elements like my .panel
divs seem to preserve the border's containment, rendering the :before
pseudo-element ineffective in altering the div's calculated height, leading to coverage by the navbar once more.
You can view my code on JSFiddle here: http://jsfiddle.net/rszqtw80/3/
A visual inspection using developer tools will confirm the proper creation and correct height (60px) of the :before
element for both outer and inner divs
. However, the total calculated height omits the :before
element for inner divs
, resulting in functionality impairment. Disabling the border in Chrome Dev Tools showed improvement, hinting that the border could be the obstacle.
Hence, my query: Can this CSS-based offset concept be effective on my .panel
elements without sacrificing the border or resorting to widespread a
tag usage? Removing borders leaves the panels aesthetically lacking, while wrapping each div
within an a
tag appears inelegant.
Thank you for your assistance!
UPDATE: Altered my question slightly for clarity, aiming to eliminate any confusion arising from my initial explanation. Apologies for any ambiguity.
ADDITIONAL UPDATE: I've attached three screenshots illustrating the issue better than words can convey. Regrettably, I can't include them here due to limited "reputation" allowing only two links.