温馨提示×

温馨提示×

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

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

CSS按钮怎么实现

发布时间:2022-02-25 10:52:37 来源:亿速云 阅读:98 作者:小新 栏目:web开发

这篇文章将为大家详细讲解有关CSS按钮怎么实现,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

  例一:

  首先,我们将给出按钮的一般样式,包括其活动状态。重要的是要注意相对定位,因为它将帮助我们稍后定位::before元素:

  CSS

  .a_demo_one{

  background-color:#ba2323;

  padding:10px;

  position:relative;

  font-family:'OpenSans',sans-serif;

  font-size:12px;

  text-decoration:none;

  color:#fff;

  border:solid1px#831212;

  background-image:linear-gradient(bottom,rgb(171,27,27)0%,rgb(212,51,51)100%);

  border-radius:5px;

  }

  .a_demo_one:active{

  padding-bottom:9px;

  padding-left:10px;

  padding-right:10px;

  padding-top:11px;

  top:1px;

  background-image:linear-gradient(bottom,rgb(171,27,27)100%,rgb(212,51,51)0%);

  }

  然后,我们使用::before伪元素创建灰色容器。使用绝对的定位来定位我们的元素:

  CSS

  .a_demo_one::before{

  background-color:#ccd0d5;

  content:"";

  display:block;

  position:absolute;

  width:100%;

  height:100%;

  padding:8px;

  left:-8px;

  top:-8px;

  z-index:-1;

  border-radius:5px;

  box-shadow:inset0px1px1px#909193,0px1px0px#fff;

  }

  例二:

  CSS

  .a_demo_two{

  background-color:#6fba26;

  padding:10px;

  position:relative;

  font-family:'OpenSans',sans-serif;

  font-size:12px;

  text-decoration:none;

  color:#fff;

  background-image:linear-gradient(bottom,rgb(100,170,30)0%,rgb(129,212,51)100%);

  box-shadow:inset0px1px0px#b2f17f,0px6px0px#3d6f0d;

  border-radius:5px;

  }

  .a_demo_two:active{

  top:7px;

  background-image:linear-gradient(bottom,rgb(100,170,30)100%,rgb(129,212,51)0%);

  box-shadow:inset0px1px0px#b2f17f,inset0px-1px0px#3d6f0d;

  color:#156785;

  text-shadow:0px1px1pxrgba(255,255,255,0.3);

  background:rgb(44,160,202);

  }

  由于伪元素的位置取决于其父元素,因此一旦父元素向下移动几个像素,就必须向上移动具有相同像素数量的伪元素。

  CSS

  .a_demo_two::before{

  background-color:#072239;

  content:"";

  display:block;

  position:absolute;

  width:100%;

  height:100%;

  padding-left:2px;

  padding-right:2px;

  padding-bottom:4px;

  left:-2px;

  top:5px;

  z-index:-1;

  border-radius:6px;

  box-shadow:0px1px0px#fff;

  }

  .a_demo_two:active::before{

  top:-2px;

  }

  例三:

  我们要做的第一件事就是创造简单的部分。在这里,你会注意到一个右边距,这是为了补偿伪元素的宽度,如果你想让按钮居中。

  .a_demo_three{

  background-color:#3bb3e0;

  font-family:'OpenSans',sans-serif;

  font-size:12px;

  text-decoration:none;

  color:#fff;

  position:relative;

  padding:10px20px;

  border-left:solid1px#2ab7ec;

  margin-left:35px;

  background-image:linear-gradient(bottom,rgb(44,160,202)0%,rgb(62,184,229)100%);

  border-top-right-radius:5px;

  border-bottom-right-radius:5px;

  box-shadow:inset0px1px0px#2ab7ec,0px5px0px0px#156785,0px10px5px#999;

  }

  .a_demo_three:active{

  top:3px;

  background-image:linear-gradient(bottom,rgb(62,184,229)0%,rgb(44,160,202)100%);

  box-shadow:inset0px1px0px#2ab7ec,0px2px0px0px#156785,0px5px3px#999;

  }

  然后是伪元素:

  .a_demo_three::before{

  content:"·";

  width:35px;

  max-height:29px;

  height:100%;

  position:absolute;

  display:block;

  padding-top:8px;

  top:0px;

  left:-36px;

  font-size:16px;

  font-weight:bold;

  color:#8fd1ea;

  text-shadow:1px1px0px#07526e;

  border-right:solid1px#07526e;

  background-image:linear-gradient(bottom,rgb(10,94,125)0%,rgb(14,139,184)100%);

  border-top-left-radius:5px;

  border-bottom-left-radius:5px;

  box-shadow:inset0px1px0px#2ab7ec,0px5px0px0px#032b3a,0px10px5px#999;

  }

  .a_demo_three:active::before{

  top:-3px;

  box-shadow:inset0px1px0px#2ab7ec,0px5px0px0px#032b3a,1px1px0px0px#044a64,2px2px0px0px#044a64,2px5px0px0px#044a64,6px4px2px#0b698b,0px10px5px#999;

  }


CSS按钮怎么实现

关于“CSS按钮怎么实现”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

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

css
AI