css设置按钮样式

by Ashwini Sheshagiri

通过Ashwini Sheshagiri

Buttons have become an inevitable part of front end development. Thus, it is important to keep in mind a few things before you start styling buttons. I have gathered some of the ways of styling buttons using CSS. You can combine most of the methods in order to create a new style, too. To create CSS for gradients, you may use https://uigradients.com.

按钮已成为前端开发的必然部分。 因此,在开始设计按钮样式之前,请记住一些注意事项。 我已经收集了一些使用CSS设置按钮样式的方法。 您也可以组合大多数方法来创建新样式。 要为渐变创建CSS,可以使用https://uigradients.com 。

一个简单的“入门”按钮 (A simple “Get Started” button)

.btn {
background: #eb94d0;

/ *创建渐变* / (/* to create the gradients */)

background-image: -webkit-linear-gradient(top, #eb94d0, #2079b0);  background-image: -moz-linear-gradient(top, #eb94d0, #2079b0);  background-image: -ms-linear-gradient(top, #eb94d0, #2079b0);  background-image: -o-linear-gradient(top, #eb94d0, #2079b0);  background-image: linear-gradient(to bottom, #eb94d0, #2079b0);

/ *给出btn的弯曲边缘* / (/* to give the curved edge for the btn */)

-webkit-border-radius: 28;  -moz-border-radius: 28;  border-radius: 28px;
text-shadow: 3px 2px 1px #9daef5;  -webkit-box-shadow: 6px 5px 24px #666666;  -moz-box-shadow: 6px 5px 24px #666666;  box-shadow: 6px 5px 24px #666666;
font-family: Arial;  color: #fafafa;  font-size: 27px;  padding: 19px;  text-decoration: none;}

/ *悬停按钮* / (/*button on hover*/)

.btn:hover {
background: #2079b0;
background-image: -webkit-linear-gradient(top, #2079b0, #eb94d0);  background-image: -moz-linear-gradient(top, #2079b0, #eb94d0);  background-image: -ms-linear-gradient(top, #2079b0, #eb94d0);  background-image: -o-linear-gradient(top, #2079b0, #eb94d0);  background-image: linear-gradient(to bottom, #2079b0, #eb94d0);
text-decoration: none;}

透明背景按钮 (Transparent background button)

.btn {

/ *文字颜色* / (/* Text color */)

color: #0099CC;

/ *删除背景色* / (/* Remove background color */)

background: transparent;

/ *边框粗细,线条样式和颜色* / (/* Border thickness, line style, and color */)

border: 2px solid #0099CC;

/ *将曲线添加到边界角* / (/* Adds curve to border corners */)

border-radius: 6px;

/ *使字母大写* / (/* Make letters uppercase */)

border: none;      color: white;      padding: 16px 32px;      text-align: center;      display: inline-block;      font-size: 16px;      margin: 4px 2px;      -webkit-transition-duration: 0.4s; /* Safari */      transition-duration: 0.4s;      cursor: pointer;      text-decoration: none;      text-transform: uppercase;}.btn1 {      background-color: white;       color: black;       border: 2px solid #008CBA;}

/ *悬停按钮* / (/*button on hover*/)

.btn1:hover {      background-color: #008CBA;      color: white; }

具有CSS实体的按钮 (Button with CSS Entities)

You can find the complete list of CSS entities here: https://www.w3schools.com/cssref/css_entities.asp

您可以在此处找到CSS实体的完整列表: https : //www.w3schools.com/cssref/css_entities.asp

You can also use HTML entities, but they’re limited. https://www.w3schools.com/html/html_entities.asp

您也可以使用HTML实体,但是它们是有限的。 https://www.w3schools.com/html/html_entities.asp

.button {  display: inline-block;  border-radius: 4px;  background-color: #f4511e;  border: none;  color: #FFFFFF;  text-align: center;  font-size: 28px;  padding: 20px;  width: 200px;  transition: all 0.5s;  cursor: pointer;  margin: 5px;}
.button span {  cursor: pointer;  display: inline-block;  position: relative;  transition: 0.5s;}
.button span:after {
content: '\00bb';  /* CSS Entities. To use HTML Entities, use →*/
position: absolute;  opacity: 0;  top: 0;  right: -20px;  transition: 0.5s;}
.button:hover span {  padding-right: 25px;}
.button:hover span:after {  opacity: 1;  right: 0;}

带有点击动画的按钮 (Button with click animation)

CSS: (SCSS)

CSS:(SCSS)

$gray: #bbbbbb;
* {  font-family: 'Roboto', sans-serif;}
.container {  position: absolute;  top:50%;  left:50%;  margin-left: -65px;  margin-top: -20px;  width: 130px;  height: 40px;  text-align: center;}
.btn {      color: #0099CC; /* Text color */      background: transparent; /* Remove background color */      border: 2px solid #0099CC; /* Border thickness, line style, and color */      border-radius: 70px; /* Adds curve to border corners */      text-decoration: none;      text-transform: uppercase; /* Make letters uppercase */      border: none;      color: white;      padding: 16px 32px;      text-align: center;      text-decoration: none;      display: inline-block;      font-size: 16px;      margin: 4px 2px;      -webkit-transition-duration: 0.4s; /* Safari */      transition-duration: 0.4s;      cursor: pointer;}.btn1 {      background-color: white;       color: black;       border: 2px solid #008CBA;} .btn1:hover {      background-color: #008CBA;      color: white; }
b {  outline:none;  height: 40px;  text-align: center;  width: 130px;  border-radius:100px;  background: #fff;  border: 2px solid #008CBA;  color: #008CBA;  letter-spacing:1px;  text-shadow:0;  font:{    size:12px;    weight:bold;  }  cursor: pointer;  transition: all 0.25s ease;
&:active {    letter-spacing: 2px ;  }  &:after {    content:"";  }}.onclic {  width: 10px !important;  height: 70px !important;  border-radius: 50% !important;  border-color:$gray;  border-width:4px;  font-size:0;  border-left-color: #008CBA;  animation: rotating 2s 0.25s linear infinite;  &:hover {    color: dodgerblue;    background: white;  }}.validate {  content:"";  font-size:16px;  color: black;  background: dodgerblue;  border-radius: 50px;  &:after {    font-family:'FontAwesome';    content:" done \f00c";  }}
@keyframes rotating {  from {    transform: rotate(0deg);  }  to {    transform: rotate(360deg);  }}

Javascript: (JQuery)

Javascript:(jQuery)

$(function() {  $("#button").click(function() {    $("#button").addClass("onclic", 250, validate);  });
function validate() {    setTimeout(function() {      $("#button").removeClass("onclic");      $("#button").addClass("validate", 450, callback);    }, 2250);  }  function callback() {    setTimeout(function() {      $("#button").removeClass("validate");    }, 1250);  }});

带有图像的按钮 (Button with an image)

.btn {
background: #92c7eb; background-image: url(“http://res.freestockphotos.biz/pictures/15/15107-illustration-of-a-red-close-button-pv.png"); background-size: cover; background-position: center; display: inline-block; border: none; padding: 20px; width: 70px; border-radius: 900px; height: 70px; transition: all 0.5s; cursor: pointer;}.btn:hover{ width: 75px; height: 75px;}

带有图标的按钮 (Button with icons)

index.html:

index.html:

<div class="main"><button class="button" style="vertical-align:middle"><a href="#" class="icon-button twitter"><i class="icon-twitter"></i><span></span></button></a>  <div class="text"><strong>TWEET!</strong></div></div>

style.css:

style.css:

button{  border: none;  border-radius: 50px;}html,body {  font-size: 20px;  min-height: 100%;  overflow: hidden;  font-family: "Helvetica Neue", Helvetica, sans-serif;    text-align: center;}.text {  padding-top: 50px;  font-family: "Helvetica Neue", Helvetica, 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}.text:hover{  cursor: pointer;  color: #1565C0;}.main {  padding: 0px 0px 0px 0px;  margin: 0;  background-image: url("https://someimg");  text-align: center;  background-size: 100% !important;  background-repeat: no-repeat;  width: 900px;  height: 700px;  }
.icon-button {  background-color: white;  border-radius: 3.6rem;  cursor: pointer;  display: inline-block;  font-size: 2rem;  height: 3.6rem;  line-height: 3.6rem;  margin: 0 5px;  position: relative;  text-align: center;  -webkit-user-select: none;  -moz-user-select: none;  -ms-user-select: none;  user-select: none;  width: 3.6rem;}
.icon-button span {  border-radius: 0;  display: block;  height: 0;  left: 50%;  margin: 0;  position: absolute;  top: 50%;  -webkit-transition: all 0.3s;  -moz-transition: all 0.3s;  -o-transition: all 0.3s;  transition: all 0.3s;  width: 0;}.icon-button:hover span {  width: 3.6rem;  height: 3.6rem;  border-radius: 3.6rem;  margin: -1.8rem;}.twitter span {  background-color: #4099ff;}
/* Icons */.icon-button i {  background: none;  color: white;  height: 3.6rem;  left: 0;  line-height: 3.6rem;  position: absolute;  top: 0;  -webkit-transition: all 0.3s;  -moz-transition: all 0.3s;  -o-transition: all 0.3s;  transition: all 0.3s;  width: 3.6rem;  z-index: 10;}.icon-button .icon-twitter {  color: #4099ff;}
.icon-button:hover .icon-twitter {  color: white;}

结论 (Conclusion)

In this tutorial, you’ve learned how to customize buttons using CSS and a bit of Javascript if you need the “after click” function. You can also use CSS3ButtonGenerator to generate simple buttons. Feel free to ping me if you have any questions.

在本教程中,您学习了如何在需要“单击后”功能的情况下使用CSS和一些Javascript定制按钮。 您还可以使用CSS3ButtonGenerator生成简单的按钮。 如有任何疑问,请随时与我联系。

If you liked this article and if it helped you, do give some claps! ?

如果您喜欢这篇文章,并且对您有所帮助,请鼓掌! ?

翻译自: https://www.freecodecamp.org/news/a-quick-guide-to-styling-buttons-using-css-f64d4f96337f/

css设置按钮样式

css设置按钮样式_使用CSS设置按钮样式的快速指南相关推荐

  1. javafx css样式_使用CSS设置JavaFX饼图样式

    javafx css样式 渲染图表时, JavaFX默认提供某些颜色. 但是,在某些情况下,您想自定义这些颜色. 在此博客文章中,我将使用一个示例来更改JavaFX饼图的颜色,该示例打算在今天下午在2 ...

  2. gradient设置上下渐变_图解CSS: CSS渐变

    CSS的渐变主要分布在 conic-gradient()和repeating-conic-gradient()两个属性.在CSS中,CSS的渐变相当于图像,我们可以使用线性渐变(linear-grad ...

  3. css改火狐滚动条样式_纯css美化滚动条样式

    知乎的编辑器对于复制转发文章来说特别不友好(直接复制后代码乱码,字体变化,表格数据丢失),不太想过多重复编辑,只会编辑转发部分到这上面来,如感觉还不错,请跳转到:https://www.emperin ...

  4. 使用HTML语言和CSS开发商业站点_初识CSS

    第4章 初识CSS 一.CSS概述     1.什么事CSS         CSS全称为层叠样式表(Cascading Style Sheet),通常又称为风格样式表(Style Sheet),它是 ...

  5. css实现图片虚化_什么? CSS 阴影竟然还有这种骚操作 ?

    点击上方"IT平头哥联盟",选择"置顶或者星标" 与你一起成长- 原作者:cocoqiao 关于 CSS 阴影,之前已经有写过一篇,box-shadow 与 f ...

  6. css界面内容可滚动_带有CSS滚动捕捉点的直观滚动界面

    css界面内容可滚动 Scroll Snap Points are a native CSS-only technique that you can use to create layouts whe ...

  7. 不用电脑怎么设置苹果铃声_苹果手机怎么设置铃声?完整教程分享

    很多人的苹果手机铃声设置的都是用原始默认的铃声,因为苹果手机不支持直接将音乐设置为铃声,而且大多数人不清楚苹果怎么换铃声.当然安卓系统就没有这个问题啦.但是苹果的默认铃声听久了也挺腻的,鉴于有不少粉丝 ...

  8. ad19pcb设置恢复默认_电脑主板BIOS设置详解BIOS知识大全

    电脑主板BIOS设置详解-BIOS知识大全 什么是电脑BIOS,一般电脑主板都设置了电脑开机后一直按着Del键即可进入BIOS. 系统开机启动 BIOS,即微机的基本输入输出系统(Basic Inpu ...

  9. 计算机的硬盘 u盘启动,【电脑bios设置硬盘启动】电脑bios设置光驱启动_电脑bios设置u盘启动...

    2017-11-14 17:02:44 浏览量:94932 怎么在BIOS里设置硬盘启动?电脑在启动时会从硬盘寻找引导文件,从而启动系统,如果硬盘不是第一启动项,或者有两个硬盘,就会导致系统无法启动, ...

  10. 数据库助手连接MySQL设置_数据库简易设置助手下载_数据库简易设置助手官方版下载_3DM单机...

    <数据库简易设置助手>是一款数据库配置工具,能够高效便捷对数据库进行管理工作,他支持一件关闭开启数据库,并能够设置服务启动类型,支持一键设置jdk环境,支持系统中安装多个版本的JDk环境, ...

最新文章

  1. ubunntu安装php7.0_在 Ubuntu/Debian 下安装 PHP7.3 教程
  2. js filter 用法
  3. Delphi中使用IXMLHTTPRequest如何用POST方式提交带参
  4. BPDU tunnel技术简介
  5. 被声明为已否决 解决方法
  6. WebRTC直播课堂实践:实时互动是核心
  7. c#怎么做windows窗体小程序_个人想做微信小程序怎么做?
  8. 的使用_面部精华使用方法和使用步骤;
  9. chrome前端开发工具_精通Chrome开发人员工具:更高级别的前端开发技术
  10. celery监控服务器性能,Python:使用celery处理多个服务器上的参数列表
  11. 在ASP.NET的服务器端使用message box(Message box Server side in ASP.Net)
  12. 月薪多少最幸福,离你有多远?
  13. 人工智能与计算机发展史
  14. 如何实现电压、液位等模拟量信号的无线传输?
  15. 远程安全接入解决方案
  16. 什么是胖客户端和瘦客户端?什么是哑终端?(转)
  17. YARN 删除所有ACCEPTED任务的命令
  18. NF-ResNet:去掉BN归一化,值得细读的网络信号分析 | ICLR 2021
  19. 开天辟地第一人---盘古
  20. 【报告分享】2021中国住宿业市场网络口碑报告-中国饭店协会众荟(附下载)

热门文章

  1. 从零开始开发IM(即时通讯)服务端附源码
  2. BA无标度网络(一):规则网络生成
  3. 豆瓣评分8.9,这本Python经典入门书重磅升级
  4. 基于LEACH的随机网络生成无线传感器网络路由协议的仿真比较(Matlab代码实现)
  5. 低压差稳压器--AMS1117芯片简介 结构
  6. jseclipse的安装和使用
  7. 密码学在实际应用中的加密技术
  8. SpringBoot启动时报错
  9. 转载:discuz代码解析(一、初始化应用的过程)
  10. Camera_Engine_Rkisp_User_Manual