1

I'm attempting to use :target in CSS to correctly position anchor tags below the static header in this webpage.

On that page, each of the images has a block similar to this:

.anchor:target {
  padding-top: 18vh;
}
.anchor {
  margin-top:2vh;
}

div.figure_image {
  width:80%;
  margin-left:auto;
  margin-right:auto;
  text-align:center;
}

figcaption {
  width: 65%;
  font-weight:bold;
  font-size:1.5vmin;
  margin-left:auto;
  margin-right:auto;
  padding-bottom:3vh;
}
<a class="anchor" name="fig3"></a>
<div class="figure_image">
  <figure>
    <a href="../Images/Articles/JMRC_43_Image03.TIFF">
      <img src="../Images/Articles/JMRC_43_fig03.JPG" />
    </a>
    <figcaption>Figure 3: Close-up of the “Balade at the Reverance of 
      Our Lady” stanza, Clopton chantry chapel, Holy Trinity, 
      Long Melford.
    </figcaption>
  </figure>
</div>  

That contains the image, a link to a larger version of the image, and a caption.

This all works great in Firefox 48.0.1 on the Mac. However, when I open it in another browser the styling for .anchor:target does not work. I've tired Safari 9.1.2 and Chrome 54.0.2840.98 and had someone try it in Chrome on Windows (they didn't give me the version) and in all cases it does not seem to be working properly -- the image appears underneath the static header. My thought is that either :target or vh is not supported, but everything I've read suggests that these are very mature css elements that should work with the versions of the browsers I've tested with. While I have jquery on the page for Hypothes.is, I'd rather not write an extensive jquery solution if css will do the trick, so I'm hoping someone might be able to tell me if I'm either formatting things poorly or if there's something else I'm simply not considering.

Minal Chauhan
  • 6,025
  • 8
  • 21
  • 41
medievalmatt
  • 427
  • 2
  • 12

1 Answers1

1

What needs to happen for the css as I have it above to work in Chrome or Safari is that the anchor tag must display as block or inline-block. Firefox will handle it if it's displayed as the default inline. Making a negative margin will fix any padding issue.

.anchor:target {
    padding-top: 18vh;
    display: block;
    margin-top: -18vh;
    }
medievalmatt
  • 427
  • 2
  • 12