css按钮自适应如何实现原理及代码

当她不爱你的时候,就是你从他生活中消失的时候,在第一时间离开她,骄傲地过属于自己的生活。同时,你也希望她能幸福快乐,希望她找到属于她的未来。我们就轻轻拥抱一下回忆里的温暖。
原理:利用a标签和i标签各自一个背景组合成为按钮,达到自适应。
复制代码
代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
.btn a{text-decoration:none;}
.btn{display: inline-block; background: url(s_btn.png) no-repeat 0 0; height: 22px; line-height: 22px; color: #666; vertical-align:top;}
.btn i{display:block;font-style: normal; font-size: 12px; padding: 0 10px; background:url(s_btn.png) no-repeat right -22px; }
.btn:hover{text-decoration: none;color:#4c8136;background-position: 0 -44px;}
.btn:hover i{background-position: right -66px;}
.btn:active{background-position: 0 -88px;}
.btn:active i{background-position: right -110px;}
.btn_disabled, .btn_disabled:hover{background: url(../img/s_btn.png) no-repeat 0 -132px;cursor: default;}
.btn_disabled i, .btn_disabled:hover i, .s_btn_disabled:active i{background-position: right -154px;color:#999;}
</style>
</head>
<body>
<a rel="nofollow noopener noreferrer" href="#" class="btn"> <i>这是按钮</i> </a>
<a rel="nofollow noopener noreferrer" href="#" class="btn"> <i>按钮</i> </a>
</body>
</html>

效果:

本文css按钮自适应如何实现原理及代码到此结束。每天开心笑,累了就睡觉,醒了就微笑。生活,没什么大不了!小编再次感谢大家对我们的支持!

您可能有感兴趣的文章
css让页脚保持在底部位置的四种方案

CSS如何使用Flex和Grid布局如何实现3D骰子

Flex布局史上最简单使用语法教程

新的CSS 伪类函数 :is() 和 :where()示例详解

纯CSS打字动画的如何实现示例