怎么用css实现button按钮的点击效果

发布时间:2022-12-15 10:13:39 作者:iii
来源:亿速云 阅读:97

本文小编为大家详细介绍“怎么用css实现button按钮的点击效果”,内容详细,步骤清晰,细节处理妥当,希望这篇“怎么用css实现button按钮的点击效果”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

1.首先创建一个html文件。

2.在html文件中添加html代码架构。

<!DOCTYPE html>
<html>
    <head>
<meta charset="UTF-8">
        <title>按钮点击效果</title>
    </head>
    <body>
    </body>
</html>

3.然后在html代码架构中的body标签里面使用button标签设计一个按钮。

<button class="primary-btn">主要按钮</button>

4.在html架构中的html标签里面添加style标签并写入css样式代码来实现按钮点击效果。

<style>
.primary-btn {
  font-size: 14px;
  color: #fff;
  height: 44px;
  padding: 0 15px;
  background-color: #07c160;
  border: 1px solid #07c160;
  line-height: 1.2;
  text-align: center;
  border-radius: 2px;
  cursor: pointer;
  transition: opacity 0.2s;
  outline: none;
  position: relative;
}
.primary-btn::before {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  background-color: #000;
  border: inherit;
  border-color: #000;
  border-radius: inherit;
  transform: translate(-50%, -50%);
  opacity: 0;
  content: ' ';
}
.primary-btn:active::before {
  opacity: 0.1;
}
</style>

5.最后可通过浏览器方式阅读html文件查看设计效果。

完整示例代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>按钮点击效果</title> 
<style>
.primary-btn {
  font-size: 14px;
  color: #fff;
  height: 44px;
  padding: 0 15px;
  background-color: #07c160;
  border: 1px solid #07c160;
  line-height: 1.2;
  text-align: center;
  border-radius: 2px;
  cursor: pointer;
  transition: opacity 0.2s;
  outline: none;
  position: relative;
}
.primary-btn::before {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  background-color: #000;
  border: inherit;
  border-color: #000;
  border-radius: inherit;
  transform: translate(-50%, -50%);
  opacity: 0;
  content: ' ';
}
.primary-btn:active::before {
  opacity: 0.1;
}
</style>
</head>
<body>
  <button class="primary-btn">主要按钮</button>
</body>
</html>

读到这里,这篇“怎么用css实现button按钮的点击效果”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. css 多种背景的使用场景和技巧、优点介绍
  2. css设置背景图片布满全屏的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

css button

上一篇:如何使用css实现分页功能

下一篇:怎么使用css实现文字循环滚动效果

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》