css3小标题制作
使用伪元素制作小标题
通过 ::before 或 ::after 伪元素添加装饰性内容,结合 content 属性插入符号或文字。例如实现左侧竖线效果:
h3 {
position: relative;
padding-left: 15px;
}
h3::before {
content: "";
position: absolute;
left: 0;
top: 2px;
bottom: 2px;
width: 3px;
background: #3498db;
}
渐变背景标题
利用 linear-gradient 创建色带效果,适合现代化设计风格:
h4 {
background: linear-gradient(90deg, #f72585 0%, #4cc9f0 100%);
color: white;
padding: 8px 15px;
display: inline-block;
border-radius: 4px;
}
边框组合样式
通过多重边框和阴影增强层次感:
h2 {
border-bottom: 2px solid #2b2d42;
box-shadow: 0 1px 0 rgba(255,255,255,0.4);
padding-bottom: 6px;
text-transform: uppercase;
font-size: 1.2em;
letter-spacing: 1px;
}
图标嵌入标题
使用 background-image 嵌入SVG或字体图标:
h5 {
background: url('icon.svg') no-repeat left center;
padding-left: 30px;
background-size: 20px;
line-height: 1.5;
}
3D立体效果
通过文字阴影创造立体感:
h1 {
text-shadow:
0 1px 0 #ccc,
0 2px 0 #bbb,
0 3px 0 #aaa,
0 4px 5px rgba(0,0,0,0.1);
color: #333;
}
响应式标题设计
使用视窗单位适应不同屏幕:
h2 {
font-size: calc(1rem + 1vw);
margin: 2vh 0;
border-left: 5px solid currentColor;
padding-left: 1vw;
}
动态悬停效果
添加交互状态提升体验:
h3 {
transition: all 0.3s ease;
border-bottom: 2px dotted transparent;
}
h3:hover {
color: #e63946;
border-bottom-color: currentColor;
}
