css如何实现button按钮的点击效果

css实现button按钮点击效果的方法:1、创建html文件;2、添加html代码架构;3、在body标签中使用button标签设计一个按钮;4、添加script标签并写入css样式代码来实现按钮点击效果;5、通过浏览器方式查看设计效果。


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>


我们的服务
专业提供中小企业网站建设.公司网站建设.外贸网站建设.营销型网站建设,响应式网站建设,商城网站定制,手机网站,微信小程序定制.php应用开发服务,公司成立于2014年,8年专注网站建设,秉承“以客户为根本,以科技为核心,以市场为导向”的经营理念;服务电话13714666846(微信同号)

声明:本站所有作品(图文、音视频)均由用户自行上传分享,或互联网相关知识整合,仅供网友学习交流,若您的权利被侵害,请联系 管理员 删除。

本文链接:http://news.ew35.com/