javascript - 从导入的图标列表图像更改呈现的图标大小

标签 javascript jquery css wordpress

我需要找到一种方法来更改单个图像文件中的一些图标的大小,这些图标由 Wordpress 的 Visual Composer 插件中的脚本模块呈现。

示例 html 代码:

<ul class="ts-social-icons simple">
<li style="margin: 5px;  padding: 0px;" class="ts-social-icon  center">
    <a href="mailto:BLABLA@gmail.com" class="ts-social-email " target="_blank" style="">
        <i style="top: 9px;" class="ts-social-email"></i>
    </a>
</li>
<li style="margin: 5px;  padding: 0px;" class="ts-social-icon  center">
    <a onclick="return false" "="" href="#" class="ts-social-phone " target="_blank" style="">
        <i "="" 9px;="" top:="" class="ts-social-phone style="></i>
    </a>
</li>
<li style="margin: 5px;  padding: 0px;" class="ts-social-icon  center">
    <a onclick="return false" "="" href="#" class="ts-social-cell " target="_blank" style="">
        <i "="" top:="" class="ts-social-cell style="></i>
    </a>
</li>
<li style="margin: 5px;  padding: 0px;" class="ts-social-icon  center">
    <a href="http://www.asd.com/" class="ts-social-portfolio " target="_blank" style="">
        <i style="top: 9px; " class="ts-social-portfolio"></i>
    </a>
</li>
<li style="margin: 5px;  padding: 0px;" class="ts-social-icon  center">
    <a href="http://www.asd.com/" class="ts-social-link " target="_blank" style="">
        <i style="top: 9px; " class="ts-social-link"></i>
    </a>
</li>
<li style="margin: 5px;  padding: 0px;" class="ts-social-icon  center">
    <a href="http://https://www.facebook.com/asd" class="ts-social-facebook " target="_blank" style="">
        <i style="top: 9px; " class="ts-social-facebook"></i>
    </a>
</li>

当前的 CSS

.ts-social-icons li a i {
  background: url("images/team-socials-black.png") no-repeat scroll center center rgba(0, 0, 0, 0) !important;
}

如果我在这里更改高度或宽度,我得到的都是重复的图标:

.ts-logo-icons li a i, .ts-social-icons li a i, .ts-teammate-icons li a i {
  display: inline-block;
  height: 20px;
  margin: 10px auto;
  text-align: center;
  text-decoration: none;
  width: 20px;
  z-index: 999;
}

也许有一种方法可以用 Javascript 或 jquery 代替 CSS 来实现?

最佳答案

我不建议您使用拼接来执行此操作,因为如果不大量编写使用数字计算在用户调整页面大小时调整 div 大小的代码,就无法获得您想要的控制。

相反,我会使用以下方法之一:

第一种方式:

改用 img 元素:

<img width="100%" height="100%"/>

然后它将始终调整到它的父 div(当前为 20px)


第二种方式:

使用 background-image(就像您已经使用的那样,但不是拼接),并添加:

background-size:100% 100%;

现在您已经了解了它是如何处理单个图像的,想象一下进行拼接会有多困难。但是如果你确实想走这条路,你需要使用第二种方式,只需将其更改为 px 坐标而不是 % 并在页面调整大小时更改它们(带有类似 jQuery 的东西)

关于javascript - 从导入的图标列表图像更改呈现的图标大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26198839/

相关文章:

html - 如何将水平的家谱变成垂直的?

javascript - jQuery - 单击元素后,获取 li 的数据项并将删除线应用于 li 中的文本(动画?)

javascript - MySQL 类型错误 : Cannot read property 'query' of undefined

javascript - 从 KML 中提取路径

javascript - 隐藏和显示输入不起作用

jQuery XML 解析(使用 Ajax)在 Chrome 中不起作用(但在 IE、FF、Opera、Safari 中起作用)

javascript - 将包含特定格式日期的字符串解析为 Javascript 中的 Date 对象

jquery - Android 上的输入类型日期验证

jquery - 为什么添加 "helper: "clone";"到这个 ui-draggable 元素会阻止它被拖动?

css - Angular ngx-bootstrap 隐藏选项卡内容