Log in

View Full Version : How to Fix position on hover



tfit
03-12-2008, 11:07 AM
Hi all
I searched a reasonable time to find an answer for my problem;
I have a menubar and when I hover over the links it shows the content. My problem is that the data moves around with the link. I like it to remain on a fixed place. Is this possible with css?

Here is the code


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
<title>futureistoday homepage</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
<!--
#menuitem {list-style: none; margin: 0; padding: 0;
}

@media all {
#menuitem { text-align: center; }
}

#menuitem li {bottom: 11px; display: inline; line-height: 1.2em; margin: 0; padding: 0;
position: relative;
}

#menuitem a, #menuiten a:link, #menuitem a:visited {background: #900; border: 1px solid #FFF;
bottom: 2px; color: #FFF; display: inline; height: 1em; margin: 0; padding: 3px 5px 3px 5px;
position: relative; right: 2px; text-decoration: none;
}

#menuitem #active a, #menuitem #active a:link, #menuitem #active a:visited, #menuitem #active a:hover {
background: #369; border-bottom: none; border-left: 1px solid #9CC; border-right: 1px solid #9CC;
border-top: 1px solid #9CC; bottom: 0; color: #FFF; margin: 0;
}

#menuitem a:hover {background: #C00; bottom: 1px; color: #FFF; right: 1px;
}

#menuitem li a span {display: none;}

#menuitem li a:hover span {display: block; position: absolute; top: 190px; left:0px; width: 150px; height: 150px; color: #AAA; background: black; text-align: center; padding: 5px; margin: 10px;
z-index: 1; font: 10px Verdana, sans-serif;
}
-->
</style>
</head>

<body>
<ul id="menuitem">
<li><a href="#">Home<span> text to be shown </span></a></li>
<li><a href="#">Products<span> some other values </span></a></li>
<li><a href="#">Services<span> info about services </span></a></li>
<li><a href="#">Support<span> contact information </span></a></li>
</ul>
</body>
</html>

Medyman
03-12-2008, 02:49 PM
Do you have a sample page that shows the problem?

I don't quite understand your explanation.

tfit
03-12-2008, 07:21 PM
Medyman,

Thanks for your time and attention. I put up a temporary server to do tests.
http://futureistoday.homeunix.net:8080/line-up-problem.html
To try to clarify what I want; when I hover over the links the text that shows up lines up with the left side of te link. Since every link has a different position the text moves accordingly. I like it to have a fixed position.

Medyman
03-13-2008, 03:25 AM
Ahh, I see what you mean.

You could fix this one of two ways.

1) Javascript
2) Change the left css property for each of the <span> tags. You can apply a seperate id to each of these and add the appropriate negative positioning.



HTML:

<ul id="menuitem">
<li><a href="#">Home<span id="home"> text to be shown </span></a></li>
<li><a href="#">Products<span id="products"> some other values </span></a></li>
<li><a href="#">Services<span id="services"> info about services </span></a></li>
<li><a href="#">Support<span id="support"> contact information </span></a></li>
</ul>

CSS:

span#home { left:0; }
span#products { left:-20px; }
span#services { left:-50px; }
span#support { left:-60px; }

Adjust values accordingly, of course.

tfit
03-13-2008, 04:17 AM
Medyman,

I was afraid that would be the case. I'm wondering how you did the measurement? Can I do measurement on this or is this a trial and error proces?
Thanks anyway.

tfit
03-13-2008, 04:21 AM
Sorry medyman I thought i thanked you but i shows up with me :mad:. No reason to thank myself is there!!

Medyman
03-13-2008, 03:25 PM
Medyman,

I was afraid that would be the case. I'm wondering how you did the measurement? Can I do measurement on this or is this a trial and error proces?
Thanks anyway.


Unfortuantely, it's trial and error. But it shouldn't be too hard with just four elements.

You can alternatively use something like this:
http://www.dynamicdrive.com/dynamicindex5/linkinfo.htm

tfit
03-16-2008, 03:00 AM
Medyman,

