html - 图像不占用 div 容器的大小
问题描述
我正在尝试制作一个页面,其中顶部有一个标题和 4 个图像,它们总共占用 100vh 减去标题的高度:
这是我尝试过的:
* {
margin: 0;
padding: 0;
}
.flex-container {
display: flex;
}
.center {
margin: 0 auto;
}
header {
justify-content: center;
padding: 2rem;
}
.theater {
flex-wrap: wrap;
height: calc(100vh - 102px);
}
.theater div {
width: 50%;
}
.theater img {
display: block;
max-width: 100%;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="index.css">
<title>Title</title>
</head>
<body>
<header class="flex-container">
<h1>header</h1>
</header>
<section class="theater flex-container">
<div><img src="https://i.imgur.com/5e88BFi.jpg" alt="image"></div>
<div><img src="https://i.imgur.com/5e88BFi.jpg" alt="image"></div>
<div><img src="https://i.imgur.com/5e88BFi.jpg" alt="image"></div>
<div><img src="https://i.imgur.com/5e88BFi.jpg" alt="image"></div>
</section>
</body>
</html>
但是,无论我做什么,图像都会“溢出” div 容器。
我尝试使用 object-fit 来裁剪图像,但是没有用。
如果有人帮助我解决这个问题,我将不胜感激。
谢谢你。
解决方案
推荐阅读
- mysql - 从重复行中选择最大的 deleted_data
- javascript - ES6 数组过滤器去除常用项
- python-3.x - 在 Python 中用空格解析 Json 数据
- javascript - 异步 Promise 阻塞 DOM
- css - 用于 Sass 的可扩展的全局变量赋值 @mixin
- python - Python 请求会话不适用于下一次调用中的 put/post
- c++ - 在 C++ 中将内部类实现为具有名称空间的单独类有什么好处?
- node.js - 节点如何处理计算和事件循环
- scala - 如何使用 Cats 组合类型参数边界和仿函数?
- react-native - 如何在图片上方添加文字?