gpt4 book ai didi

css - html5 按钮背景图像状态

转载 作者:太空狗 更新时间:2023-10-29 16:50:40 24 4
gpt4 key购买 nike

我有一个按钮,我正在尝试将此图像应用到它的背景中,绿色是关闭状态,黄色是点击状态。我可以在两个状态都在同一个文件中的情况下使用此图像,还是需要将它们分开?这种情况的标准是什么,css是如何工作的?

enter image description here

<button>click me</button>
button {
background-image:url('button.png');
}

最佳答案

是的,您绝对可以使用它们。它们称为 CSS Sprites。

这是一个 fiddle

button{
width:196px;
height:64px;
background-image:url("http://i.stack.imgur.com/BSVeQ.gif");
background-repeat:no-repeat;
}
button:active{
background-position:0px -64px;
}

关于css - html5 按钮背景图像状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21946579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com