The design was wrong!!:mad: I thought i could use it as base to build on. But like you said you will end up with tooltips. You couldn't put anchors in it and the content wouldn't remain on screen when you move the mouse.
I have been changing and trying for two days now and I have something else I hope will do the trick. I found Nathan Smith and Joshua Kaufman method's a good point into the direction. The problem now is the page moves up because I use a Iframe. I know an Iframe is a big no-no, but the technique makes sence. Especially since it doesn't break it for screenreaders. See will backman's latest podcast. Can I fix the body and the iframe so it won't move up? Here is the code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>futureistoday revised version</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
<!--
/* remove those scrollbars */
body {background-color: #6F99FF; overflow: hidden; }

/* styling the menu */
#menuitem {display: block; list-style-type: none; padding: 0px; padding-left: 1em; margin: 0px; white-space: nowrap; height: 0em; }
#menuitem li {position: relative; top: 1px; z-index: 2; display: block; font:bold 75% verdana;
float: left; padding: 0px; margin: 0px; xmargin-right: 0.6em; border: 1px solid; }
#menuitem li a {display: block; padding:0.2em 1em 0.2em 1em; color:#000; text-decoration:none; }
#menuitem li.inactive {margin-top: 2px; border-color: #356DDD; background-color: #9AA8CA; }
#menuitem li.active {padding-bottom: 2px; border-color:#356DDD; background-color: #8093B9;}
#menuitem .inactive a:hover {cursor:hand; background: #F8F9FB; }

/* styling the iframe */
#in_frame {position:relative; width:95%; height:70%; border:1px solid #6c6; padding:4px; background-color:#fff; clear:both;}
#in_frame iframe {width:100%; height:100%; border:solid 1px black;}
#iframeContent {position: relative; width:999px; height:200px; }

/* lets get this off the screen */
#asection {position: absolute; top: 8000px; left: 0px; height: 100px;}
#bsection {position: absolute; top: 9000px; left: 0px; height: 100px;}
-->

</style>
</head>

<body>

<ul id="menuitem" class="menuitem">
<li class="active"><a href="" target="content">home</a></li>
<li class="inactive"><a href="#section1" target="content">Products</a></li>
<li class="inactive"><a href="#section2" target="content">Services</a></li>
<li class="inactive"><a href="" target="content">Support</a></li>
<li class="inactive"><a href="http://codylindley.com/CSS/297/the-iframe-slide" target="content"> nathan smith</a></li>
<li class="inactive"><a href="http://bsdtalk.blogspot.com/" target="content">will beckman</a></li>
</ul>

<pre>
<a id="asection" name="section1">
3-Day Chargeback Workshop
The recently released VMware Chargeback Workshop provides you with an interactive knowledge
sharing workshop on IT chargeback models, including presentation of industry best practices,
special considerations relevant to virtual infrastructure, presentation of a set of chargeback
tools and an example report using third-party chargeback metering software.

The VMware Chargeback Workshop will help you:
* Accelerate the design and deployment of chargeback processes and solutions for Virtual
Infrastructure.
* Gain financial flexibility and value from a virtual environment.
* Validate feasibility of chargeback in a virtual environment with proof-of-concept.
</a></pre>

<pre>
<a id="bsection" name="section2">
Oracle Releases Oracle VM Oracle VM is free server virtualization software that fully
supports both Oracle and non-Oracle applications, and is three times more efficient than
other server virtualization products. Backed by Oracle's world-class support organization,
customers now have a single point of enterprise-class support for their entire virtualization
environments, including the Linux operating system, Oracle Database, Fusion Middleware,
and Application software. These and other Oracle products are certified with Oracle VM.
Download software and documentation, guest templates, and kernels and modules from the new
Virtualization Technology Center.
</a></pre>

<!-- screenreaders end of content. Everything else is vanity :-) -->
<div id="in_frame">
<iframe name="content" src="" id="iframeContent" frameborder="0"></iframe>
</div>

</body>
</html>


and here is a link:


http://futureistoday.homeunix.net:8080/revised-version.html


A bit off-topic: after 1 post and within 9 hours my site :) (two non-linked pages) got visited by a googlebot. How is that for marketing! :p

tfit
03-16-2008, 03:02 AM
Btw,

I thought stylesheets where for styling. Sometimes it looks more like programming:D

tfit
08-29-2008, 11:35 AM
I need to mention that the link doesn't work anymore so I won't waste your time