使用fit-content撑开子元素
2024-08-30 04:05:05
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html, body {
padding: 0;
margin: 0;
/* height: 2400px; */
height: 100%;
background: lightgray;
}
.container {
width: 400px;
}
.header {
height: 50px;
background: red;
}
.body {
height: 100px;
background: yellow;
width: 600px;
}
</style>
</head>
<body>
<div class="container">
<div class="header"></div>
<div class="body"></div>
</div>
</body>
</html>
上面的例子body比container还宽,header使用了container的宽度,所以出现了上短下长。
让container设置min-width: fit-content能解决这个问题。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html, body {
padding: 0;
margin: 0;
/* height: 2400px; */
height: 100%;
background: lightgray;
}
.container {
width: 400px;
min-width: fit-content;
}
.header {
height: 50px;
background: red;
}
.body {
height: 100px;
background: yellow;
width: 600px;
}
</style>
</head>
<body>
<div class="container">
<div class="header"></div>
<div class="body"></div>
</div>
</body>
</html>
最新文章
- C++01.类的引入
- Sublime Text配置Python开发利器
- Java Lambda表达式初探
- POI2007_zap 莫比乌斯反演
- JavaWeb---总结(四)Tomcat服务器学习和使用(二)
- OpenCV成长之路(9):特征点检测与图像匹配
- schemaLocation value = &#39;xxxxxxxxxxxx&#39; must have even number of URI&#39;s
- 查看oracle SID
- list排序成员函数对string对象与char*对象排序的差别
- 新测 thinkphp3.2 整合 PHPMailer 发送邮件
- Hibernate: merge方法
- Cocos2d-X学习之Ref类
- 关于Update语句的锁
- Objective-C 是如何慢慢走红的?
- bbs论坛流程
- redis学习(六)——Sorted Set数据类型
- C#获取程序运行时间
- HOOK -- DLL的远程注入技术详解(1)
- SpringMVC源码阅读入门
- OC Foundation框架—字符串