css - 移动分辨率和容器的flexlayout问题
问题描述
你好,我的 flexbox 中有以下结构
页眉主页脚
在我的主要内容中,我有一个容器来集中内容但是当我使用较小的分辨率时,它会出现问题,如照片所示:
代码:
export default function App() {
return (
<div style={{ display: "flex", flexDirection: "column", height: "100%" }}>
<div style={{ flex: "none", background: "blue", height: "140px" }}>a</div>
<div
style={{
padding: "0 30px",
margin: "0 auto",
background: "red",
maxWidth: "1240px",
width: "100%"
}}
>
<h2>
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi..
</h2>
</div>
<div style={{ flex: "none", background: "yellow", height: "40px" }}>
c
</div>
</div>
);
}
CSS重置:
body > #root > div {
height: 100vh;
background: black;
}
body {
margin: 0;
padding: 0;
}
例子:
解决方案
width 属性不包括内边距,因此当您的中间元素在左侧和右侧包括 30px 内边距并且也设置为 100% 宽度时,它会导致 x 溢出。如果您希望中间元素的整个边界框为 100% 宽度,您可以执行以下样式:
<div
style={{
padding: "0 30px",
margin: "0 auto",
background: "red",
maxWidth: "1240px",
width: "calc(100% - 60px)"
}}
>
推荐阅读
- java - Spring boot embedded tomcat listening but not responding
- python - Python compare list of dictionaries with another dictionary in loop
- c++ - 默认参数匹配 std::index_sequence
- database - 在后端获取一个 Flask 脚本与用户的本地数据库进行通信:可能吗?
- https - 如何获取 https 响应的正文
- python - 测试不同列中是否存在值
- python - 循环中的 makedirs() 创建不可见的目录/文件夹?
- maven - Tomcat 错误“源服务器没有找到目标资源的当前表示或不愿意透露存在的表示。”
- c# - 如何在不更改原始字符串的情况下创建和更改新字符串 [] []?
- coordinates - 在第 i 个相机图像(KITTI 数据集)中投影 3D 激光雷达点