You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将文本置于底部导航栏每个图标的下方

实现导航图标下方显示文本的解决方案

修改步骤:

  • 将.menu__item的flex布局方向改为垂直,让图标和文本自动上下排列
  • 为.text类添加基础样式,设置颜色、字体大小和文本居中,确保显示在图标下方
  • 调整.menu__item的内边距,适配垂直布局的内容
  • 微调.menu__item.active的向上偏移量,避免激活状态下文本被遮挡

修改后的完整CSS代码:

html {
    box-sizing: border-box;
    --bgColorMenu : #1d1d27;
    --duration: .7s;   
}
html *,
html *::before,
html *::after {
    box-sizing: inherit;
}
body{
    margin: 0;
    display: flex;
    height: 100vh;
    overflow: hidden;
    align-items: center;
    justify-content: center;
    background-color: #d6cbd3;
    -webkit-tap-highlight-color: transparent;
    transition: background-color var(--duration);
}
.menu{
    margin: 0;
    display: flex;
    /* Works well with 100% width  */
    width: 32.05em;
    font-size: 1.5em;
    padding: 0 0.85em;
    position: relative;
    align-items: center;
    justify-content: center;
    background-color: var(--bgColorMenu);   
}
.menu__item{
    all: unset;
    flex-grow: 1;
    z-index: 100;
    display: flex;
    flex-direction: column; /* 改为垂直布局 */
    cursor: pointer;
    position: relative;
    border-radius: 50%;
    align-items: center;
    will-change: transform;
    justify-content: center;
    padding: 0.55em 0.2em 0.85em; /* 调整左右内边距适配垂直内容 */
    transition: transform var(--timeOut , var(--duration));   
}
.menu__item::before{
    content: "";
    z-index: -1;
    width: 4.2em;
    height: 4.2em;
    border-radius: 50%;
    position: absolute;
    transform: scale(0);
    transition: background-color var(--fduration), transform var(--duration);
}
.menu__item.active {
    transform: translate3d(0, -.6em , 0); /* 微调向上偏移量 */
}
.menu__item.active::before{   
    transform: scale(1);
    background-color: var(--bgColorItem);
}
.icon{   
    width: 2.6em;
    height: 2.6em;
    stroke: white;
    fill: transparent;
    stroke-width: 1pt;
    stroke-miterlimit: 10;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 400;
    margin-bottom: 0.3em; /* 图标和文本之间添加间距 */
}
.menu__item.active .icon {
    animation: strok 1.5s reverse;
}

@keyframes strok {
    100% {
        stroke-dashoffset: 400;
    }
}
.menu__border{
    left: 0;
    bottom: 99%;
    width: 10.9em;
    height: 2.4em;
    position: absolute;
    clip-path: url(#menu);
    will-change: transform;
    background-color: var(--bgColorMenu);
    transition: transform var(--timeOut , var(--duration));
}
.svg-container {
    width: 0;
    height: 0;
}

@media screen and (max-width: 50em) {
    .menu{
        font-size: .8em;
    }
}

.text{
    color: #fff; /* 设置文本颜色为白色 */
    font-size: 0.7em; /* 设置文本大小 */
    text-align: center; /* 文本居中 */
    white-space: nowrap; /* 防止文本换行 */
}

说明:

  • flex-direction: column 让.menu__item内部元素垂直排列,图标在上、文本在下
  • .icon的margin-bottom保证图标和文本之间有合适间距
  • 调整.menu__item.active的偏移量,避免激活状态下文本被遮挡
  • .text类的样式确保文本清晰显示且不会超出导航项范围

内容的提问来源于stack exchange,提问作者Bet Pro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 01:20:37