html - 使用 CSS 和 spritesheet 中的多个图像设计按钮样式

标签 html css button styling

我在 sprite 表中有以下图像,想用它来设置按钮样式:

enter image description here

我已经尝试了所有我能想到的(甚至是伪元素),但我无法让它工作。我曾认为这样的事情应该有效:

.ui-button {
height:45px;
background-image: url(../button.png), url(../button.png), url(../media/button.png);
background-size: 8px 45px, 8px 45px, 3px 45px !important;
background-position: -63px -1px, -77px -1px, -73px -1px; 
background-repeat: no-repeat, no-repeat, repeat;
}

但事实并非如此。背景大小位是我正在使用的 Sprite 表中每个 block 的大小,位置是 Sprite 表中每个部分的左上角坐标。显然我做错了什么。什么?

编辑:这是整张图片:

enter image description here

最佳答案

这是我用 JSFiddle 尝试过的:

http://jsfiddle.net/Kpusc/

.ui-button {
    height:45px;
    width:18px;
    background: url(http://i.stack.imgur.com/ipKrd.png);
    background-position: -72px -1px;
    background-repeat: no-repeat;
    position:relative;
    border:0;
}

.ui-button:before {
    content:"";
    display:block;
    height:45px;
    width:8px;
    background: url(http://i.stack.imgur.com/ipKrd.png);
    background-position: -64px -1px;
    background-repeat: no-repeat;
    position:absolute;left:0;top:0;
}

 .ui-button:after {
     content:"";
     display:block;
     height:45px;
     width:8px;
     background: url(http://i.stack.imgur.com/ipKrd.png);
     background-position: -78px -1px;
     background-repeat: no-repeat;
     position:absolute;right:0;top:0;
 }

不幸的是,我只能将它设为 34px。因为我不能让中心内容重复。

我想你需要使中心部分至少比 60px 宽,以便它可以作为 .ui-button 背景图像应用(或者可能将其完全作为一个单独的文件,所以有可能重复)。

我想知道是否还有其他解决方法。

关于html - 使用 CSS 和 spritesheet 中的多个图像设计按钮样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12952234/

相关文章:

javascript - 样式化 HTML 选择/选项元素

html - ASP.Net MVC 4 在提交表单时设置 'onsubmit'

javascript - 在 Jquery 中滚动到顶部和滚动到底部

java - 为 HBox 设置背景图像 - JavaFX

css - Angular JS 中搜索文本中的 Material 图标

ios - 按钮触摸事件

html - 鼠标悬停在被标签包围的 div 按钮上,为什么?

css - 页面的文本和框中心

javascript - 使用 ajax 附加 html 后,Jquery 方法不适用于按钮

objective-c - Objective-C : Programmatically create a UIImageView