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

CSS可调整大小Tooltip数据列重排需求技术求助

需求场景

客户的点击触发式Tooltip有以下显示逻辑:

  • 初始状态:数据垂直单列展示

    Data1
    Data2
    Data3
    Data4
    Data5
    Data6

  • 调整Tooltip尺寸后:原本自动转为横向多行展示

    Data1 Data2 Data3
    Data4 Data5 Data6

现要求调整为纵向多列展示,最终效果:

Data1 Data3 Data5
Data2 Data4 Data6

当前使用的CSS代码如下:

.tooltip-wrapper {
}

.tooltip-content {

    font-family: AvertaRegular;

    position: relative;
    padding: 0px;
    margin: 0;
    box-shadow: 0 0 0 4px rgba(0, 0, 0, .15);
    border-radius: 2px;
    background: #FFFFFF;

    .tooltip-real-content {
        height: 100%;
        max-height: 300px;
        overflow: auto;
    }

    &:before {
        content: '';
        position: absolute;
        bottom: -14px;
        left: 0;
        width: 0;
        height: 0;
        margin-left: 28px;
        border-left: 0 solid transparent;
        border-right: 14px solid transparent;
        border-top: 14px solid #FFFFFF;
        z-index: 2;
    }

    a.close-button {
        position: absolute;
        right: -12px;
        top: -12px;
        width: 20px;
        height: 20px;
        padding: 0px;
        text-indent: -9999px;
        font-size: 0px;
        line-height: 0px;
        opacity: 1;
        text-transform: uppercase;
        z-index: 3;
        background: #FFFFFF;
        border-radius: 18px;
        box-shadow: 0 0 0 3px rgba(0, 0, 0, .15);

        &:after, &:before {
            content: '';
            position: absolute;
            top: 9px;
            left: 6px;
            width: 8px;
            height: 2px;
            background: #397DBA;
            border-radius: 3px;
        }

        &:before {
            transform: rotate(45deg);
        }

        &:after {
            transform: rotate(-45deg);
        }

    }

    .inner-content-wrapper {
        min-width: 210px;
        width: 210px;
        max-width: 650px;
        max-height: 400px;
        overflow: hidden;
        padding: 12px;
        border-radius: 2px;
        resize: auto;
        transition: .2s;

        .pictoDisplay {
            display: flex;
            flex-flow: wrap;
            min-width: 190px;
            max-width: 100%;
            min-height: 170px;
            max-height: 100%;
        }
        .infoDisplay {
            display: block;
            width: 210px;
        }

        .inner-content {
            margin: 0;
            padding: 0;
            overflow-y: auto;
            overflow-x: hidden !important;
            outline: 0;
            text-align: left;

            .infowindow_template_geom_qt {
                span {
                    margin: 5px 0;
                    display: block;
                }
            }

            h4 {
                display: block;
                width: 190px;
                margin: 0;
                padding: 0;
                font-weight: 700;
                font-family: AvertaRegular;
                text-transform: uppercase;
                word-wrap: break-word;
                line-height: 120%;
                color: #CCCCCC;
                font-size: 11px;
            }

            p {
                color: #333333;
                display: block;
                width: 190px;
                max-width: 190px;
                margin: 0;
                padding: 0 0 7px;
                font-family: AvertaRegular;
                font: 400 13px AvertaRegular;
                word-wrap: break-word;
            }

        }

    }

    .tip-container {
        position: absolute;
        bottom: -20px;
        left: -4px;
        width: 20px;
        height: 16px;
        margin-left: 28px;
        overflow: hidden;
        z-index: 0;

        &:before {
            content: '';
            position: absolute;
            width: 20px;
            height: 20px;
            left: 0;
            top: -10px;
            margin-left: 0;
            transform: skew(0, -45deg);
            border-radius: 0 0 0 10px;
            background: rgba(0, 0, 0, .15);
            z-index: 0;
        }
    }
}

.selectFilterContainer {
    cursor: pointer;
}

.imageContainer {
    float: right;
    vertical-align: middle;
    display: table-cell;
    padding-top: 5px;
    width: 22px;

    image {
        width: 22px;
    }
}

.infowindow_template_cuota_descr
.infowindow_template_geom_descr,
.infowindow_template_geom_qt,
.infowindow_template_pictos_data {
    font-family: AvertaRegular;
}

.infowindow_template_cuota_descr {
    padding: 1px;
}

.loader {
    border: 16px solid #f3f3f3;
    border-radius: 50%;
    border-top: 16px solid #3498db;
    width: 30px;
    height: 30px;
    -webkit-animation: spin 2s linear infinite; /* Safari */
    animation: spin 2s linear infinite;
}

div.notes {
    input {
        font-size: 11px;
        width: 122px;
    }

    h4 {
        padding-bottom: 2px;
    }
}

.confirmButton {
    border: 0;
    background-color: #15A4FA;
    font-family: AvertaBold;
    font-size: 9.5px;
    letter-spacing: 1px;
    padding: 4px;
    color: #FFF;
    border-radius: 2px;
    height: 22px;
    outline: none;
    margin: 0 auto;
    width: 54px;

    &:hover {
        background-color: #50BDFF;
    }
}

/* Safari */
@-webkit-keyframes spin {
    0% {
        -webkit-transform: rotate(0deg);
    }
    100% {
        -webkit-transform: rotate(360deg);
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

:host ::ng-deep mat-icon {
    &.edit {
        font-size: 16px;
        float: right;
        color: #15A4FA;
        cursor: pointer;
    }

    &.save-edit, &.cancel-edit {
        width: 20px;
        padding-top: 4px;
    }

    &.cancel-edit {
        color: rgb(201, 51, 51);
    }
}

input.editBox {
    width: 75%;
    margin-bottom: 8px;
}
实现方案

利用CSS Grid布局实现纵向多列排列,核心修改如下:

  1. 调整数据容器的Grid布局
    找到存放数据的容器(即.infowindow_template_geom_qt),修改其display属性为grid,并设置按列自动流动:
.infowindow_template_geom_qt {
  display: grid;
  /* 让元素优先按列排列,填满一行后自动新增列 */
  grid-auto-flow: column;
  /* 固定行数为2,适配6条数据分成3列的需求 */
  grid-template-rows: repeat(2, auto);
  /* 设置列之间的间距,根据需求调整 */
  column-gap: 15px;
}
  1. 取消固定宽度限制
    原.infoDisplay设置了固定210px宽度,会限制多列展示,修改为自适应:
.infoDisplay {
  display: block;
  width: auto;
}
  1. 保持元素块级特性(可选)
    原span元素的block属性可以保留,Grid会自动处理排列:
.infowindow_template_geom_qt span {
  margin: 5px 0;
  display: block;
}

效果说明

  • grid-auto-flow: column会让数据元素先填满第一列的2行,再自动创建第二列、第三列,最终呈现纵向多列的排列效果。
  • 如果数据数量变化,比如8条数据,设置grid-template-rows: repeat(2, auto)会自动分成4列,每行显示2条数据,符合纵向排列逻辑。
  • 当用户调整Tooltip宽度时,Grid会根据容器宽度自动适配列数,保证布局始终符合纵向多列的要求。

内容的提问来源于stack exchange,提问作者Gabriel V

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 10:17:42