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

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

可以通过添加 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样式控制换行问题
        }


相关推荐
Justinc.42 分钟前
HTML5新增属性
前端·html·html5
1024小神1 小时前
nextjs项目build导出静态文件
前端·javascript
阿聪_1 小时前
createContext 还是 useSyncExternalStore?一文讲清场景与选型
前端
Linsk1 小时前
当我把前端条件加载做到极致
前端·前端工程化
_辉1 小时前
大模型构建表单与数据结构
前端
祝鹏2 小时前
动态表单生成
前端
luckyJian2 小时前
React深入浅出理解
前端
是一碗螺丝粉2 小时前
拯救你的app/小程序审核!一套完美避开审核封禁的URL黑名单机制
前端·javascript·微信小程序
littleding2 小时前
Vue3之计算属性
前端·vue.js
VincentHe2 小时前
利用豆瓣rss生成(伪)纯静态影单
前端