html - 在图像( map )上自定义绝对定位的 FontAwesome 标记

标签 html css font-awesome

我使用 FontAwesome 在 map 上绝对定位了标记,这样我就可以调整 map 的大小并且图像保持相同的相对位置。

每个都有一个数字,FontAwesome 字符是一个圆圈,但我希望使用伪元素并将数字定位在圆圈中并有一个标记。

这可能吗?我尝试了许多不同的方法,但没有一种对我有用。

请看下面的例子;

.map-marker {
    position: absolute;
    font-size: 20px;
    text-shadow: 1px 1px 1px #000;
}
#one {
    top: 70px;
    left: 20px;
}
#one:after {
    content: "\f111";
    font-family: 'FontAwesome';
}
#two {
    top: 50px;
    left: 260px;
}
#two:after {
    content: "\f111";
    font-family: 'FontAwesome';
}
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="map_container">
  <img src="http://geology.com/world/world-map-clickable.gif"/>
  <a href="#"><div id="one" class="map-marker" aria-hidden="true">1</div></a>
  <a href="#"><div id="two" class="map-marker" aria-hidden="true">2</div></a>
</div>

最佳答案

您可以使 a 处于绝对位置,然后在其上使用 before(或 after)。这样,您将在其中包含两个不同的元素,您可以使用每个元素的 z-index 来制作数字下方的伪元素。

您还可以简化您的 CSS,因为 onetwo 的伪元素相同

.map-marker {
  position: absolute;
  font-size: 20px;
  text-shadow: 1px 1px 1px #000;
  text-decoration:none;
}
.map-marker span {
  position:relative;
  z-index: 2;
  color:#fff;
}
.map-marker:before {
  content: "\f111";
  font-family: 'FontAwesome';
  position: relative;
  right: -14px;
  z-index: 0;
}
#one {
  top: 70px;
  left: 20px;
}

#two {
  top: 50px;
  left: 260px;
}
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="map_container">
  <img src="http://geology.com/world/world-map-clickable.gif" />
  <a href="#" id="one" class="map-marker">
    <span aria-hidden="true">1</span>
  </a>
  <a href="#" id="two" class="map-marker">
    <span aria-hidden="true">2</span>
  </a>
</div>

关于html - 在图像( map )上自定义绝对定位的 FontAwesome 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47062722/

相关文章:

html - 在使用剪辑路径的 svg 矩形元素上重复背景图像

javascript - Javascript 中的 PS3 原创主题

javascript - 按条件为 contenteditable div 文本字段中的字母着色

css - Bootstrap 3 - 图像始终与包含行的高度相同

html - 将字体图标附加到文本字符串中的最后一个单词并防止换行

javascript - 使用 html/js 的动画和随机化器

javascript - CSS:不同分辨率的缩放问题

css - 如何在 css 中使用很棒的字体

html - 无法显示 Font Awesome 图像

javascript - Bootstrap 4 Popover 内联样式问题