Position badge over corner of image automatically

前端 未结 4 1025
独厮守ぢ
独厮守ぢ 2020-12-04 15:55

I have a layout where images \"float\" within a certain area. The layout looks like this:

\"Layout

4条回答
  •  伪装坚强ぢ
    2020-12-04 16:49

    I did find one solution using jQuery. I don't prefer this because it noticably impacts page loading, but it is acceptable if nothing else will work. I'm more interested in NGLN's idea which seems promising but I haven't entirely figured out yet. However, since this thread has picked up a lot of traffic I thought I'd post one solution that I came up with for future readers to consider:

    Given this markup:

    Andrew_burleson_10_tile
    Houston
    T6 | Conduit | Infrastructure

    Same CSS as in question except:

    span.transect-badge { display: block; height: 20px; width: 20px; position: absolute; background: url('/images/transect-badge.png'); }
    

    Then this jQuery solves the problem:

    $(function() {
      $('img.canonical').load( function() {
        var position = $(this).position();
        $(this).next().css({ 'top': position.top+1, 'left': position.left+1 });
      });
    });
    

    Like I said, though, this incurs noticeable run-time on the client end, so I'd prefer to use a non JS solution if I can. I'll continue to leave this question open while I test out and give feedback on the other solutions offered, with hopes of finding one of them workable without JS.

提交回复
热议问题