文本按钮

创建于 2024-12-03 / 36
字体: [默认] [大] [更大]

了解如何使用 CSS 设置文本按钮的样式。



如何为文本按钮设置样式

步骤 1) 添加 HTML:

实例

<button class="btn success">Success</button>
<button class="btn info">Info</button>
<button class="btn warning">Warning</button>
<button class="btn danger">Danger</button>
<button class="btn default">Default</button>
步骤 2) 添加 CSS:

为了获得"文本按钮"的外观,我们移除了默认的背景颜色和边框:

实例

.btn {
  border: none;
  background-color: inherit;
  padding: 14px 28px;
  font-size: 16px;
  cursor: pointer;
  display: inline-block;
}

/* 鼠标悬停 */
.btn:hover {background: #eee;}

.success {color: green;}
.info {color: dodgerblue;}
.warning {color: orange;}
.danger {color: red;}
.default {color: black;} 亲自试一试 »

具有单独背景的文本按钮

悬停时具有特定背景颜色的文本按钮:

实例

.btn {
    border: none;
    background-color: inherit;
    padding: 14px 28px;
    font-size: 16px;
    cursor: pointer;
    display: inline-block;
}

/* Green */
.success {
    color: green;
}

.success:hover {
    background-color: #4CAF50;
    color: white;
}

/* Blue */
.info {
    color: dodgerblue;
}

.info:hover {
    background: #2196F3;
    color: white;
}

/* Orange */
.warning {
    color: orange;
}

.warning:hover {
    background: #ff9800;
    color: white;
}

/* Red */
.danger {
    color: red;
}

.danger:hover {
    background: #f44336;
    color: white;
}

/* Gray */
.default {
    color: black;
}

.default:hover {
    background: #e7e7e7;
} 亲自试一试 »

转到我们的 CSS 按钮教程,了解有关如何设置按钮样式的更多信息。



0 人点赞过