绝对定位导致内容自动换行问题解决

今天在做一个定位元素的时候遇到一个嵌套定位之后,使用绝对定位的元素的内容自动换行的问题,希望不换行只在一行显示。

可以通过添加 white-space: nowrap; 样式控制不换行

html 复制代码
<div class="box">
    <div class="box1">
        <div class="box2">
            <div class="div"></div>
            <div class="content">今天天气真不多,适合野外活动</div>
        </div>
    </div>
</div>
css 复制代码
        .box {
            position: relative;
            width: 500px;
            height: 400px;
            background-color: rgb(235, 235, 235);
        }
        .box1 {
            position: absolute;
            top: 200px;
            left: 100px;
            height: 70px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .box2 {
            position: relative;
        }
        .div {
            width: 70px;
            height: 70px;
            background-color: aqua;
            border-radius: 50%;
        }
        .content {
            position: absolute;
            background-color: antiquewhite;
            white-space: nowrap; // 通过这个css样式控制换行问题
        }


相关推荐
还有你Y3 小时前
Shell 脚本语法
前端·语法·sh
踩着两条虫5 小时前
如何评价VTJ.PRO?
前端·架构·ai编程
Mh6 小时前
鼠标跟随倾斜动效
前端·css·vue.js
小码哥_常7 小时前
Kotlin类型魔法:Any、Unit、Nothing 深度探秘
前端
Web极客码8 小时前
深入了解WordPress网站访客意图
服务器·前端·wordpress
幺风8 小时前
Claude Code 源码分析 — Tool/MCP/Skill 可扩展工具系统
前端·javascript·ai编程
vjmap9 小时前
唯杰地图CAD图层加高性能特效扩展包发布
前端·gis
ZC跨境爬虫9 小时前
3D 地球卫星轨道可视化平台开发 Day7(AI异步加速+卫星系列精简+AI Agent自动评论)
前端·人工智能·3d·html·json
ID_180079054739 小时前
淘宝 API 上货 / 商品搬家 业务场景实现 + JSON 返回示例
前端·javascript·json
M ? A9 小时前
Vue 动态组件在 React 中,VuReact 会如何实现?
前端·javascript·vue.js·经验分享·react.js·面试·vureact