跳转到帖子
在手机APP中查看

一个更好的浏览方法。了解更多

OKCCN - XenForo & IPS Plugin Marketplace

主屏幕上的全屏APP,带有推送通知、徽章等。

在iOS和iPadOS上安装此APP
  1. 在Safari中轻敲分享图标
  2. 滚动菜单并轻敲添加到主屏幕
  3. 轻敲右上角的添加按钮。
在安卓上安装此APP
  1. 轻敲浏览器右上角的三个点菜单 (⋮) 。
  2. 轻敲添加到主屏幕安装APP
  3. 轻敲安装进行确认。
  • 选择语言

CSS Styling Buttons

推荐的帖子

  • 行政经理

CSS Styling Buttons


CSS Styling Buttons

With CSS, different HTML buttons can be styled in many ways.

The most common CSS properties for styling buttons are:

  • background-color - defines the background color of a button
  • color - defines the text color of a button
  • border - defines the border of a button
  • padding - defines the space between the text and the border of a button
  • border-radius - adds rounded corners to a button
  • box-shadow - adds shadows to a button
  • text-align - centers the text of a button
  • font-size - defines the font size of the text on a button
  • text-decoration - removes the underline for <a> elements used as buttons
  • cursor - changes the mouse cursor when hovering over the button

Buttons are typically created with the HTML <button> element, the <input type="button"> element, or an <a> element styled as a button.


CSS Basic Button Styling

Example

A basic button styling for different HTML elements:

.button {
  background-color: red;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  cursor: pointer;
}
Try it Yourself »

CSS Button Colors

The CSS background-color property is used to define the background color of a button.

The CSS color property is used to define the text color of a button.

Example

Buttons with different colors:

.button1 {background-color: #04AA6D;} /* Green */
.button2 {background-color: #008CBA;} /* Blue */
.button3 {background-color: #f44336;} /* Red */
.button4 {background-color: #e7e7e7; color: black;} /* Gray */
.button5 {background-color: #555555;} /* Black */
Try it Yourself »


CSS Button Sizes

The CSS font-size property is used to define the font size for the text on a button:

Example

Buttons with different font size:

.button1 {font-size: 10px;}
.button2 {font-size: 12px;}
.button3 {font-size: 16px;}
.button4 {font-size: 20px;}
.button5 {font-size: 24px;}
Try it Yourself »

The CSS padding property is used to define the space between the text and the border of a button:

Example

Buttons with different padding:

.button1 {padding: 10px 24px;}
.button2 {padding: 12px 28px;}
.button3 {padding: 14px 40px;}
.button4 {padding: 32px 16px;}
.button5 {padding: 16px;}
Try it Yourself »

CSS Rounded Buttons

The CSS border-radius property is used to add rounded corners to a button:

Example

Buttons with different rounded corners:

.button1 {border-radius: 2px;}
.button2 {border-radius: 4px;}
.button3 {border-radius: 8px;}
.button4 {border-radius: 12px;}
.button5 {border-radius: 50%;}
Try it Yourself »

CSS Button Borders

The CSS border property is used to define the border of a button:

Example

Buttons with different borders:

.button1 {border: 2px solid #04AA6D;}
.button2 {border: 2px dotted #008CBA;}
.button3 {border: 2px dashed #f44336;}
.button4 {border: 1px solid #e7e7e7;}
.button5 {border: 1px solid #555555;}
Try it Yourself »

Button Subpages

Continue learning about CSS buttons:

  • Button Hover Effects - hover, shadow, disabled, width
  • Button Groups - horizontal/vertical groups, animated buttons



参与讨论

你可立刻发布并稍后注册。 如果你有帐户,立刻登录发布帖子。

游客
回帖…

帐户

导航

搜索

搜索

配置浏览器推送通知

Chrome (安卓)
  1. 轻敲地址栏旁的锁形图标。
  2. 轻敲权限 → 通知。
  3. 调整你的偏好。
Chrome (台式电脑)
  1. 点击地址栏中的挂锁图标。
  2. 选择网站设置。
  3. 找到通知选项并调整你的偏好。