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

Position something relative to an inline element?

I've spent most of the day struggling with what I thought would be a
trivial problem.

I have a hidden element that appears, outside of the normal flow,
when the mouse hovers over an inline element. HOWEVER, I want the
hidden element positioned at a location of my choosing relative to
that inline element.

Is this possible?

The best I can do is use "position: absolute" on the hidden block
with no top/left position defined. The problem is, the block always
appears to the right of the inline element. I can't move it!!

What if I want the element to appear BELOW the inline element, lined
up with the left border of the element? How do I do that?

Example demo: http://sunshine.rahul.net/~unicorn/test2.html
(Test in Firefox or Opera; doesn't work in IE)

================================================== ==============
CSS:
ul { margin: 0; padding: 0; }
li { list-style: none; margin: 0; padding: 0; display: inline; }
li div { border: 1px solid red; display: none; position: absolute; }
li:hover div { display: inline; background: yellow; }

HTML:
<ul>
<li>item 1
<div>hidden<br>block 1</div></li>
<li>item2
<div>hidden<br>block 2</div></li>
</ul>
================================================== ==============

If I change the "li: hover div" definition to "display: block" then
the block always appears at the left edge of the page, not relative
to the inline element. Setting "position: relative" puts the hidden
element into the normal flow, which messes up the appearance of the
page; the element should be outside the normal flow.

Any suggestions? Help!

-Alex
Jul 3 '06 #1
6 6448
Els
axlq wrote:
I've spent most of the day struggling with what I thought would be a
trivial problem.

I have a hidden element that appears, outside of the normal flow,
when the mouse hovers over an inline element. HOWEVER, I want the
hidden element positioned at a location of my choosing relative to
that inline element.

Is this possible?

The best I can do is use "position: absolute" on the hidden block
with no top/left position defined. The problem is, the block always
appears to the right of the inline element. I can't move it!!

What if I want the element to appear BELOW the inline element, lined
up with the left border of the element? How do I do that?

Example demo: http://sunshine.rahul.net/~unicorn/test2.html
(Test in Firefox or Opera; doesn't work in IE)

================================================== ==============
CSS:
ul { margin: 0; padding: 0; }
li { list-style: none; margin: 0; padding: 0; display: inline; }
li div { border: 1px solid red; display: none; position: absolute; }
li:hover div { display: inline; background: yellow; }

HTML:
<ul>
<li>item 1
<div>hidden<br>block 1</div></li>
<li>item2
<div>hidden<br>block 2</div></li>
</ul>
================================================== ==============

If I change the "li: hover div" definition to "display: block" then
the block always appears at the left edge of the page, not relative
to the inline element. Setting "position: relative" puts the hidden
element into the normal flow, which messes up the appearance of the
page; the element should be outside the normal flow.
Give <liposition:relative, so that it forms the reference for the
position:absolute and the top and left values on the <div>.

--
Els http://locusmeus.com/
accessible web design: http://locusoptimus.com/
Jul 3 '06 #2
In article <37***************************@40tude.net>,
Els <el*********@tiscali.nlwrote:
>Give <liposition:relative, so that it forms the reference for the
position:absolute and the top and left values on the <div>.
See, I *knew* it was simple! That worked well. Thanks! And to
think I struggled for 6 hours not knowing position:relative had that
effect.

-A
Jul 3 '06 #3
In article <37***************************@40tude.net>,
Els <el*********@tiscali.nlwrote:
>Example demo: http://sunshine.rahul.net/~unicorn/test2.html

Give <liposition:relative, so that it forms the reference for the
position:absolute and the top and left values on the <div>.
I was overjoyed that this seemed to fix the problem, however....

It turns out that it worked only for Firefox, but not Opera.

Opera behaves as if the inline elements are left-justified. If I
left-justify them, Opera still puts the hidden blocks to the right
of its associated inline element.

I'm using Opera 8.51 because Opera 9 seems too buggy in other ways.

Any ideas?

-Alex
Jul 4 '06 #4
Els
axlq wrote:
In article <37***************************@40tude.net>,
Els <el*********@tiscali.nlwrote:
>>Example demo: http://sunshine.rahul.net/~unicorn/test2.html

Give <liposition:relative, so that it forms the reference for the
position:absolute and the top and left values on the <div>.

I was overjoyed that this seemed to fix the problem, however....

It turns out that it worked only for Firefox, but not Opera.

Opera behaves as if the inline elements are left-justified. If I
left-justify them, Opera still puts the hidden blocks to the right
of its associated inline element.

I'm using Opera 8.51 because Opera 9 seems too buggy in other ways.

Any ideas?
It seems indeed that Opera (I'm using 8.54) has a bug in this case.
You are right about it behaving as if the inline elements are
left-justified - I added some extra text to the first <li>, and the
placing of the second <li>'s <divmoves up exactly the amount of
space needed for the text of the first <li>.

Also, it isn't a problem with the <uland <liconstruction in itself
- the same thing goes wrong if you wrap it all in divs and spans: as
soon as you center align the lot, everything is centered, except for
the absolute positioned items.

So far, I haven't even found a workaround, other than setting an
explicit width on the <ul>, so that the left side of the <ul*is* the
left side of the first <li>. Not exactly a solution in a real website
environment :\

--
Els http://locusmeus.com/
accessible web design: http://locusoptimus.com/
Jul 4 '06 #5
In article <1g*****************************@40tude.net>,
Els <el*********@tiscali.nlwrote:
>axlq wrote:
>>>Example demo: http://sunshine.rahul.net/~unicorn/test2.html

It seems indeed that Opera (I'm using 8.54) has a bug in this case.
You are right about it behaving as if the inline elements are
left-justified - I added some extra text to the first <li>, and the
placing of the second <li>'s <divmoves up exactly the amount of
space needed for the text of the first <li>.

Also, it isn't a problem with the <uland <liconstruction in itself
- the same thing goes wrong if you wrap it all in divs and spans: as
soon as you center align the lot, everything is centered, except for
the absolute positioned items.

So far, I haven't even found a workaround, other than setting an
explicit width on the <ul>, so that the left side of the <ul*is* the
left side of the first <li>. Not exactly a solution in a real website
environment :\
Yes, that solution won't really work because I have no way of
knowing in advance what the width of the <ulwill be.

I can think of two other workarounds, and I can't figure out how to
implement either of them:

1. One workaround is to make Opera behave like IE, which doesn't
show the hidden boxes. To do this, one needs to hide the :hover
CSS rules from Opera. I have no idea how to do this. A web search
reveals all sorts of ways to hide CSS from Opera 5 and lower, or
Opera 7 and lower, but so far I can't figure out how to hide CSS
from Opera 8 and lower.

2. Another workaround is to have some sort of conditional comments
in the HTML to eliminate the centering for Opera. Unfortunately,
conditional comments seem to be a Microsoft hack, not supported
by Opera as far as I can tell. I guess I could use javascript to
detect the browser and modify the centering div somehow, but I'd
rather not resort to that.

-A
Jul 4 '06 #6
Followup:
In article <e8**********@blue.rahul.net>, axlq <ax**@spamcop.netwrote:
>I can think of two other workarounds, and I can't figure out how to
implement either of them:

1. One workaround is to make Opera behave like IE, which doesn't
show the hidden boxes. To do this, one needs to hide the :hover
CSS rules from Opera. I have no idea how to do this. A web search
reveals all sorts of ways to hide CSS from Opera 5 and lower, or
Opera 7 and lower, but so far I can't figure out how to hide CSS
from Opera 8 and lower.

2. Another workaround is to have some sort of conditional comments
in the HTML to eliminate the centering for Opera. Unfortunately,
conditional comments seem to be a Microsoft hack, not supported
by Opera as far as I can tell. I guess I could use javascript to
detect the browser and modify the centering div somehow, but I'd
rather not resort to that.
What I ended up doing on the site I'm developing is to define a
CSS text-centering class and hide it from Opera. So now my list
items are left justified in Opera, but that's OK. I put this in the
<headsection of my site pages:

<style type="text/css" media="scReen"><!-- /* hide from Opera */
..ctr { text-align: center; }
--></style>

Evidently that hack works for Opera version 8 and lower. I haven't
tested with Opera 9; hopefully with Opera 9 it won't be necessary.
Then I use <div class="ctr"to center the list items in all
browsers except Opera.

-A
Jul 4 '06 #7

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

Similar topics

14
by: Zenobia | last post by:
Hello folks, Is it possible to position an item within a <td> element? For instance see below. The table has multiple rows, one for each database record. Each row has 3 hrefs associated with it...
3
by: Markus Ernst | last post by:
Hello Reading the follwing document: http://www.w3.org/TR/WD-positioning-970131#In-flow it seems very clear that position:relative should be relative to the parent element. So in the following...
2
by: Martin Geisler | last post by:
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQBDNmLx6nfwy35F3TgRAtjIAJ9ryEjr0kaaEapRD0z1bHQYmKi+1wCdEOZC /wY2033SyIVl0za07v8RMkk= =6BZ+ -----END PGP SIGNATURE-----
4
by: spivee | last post by:
I'm having an odd type of issue. I want to be able to pass an element name in my javascript event and find the location of the element, be it a div, span, img whatever, specifically the top and...
6
by: Gérard Talbot | last post by:
Hello fellow stylers, When trying this page http://www.gtalbot.org/BrowserBugsSection/PercentualRelativePositioning.html I get different rendered layouts with IE 6, IE 7 beta 2, Firefox...
5
by: André Hänsel | last post by:
Hi, I want to make a horizontal navigation with the second level beneath the first level. The items of the second level shall appear left aligned with their corresponding first level item. To...
2
by: drillbatting | last post by:
Hi, I have a site with a heap of small menus in various elements. It looks something like this (inline style's etc for readability): <div>
14
by: David C. Stone | last post by:
Is there a way in CSS to adjust the baseline position of text marked up with either <sup></supor <sub></sub>, relative to the surrounding text? Reason for asking is that the default rendering in...
4
by: HoangTuanSu | last post by:
I have just got a javascript code from my friend. I've modified it for my purpose but a problem happens. First, here's my code html <body> <table align="center" width="60%" height="100%"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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,...

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.