首页 > 解决方案 > 将锚的背景图像定位在锚文本的左侧?

问题描述

我正在尝试获取我为锚设置的背景图像作为图标,在锚文本旁边并调整大小 - 以便图像和文本彼此对齐,但我不确定如何去做这个。

代码:

a {
    font-family: sans-serif;
    font-size: 14pt;
}
<a style="background: url('https://cdn1.iconfinder.com/data/icons/ninja-things-1/1772/ninja-simple-128.png');">
    Text here
</a>

标签: htmlcssanchor

解决方案


试试这个代码。

a {
  font-family: sans-serif;
  font-size: 14pt;
  background-image: url('https://cdn1.iconfinder.com/data/icons/ninja-things-1/1772/ninja-simple-128.png');
  background-size: 15px;
  background-repeat: no-repeat;
  background-position: left;
  padding-left: 15px;
}
<a href="#">Text here</a>


推荐阅读