设置flex后<a>标签嵌套图标未横向排列问题排查
解决社交图标纵向排列的问题
你的核心问题是**.social-media容器没有设置display: flex**——div默认是块级元素,而你给<a>标签设置了display: flex,导致每个<a>变成块级元素自动换行,最终呈现纵向排列的效果。
修正方案:
- 给
.social-media添加display: flex,让子元素横向排列 - 可选:用
gap属性设置图标间距,比手动加margin更简洁 - 修正CSS拼写错误:CSS仅识别美式拼写,
background-colour需改为background-color,colour改为color
修改后的完整CSS代码:
.social-media a{ text-decoration: none; border: 3px solid #0ef; border-radius: 50%; justify-content: center; align-items: center; display: flex; padding: 10px; color: #0ef; background: transparent; transition: 0.5s; width: 40px; height: 40px; font-size: 20px; } .social-media a:hover{ background-color: #0ef; /* 修正拼写错误 */ color: #1f242d; /* 修正拼写错误 */ } .social-media{ width: 50%; padding: 20px 0; display: flex; /* 添加flex布局 */ gap: 15px; /* 可选:设置图标间的间距,可按需调整 */ }
修改后社交图标会横向排列,hover交互效果也能正常生效。
内容的提问来源于stack exchange,提问作者INI
相关产品推荐
相关产品推荐

