473,698 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6482
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:rel ative, so that it forms the reference for the
position:absolu te 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*********@ti scali.nlwrote:
>Give <liposition:rel ative, so that it forms the reference for the
position:absol ute 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:relati ve had that
effect.

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

Give <liposition:rel ative, so that it forms the reference for the
position:absol ute 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*********@ti scali.nlwrote:
>>Example demo: http://sunshine.rahul.net/~unicorn/test2.html

Give <liposition:rel ative, so that it forms the reference for the
position:abso lute 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 <liconstructi on 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*********@ti scali.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 <liconstructi on 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**********@b lue.rahul.net>, axlq <ax**@spamcop.n etwrote:
>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
21918
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 (for edit, delete and update). I want to position these 3 href items in the same columns, which would be posible if the span could be positioned - for instance on the extreme right of the td in which it is contained.
3
19774
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 test case element1 and element2 should be placed side by side inside a centered white container element: http://www.markusernst.ch/test.htm
2
3867
by: Martin Geisler | last post by:
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQBDNmLx6nfwy35F3TgRAtjIAJ9ryEjr0kaaEapRD0z1bHQYmKi+1wCdEOZC /wY2033SyIVl0za07v8RMkk= =6BZ+ -----END PGP SIGNATURE-----
4
6357
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 left attributes. I have defined my element like so... ### .css file... #mydiv { position:absolute;
6
6079
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 1.5.0.2 and Opera 9.0 build 8367. Firefox 1.5 and Opera 9 will just ignore the CSS declaration
5
2069
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 visualize it: Entry1 Entry2 Entry3 Entry4 Entry3.1 Entry3.2 Entry3.3
2
5359
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
37058
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 most browsers always increases the spacing between the line of text containing these elements and those above/below that lack it. I can easily reduce the size of the subscript or superscript
4
3467
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%" border="0" cellpadding="0" cellspacing="0"> <tr height="100"> <td width="20%" height="114">abc</td> <td width="80%">def</td>
0
9166
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...
1
8899
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
8871
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
7737
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
5861
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
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
2007
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.