在现代网页设计中,我们经常会遇到一些特殊形状的按钮设计,其中"镂空的内凹圆角边框"是一种既美观又具有视觉冲击力的设计。这种按钮看起来像是从背景中雕刻出来,边框内凹且带有圆角,通过背景透出形成独特的视觉效果。
<!DOCTYPE html><html lang="zh-CN"><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>镂空内凹圆角边框按钮</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
margin: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.container {
text-align: center;
padding: 2rem;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 20px;
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
}
h1 {
color: white;
margin-bottom: 2rem;
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}
/* 按钮基础样式 */
.btn {
position: relative;
display: inline-block;
padding: 16px 32px;
margin: 12px;
font-size: 18px;
font-weight: bold;
text-decoration: none;
text-align: center;
border-radius: 12px;
cursor: pointer;
overflow: hidden;
transition: all 0.3s ease;
}
/* 镂空内凹效果实现 */
.btn-hollow {nav.xplwz.com
background: transparent;
color: white;
border: none;
box-shadow:
0 0 0 2px rgba(255, 255, 255, 0.3),
0 4px 12px rgba(0, 0, 0, 0.2);
}
.btn-hollow::before {
content: '';
position: absolute;
top: 2px;
left: 2px;mip.xplwz.com
right: 2px;
bottom: 2px;
background: inherit;
border-radius: 10px;
box-shadow:
inset 0 0 15px rgba(255, 255, 255, 0.5),
0 0 5px rgba(255, 255, 255, 0.2);
z-index: -1;
}
/* 悬停效果 */
.btn-hollow:hover {blog.xplwz.com
transform: translateY(-3px);
box-shadow:
0 0 0 2px rgba(255, 255, 255, 0.5),
0 6px 20px rgba(0, 0, 0, 0.3);
}
.btn-hollow:hover::before {navgation.krzwz.com
box-shadow:
inset 0 0 20px rgba(255, 255, 255, 0.7),
0 0 8px rgba(255, 255, 255, 0.3);
}
/* 点击效果 */
.btn-hollow:active {
transform: translateY(1px);
box-shadow:
0 0 0 2px rgba(255, 255, 255, 0.3),
0 2px 8px rgba(0, 0, 0, 0.2);
}
/* 不同颜色变体 */
.btn-primary::before {mip.krzwz.com
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
}
.btn-success::before {
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}
.btn-warning::before {blog.krzwz.com
background: linear-gradient(135deg, #ff9966 0%, #ff5e62 100%);
}
/* 说明部分 */
.explanation {navgation.qugwz.com
max-width: 600px;
margin: 2rem auto 0;
padding: 1.5rem;
background: rgba(255, 255, 255, 0.1);
border-radius: 12px;nav.qugwz.com
color: white;
}
.explanation h2 {navgation.vkqwz.com
margin-top: 0;
}
.code {mip.qugwz.com
background: rgba(0, 0, 0, 0.2);
padding: 1rem;
border-radius: 8px;
overflow-x: auto;
font-family: monospace;
} </style></head><body>
<div class="container">
<h1>镂空内凹圆角边框按钮</h1>
<a href="#" class="btn btn-hollow btn-primary">主要按钮</nav.tltwz.com >
<a href="#" class="btn btn-hollow btn-success">成功按钮</navgation.tltwz.com >
<a href="#" class="btn btn-hollow btn-warning">警告按钮</blog.vkqwz.com >
<div class="explanation">
<h2>实现原理</h2>
<p>这种效果通过以下CSS技术实现:</p>
<ul>
<li>使用<code>::before</code>伪元素创建内层</li>
<li>利用<code>box-shadow</code>的inset值创建内凹阴影效果</li>
<li>使用略微不同的尺寸和定位实现"镂空"效果</li>
<li>应用渐变背景增强视觉深度</li>
</ul>
<div class="code">/* 核心代码片段 */
.btn-hollow::before {
content: '';
position: absolute;
top: 2px;blog.tltwz.com
left: 2px;
right: 2px;nav.fkmwz.com
bottom: 2px;
background: inherit;
border-radius: 10px;mip.tltwz.com
box-shadow:
inset 0 0 15px rgba(255, 255, 255, 0.5),
0 0 5px rgba(255, 255, 255, 0.2);
z-index: -1;navgation.qhiwz.com
} </div>
</div>blog.fkmwz.com
</div></body></html>mip.fkmwz.com
通过巧用CSS伪元素和阴影特性,我们可以创建出视觉上复杂但代码简洁的内凹镂空按钮效果。这种方法无需使用图片或SVG,保持了代码的轻量性和可维护性,同时能够轻松适应不同尺寸和颜色变体。