html - 缩放 div 背景图像

标签 html css

我有一个 png,上面有各种社交登录按钮图像。我可以使用以下 CSS 类让它们只显示我想要的图像:

.sign-in-with-facebook {
    width: 430px;
    height: 88px;
    background-image: url("/static/social-media-icons/social-sign-in-buttons.png");
    background-position: -184px -110px;
}
.sign-in-with-google {
    width: 430px;
    height: 88px;
    background-image: url("/static/social-media-icons/social-sign-in-buttons.png");
    background-position: -184px -401px;
}
.sign-in-with-twitter {
    width: 430px;
    height: 88px;
    background-image: url("/static/social-media-icons/social-sign-in-buttons.png");
    background-position: -184px -207px;
}

然后像下面这样添加 div 将使我的图像出现在我的页面上:

<div class="sign-in-with-twitter"></div>

首先,这是处理这样一张图片的合理方法吗?

其次,我的主要问题是我想缩小这些按钮,使它们更小,因为它们在原始 png 中相当大。我试过使用 background-sizemax-widthmax-height,将它们包裹在另一个 div 中,等等,但没有成功迄今为止。非常感谢您的帮助!

最佳答案

  1. 是的!这是一种合理的命名方式 Spriting
  2. 最好的方法是缩小它,使用一些光栅编辑工具(如 photoshop)

关于html - 缩放 div 背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31372718/

相关文章:

CSS 列网格排序问题

iphone - HTML Newsletter - iOS 上同一行的链接

html - 截断隐藏单选按钮

html - 带有 HTML 标签的 Cognito 自定义消息

html - CSS 显示内联 block : delete the blank space

javascript - 如何增加文本框中的值

javascript - 边缘将 .jpg 图像显示为随机颜色的正方形

html - 转换后文本模糊 : translate and it is adjacent to another element with an animation

javascript - 无法使用 React 中的 defaultValue 属性渲染 <select> 上的默认值

html - Bootstrap 3 div定位