CSS3 按钮

创建 CSS3 按钮可以通过组合样式属性和伪类来实现

复制代码
<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
  <button class="basic-button">基本按钮</button>
</body>
</html>

CSS (styles.css):

复制代码
/* 基本按钮样式 */
.basic-button {
  display: inline-block;
  padding: 10px 20px;
  font-size: 16px;
  background-color: #3498db;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

/* 悬停效果 */
.basic-button:hover {
  background-color: #2980b9;
}

创建了一个基本的按钮样式,然后使用 :hover 伪类来定义鼠标悬停时的效果。主要的样式属性包括:

  • padding:指定按钮的内边距,增加按钮的大小和点击区域。
  • font-size:设置按钮文本的字体大小。
  • background-color:按钮的背景颜色。
  • color:按钮文本的颜色。
  • border:按钮的边框样式。
  • border-radius:圆角边框,使按钮更加美观。
  • cursor:当鼠标悬停在按钮上时,指定光标形状。
  • transition:定义过渡效果,实现悬停时背景颜色平滑变化。
相关推荐
2013编程爱好者1 小时前
Vue工程结构分析
前端·javascript·vue.js·typescript·前端框架
小满zs2 小时前
Next.js第十一章(渲染基础概念)
前端
不羁的fang少年3 小时前
前端常见问题(vue,css,html,js等)
前端·javascript·css
change_fate3 小时前
el-menu折叠后文字下移
前端·javascript·vue.js
yivifu3 小时前
CSS Grid 布局详解(2025最新标准)
前端·css
o***Z4484 小时前
前端性能优化案例
前端
张拭心5 小时前
前端没有实际的必要了?结合今年工作内容,谈谈我的看法
前端·ai编程
姜太小白5 小时前
【前端】CSS媒体查询响应式设计详解:@media (max-width: 600px) {……}
前端·css·媒体
HIT_Weston5 小时前
39、【Ubuntu】【远程开发】拉出内网 Web 服务:构建静态网页(二)
linux·前端·ubuntu
百***06015 小时前
SpringMVC 请求参数接收
前端·javascript·算法