This requires Javascript. In CSS, setting something on :hover or :focus or whatever, that state is temporary. Youâre no longer :hovering over something when the mouse isnât sitting over the link, right?
There is :target, which doesnât work in IE less than 9 I donât believe, which sortof does what you want: the user has to click another link to change the CSS. Seeingâs how itâs not cross-browser at a low level and requires your URL history to get polluted, I think Javascript is the better route.
One thing to mention: neither the current work-in-progress, nor the original nautical site, is keyboard friendly. Web sites should not require that the user has a mouse simply to work. CSS has :focus for a reason, and Javascript also has onfocus() and onblur() to complement onmouseover() and onmouseout(). Use the keyboard versions with every mouse version, and when you need :hover or onmouseover() on something that cannot normally receive keyboard focus (anything not an anchor or form input), you can add (the illegal in HTML4 but works everywhere and is perfectly fine in HTML5) a tabindex=â0â to those elements, so then with Javascript you can now haz onfocus() and onblur() events.
A last thing to keep in mind is, the ship site and your work in progress are okay as far as distance, but donât let your distance grow much between where the user does his/her action and where the image appears. For accessibility and usability reasons, try to keep the event and the result physically close to each other.
.popup span {
position:fixed;
Fixed is in relation to the userâs monitor and not the web site. You know, itâs as if you stuck a Post-It note on the userâs screen: it doesnât move when the user scrolls and stuff. I donât think you meant to use that. Position: absolute generally is what you want with these kinds of things.
Itâs âsaferâ (more stable) to make the positioned parent (the anchor) a block of some sort. Opera for example had issues with loosy goosy inlines being positioned parents, and Iâm not sure if this has been fixed yet. IE of course has been notorious for similar issues. Also, for IE, weâve learned we donât want to change someoneâs âstateâ (whether theyâre a block or not, setting display: or position: etc) on the pseudo-classes like :hover. IE is a whiny brat in that way.
.boatz {
set the width you want here. This will automagically limit the width of the anchors too;
}
/*all anchors in this ul*/
.boatz a {
display: block;
width: 100%; /*this Haslayout trigger taking the place of zoom and therefore passes the validator, if it matters. Width is already naturally 100% by default anyway so we haven't changed anything except trigger Haslayout for IE*/
position:relative;
text-decoration:none;
}
/*all images inside boat ul*/
.boatz img {
position: absolute;
display: block; /*abso-position is already block context; you only need this line if IE is squirrely without it. Otherwise, take this line out*/
width:350px;
padding:10px;
border:10px solid #000;
border-radius:10px;
margin-left:-9999px; /*IE likes margins better than "left" for some reason*/
top:170px;
left: 0; /*but set a left and top for stability*/
}
.boatz a:hover, .boatz a:focus {
give users some visual feedback on the anchor itself too, like underline or colour change or something;
}
.boatz a:hover img, .boatz a:focus img {
margin-left: 500px; /*set the image where you want it on hover/focus of anchor*/
}
</style>
</head>
<body>
<ul class="boatz">
<li><a id="boat1" href="#boat1">Ship 1 <img src="http://insurancecommissionrefund.com/testwebsite/wp-content/uploads/2012/04/AccomodationWorkBoats_2.jpg" [b] alt="I'm on a boat!"[/b]></a></li>
<li><a id="boat2" href="#boat2">Ship 2 <img src="http://insurancecommissionrefund.com/testwebsite/wp-content/uploads/2012/04/AccomodationWorkBoats_3.jpg" [b]alt="LIKE A BOSS"[/b]></a> </li>
</ul>
If the images arenât just fun decoration, they get an alt text that either describes the image, or âsaysâ whatever the image says to users (the meaning/reason for the images).
The idâs/hrefs on the anchors is so that if your page is long and the anchors are not already at the top, the user will not be brought up to the top of the page (what â#â does) when they click. You can remove the id if the anchor will ultimately go somewhere instead. Some people just click on links immediately without waiting to see if something pops up.
You can also put the images in CSS alone, which is when youâd use the span.
The span would refer to the anchorâs unique ID to each have a separate background image. If you do it this way, then the span is pre-styled as a abso-poâd block with dimensions and the background image, and all that changes on hover/focus is, again, the left or margin-left position. If you do it this way, Javascript would probably best be used to add/remove a class that sets if the span is on-screen or not. So youâd be setting the class on mouseover/onfocus and only removing it when another onmouseover/onfocus event occurs.