title: How can I position a tooltip with respect to its parent element?
body: <p>I'm trying to make small image gallery.On :hover there should appear a tooltip on the left side of every image. My HTML code looks like this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.gallery {
    right: 247px;
    width: 220px;
  }
  
  .gallery li {
    display: inline;
    width: 100px;
    height: 100px;
    position: relative;
  }
  
  .gallery img {
    float: right;
    margin: 10px;
    box-shadow: 0 0 0 8px rgba(0, 0, 0, 0.3);
    -webkit-background-clip: padding-box;
    /* for Safari */
    background-clip: padding-box;
    /* for IE9+, Firefox 4+, Opera, Chrome */
  }
  
  .tooltip {
    width: 300px;
    height: 100px;
    display: none;
    position: absolute;
    right: -108px;
    top: 222px;
    z-index: 70;
    background-color: rgba(0, 0, 0, 0.4);
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(opacity=40)";
  }
  
  .gallery li:hover&gt;.tooltip {
    display: inline;
    z-index: 70;
  }
  
  .gallery li:hover {
    background: #fff;
  }
  
  .gallery li:hover img {
    box-shadow: 0 0 0 8px rgba(255, 255, 255, 1);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;ul class="gallery"&gt;
    &lt;li&gt;
      &lt;a href="#" class="thumb"&gt;&lt;img src="img/pillow.jpg" alt=""&gt;&lt;/a&gt;
      &lt;div class="tooltip"&gt;&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;a href="#" class="thumb"&gt;&lt;img src="" alt=""&gt;&lt;/a&gt;
      &lt;div class="tooltip"&gt;&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;a href="#" class="thumb"&gt;&lt;img src="" alt=""&gt;&lt;/a&gt;
      &lt;div class="tooltip"&gt;&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;a href="#" class="thumb "&gt;&lt;img src="" alt=""&gt;&lt;/a&gt;
      &lt;div class="tooltip"&gt;&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;a href="#" class="thumb"&gt;&lt;img src="" alt=""&gt;&lt;/a&gt;
      &lt;div class="tooltip"&gt;&lt;/div&gt;
    &lt;/li&gt;
  &lt;/ul&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The idea is, as said, that  .tooltip has position:absolute and it should appear to the left of hovered <code>&lt;li&gt;</code>, but somehow it appears at the same place every time. What can be the reason for it?</p>