1. 视觉设计原则:
2. 常见应用场景:
• 导航菜单:采用「底边线+字体加粗」组合
css
nav-item.active {
border-bottom: 3px solid 2196F3;
font-weight: 600;
color: 1565C0;
• 数据表格:使用半透明背景色+左侧标识条
css
tr.selected {
background: rgba(33, 150, 243, 0.1);
position: relative;
tr.selected::before {
content: '';
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 4px;
background: 2196F3;
• 卡片选择:增加6-8px的外边框并提升海拔高度
css
card.selected {
border: 2px solid 2196F3;
box-shadow: 0 8px 16px rgba(0,0,0,0.1);
transform: translateY(-2px);
3. 交互动画实现:
css
/ 平滑过渡 /
selected {
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
/ 涟漪效果 /
@keyframes ripple {
from { transform: scale(0); opacity: 0.5 }
to { transform: scale(2); opacity: 0 }
selected-effect::after {
content: '';
position: absolute;
background: rgba(33, 150, 243, 0.3);
border-radius: 50%;
animation: ripple 0.6s linear;
4. 可访问性要求:
5. 响应式适配技巧:
6. 框架实现示例(React):
jsx
function SelectableList({ items }) {
const [selectedId, setSelectedId] = useState(null);
return (
{items.map(item => (
key={item.id}
className={`list-item ${selectedId === item.id ? 'selected' : ''}`}
onClick={ => setSelectedId(item.id)}
role="option
aria-selected={selectedId === item.id}
{item.text}
))}
);
最佳实践建议:
1. 保持选中状态样式在全局范围内一致
2. 避免同时存在多个主要选中状态
3. 对重要操作保留二次确认机制
4. 在表单场景中默认选中最常用选项
5. 提供明确的取消选中方式
通过合理运用这些设计模式和技术实现,可以创建直观且高效的选中状态交互体验,同时满足现代Web可访问性标准。记得在不同设备和浏览器中进行全面测试,确保视觉和交互的一致性。
版权声明: 知妳网保留所有权利,部分内容为网络收集,如有侵权,请联系QQ793061840删除,添加请注明来意。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态
