javascript - Advanced sibling selector -


this question has answer here:

i can't quite head around this. have following construct:

<div class="container">      n = 0 ...          <a href="some url">link n</a>      endfor       each link in ".container"           <div class="poptip"></div>      endfor </div> 

and example be:

<div class="container">      <a href="some url">link 1</a>      <a href="some url">link 2</a>      <a href="some url">link 3</a>       <div class="poptip">some content related link 1 retreived ajax</div>      <div class="poptip">...</div>      <div class="poptip">...</div> </div> 

now hurdle, trying show .poptip on hover on anchor tag, , works fine if there 1 link (which case). in case there's >1 link, last 1 work. current css (sass style) doesn't quite work in >1 cases:

.producttooltip {   position: relative; } .producttooltip a:hover + div {   display: block; } 

i cannot change structure of html, container > links followed poptips. can mark poptips , anchor tags unique identifiers e.g. <a href="some url" rel="identifier">link 1</a><div class="poptip" rel="identifier"></div>, can't quite figure out if in css can create general selector goes (pseudo):

a:hover + div[rel=a.rel] {     display: block } 

so question is, can construct marked in pure css, or have use js trickery (which can, prefer css). hope 1 of guys more clever me.

edit: just gonna clarify - cannot change structure of html. neatest solution wrap each element it's equivalent poptip, entire conundrum fact cannot this.

in case, can way:

$('a').on('hover', function() {   $('.poptip').eq($(this).index()).show(); }, function() {   $('.poptip:visible').hide(); }); 

it tough css alone. then, have provided css solution below. have if wanna consider css solution.


you can via css itself. although there lot of plugins, lets this. first, need hovering element, in case, link.

<a href="#">hover me!</a> 

next should tool tip. can have <span> , put inside link.

<a href="#">hover me!<span class="tooltip">hello, world!</span></a> 

now comes real css part.

a span {display: none; position: absolute; color: #fff; background: #000; padding: 5px;} {position: relative;} a:hover span {display: block; text-align: center;} 

snippet

a span {display: none; position: absolute; color: #fff; background: #000; padding: 5px;}  {position: relative;}  a:hover span {display: block; text-align: center;}
<a href="#">hover me!<span class="tooltip">hello, world!</span></a>

this 1 of pure css solution. can see working fiddle here.


however, there lot of plugins, keep concept base , work hover-cards , tool tips. examples include:


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -