用css样式定义圆角背景图片按钮根据文字自适应宽度的方法
2012-11-16 14:47
597 查看
CSS样式:
.setBottom a,.setBottom span,.popTishi .popIcon{background:url(../images/button.png) no-repeat;}
.setBottom{height:30px;position: relative;line-height:30px;}
.setBottom span{ position:absolute;height:30px;width:3px; display:inline-block;top:0; cursor:pointer;}
.setBottom span.spanLeft{left:-3px;}
.setBottom span.spanRight{right:-3px;}
.setBottom a{padding:0 20px; display:inline-block;}
.btnBlue a{ background-position:center -180px}
.btnBlue span.spanLeft{background-position:left -180px;}
.btnBlue span.spanRight{ background-position:right -180px;}
.btnBlue a:hover{background-position:center -150px;}
.btnBlue a:hover .spanLeft{background-position:left -150px;}
.btnBlue a:hover .spanRight{background-position:right -150px;}
.btnBlue a,.btnBlue a:visited{color:#fff;}
.btnBlue a:hover{color:#005383;}
html用法:
<div class="setBottom btnBlue fl">
<a href="#">
<span class="spanLeft"></span>
<span class="spanRight"></span>
搜索
</a>
</div>
样式中图片如下图所示:
.setBottom a,.setBottom span,.popTishi .popIcon{background:url(../images/button.png) no-repeat;}
.setBottom{height:30px;position: relative;line-height:30px;}
.setBottom span{ position:absolute;height:30px;width:3px; display:inline-block;top:0; cursor:pointer;}
.setBottom span.spanLeft{left:-3px;}
.setBottom span.spanRight{right:-3px;}
.setBottom a{padding:0 20px; display:inline-block;}
.btnBlue a{ background-position:center -180px}
.btnBlue span.spanLeft{background-position:left -180px;}
.btnBlue span.spanRight{ background-position:right -180px;}
.btnBlue a:hover{background-position:center -150px;}
.btnBlue a:hover .spanLeft{background-position:left -150px;}
.btnBlue a:hover .spanRight{background-position:right -150px;}
.btnBlue a,.btnBlue a:visited{color:#fff;}
.btnBlue a:hover{color:#005383;}
html用法:
<div class="setBottom btnBlue fl">
<a href="#">
<span class="spanLeft"></span>
<span class="spanRight"></span>
搜索
</a>
</div>
样式中图片如下图所示:
相关文章推荐
- CSS背景图片自适应文字宽度圆角按钮
- css圆角背景图片按钮-自适应内容大小
- 背景图片根据宽度自适应高度的方案
- 导航栏设置多个按钮、背景图、图片与文字按钮方法小结
- 按钮的背景图片根据状态的不同而显示不同的图片,网上有介绍相关的方法。
- 纯DIV+CSS圆角背景随按钮文字增多而增宽自适应,鼠标经过背景变化按钮型模块。
- 实现自适应宽度圆角按钮的方法
- div根据div内文字背景图自适应宽度
- css圆角背景图片按钮-自适应内容大小
- html 背景图片实现 宽度自适应,高度为背景图片高度 解决发案
- iOS开发--根据文字动态调整按钮(UIButton)宽度
- Android对于界面底部N个按钮平分屏幕宽度且保持按钮背景图片不变形的解决方案
- Android开发实现按钮点击切换背景并修改文字颜色的方法
- 【UGUI】UGUI 文字背景根据文字大小自适应
- CSS实现菜单背景自适应宽度的方法
- CSS自适应宽度圆角按钮
- less常用样式集,清除浮动、背景自适应、背景渐变、圆角、内外阴影、高度宽度计算。
- ios7系统圆角按钮有背景图片还显示为蓝色
- CSS背景图片自适应 根据浏览器分辨率大小自动伸缩
- js根据鼠标移动速度背景图片自动旋转的方法