css链接制作
CSS链接样式设计
基础链接样式
使用a选择器定义链接的默认状态,设置颜色、文本装饰等属性:
a {
color: #0066cc;
text-decoration: none;
transition: color 0.3s ease;
}
悬停效果
通过:hover伪类添加鼠标悬停时的交互效果:
a:hover {
color: #ff6600;
text-decoration: underline;
}
访问后状态
使用:visited控制已访问链接的样式:
a:visited {
color: #663399;
}
激活状态:active定义鼠标点击瞬间的样式:
a:active {
color: #ff0000;
}
高级链接效果
按钮式链接
将链接转换为按钮样式:
a.button {
display: inline-block;
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border-radius: 5px;
text-align: center;
}
a.button:hover {
background-color: #45a049;
}
下划线动画
创建动态下划线效果:
a.underline {
position: relative;
}
a.underline::after {
content: '';
position: absolute;
width: 0;
height: 2px;
bottom: 0;
left: 0;
background-color: #ff6600;
transition: width 0.3s;
}
a.underline:hover::after {
width: 100%;
}
响应式链接设计
移动端优化
增大触摸区域提高可用性:
@media (max-width: 768px) {
a {
padding: 8px 12px;
font-size: 18px;
}
}
暗黑模式适配
根据系统偏好调整链接颜色:
@media (prefers-color-scheme: dark) {
a {
color: #5eb0ff;
}
a:visited {
color: #b388ff;
}
}






