我对web开发很陌生,我正在尝试创建一个响应性好的映像库,包括Bootstrap和flexbox,但出于某种原因,有些图像并没有达到flex容器的全部高度。
* {
margin: 0px;
padding: 0px;
}
html,
body {
position: relative;
}
body {
overflow-y: auto;
min-height: 100vh;
}
.container {
margin-top: 20px;
}
.tile {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
border-radius: 8px;
overflow: hidden;
position: relative;
}
.tile img {
width: 100%;
height: 100%;
object-fit: cover;
transition: all 0.2s;
}
.tile img:hover {
filter: brightness(50%);
transform: scale(1.1);
}<!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" />
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="styles.css" />
<title>Document</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
class="img-one"
src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg"
alt=""
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2013/07/02/22/20/bouquet-142876_960_720.jpg"
alt=""
class="img-two"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2013/10/02/23/03/mountains-190055_960_720.jpg"
alt=""
class="img-three"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2015/06/19/20/13/sunset-815270_960_720.jpg"
alt=""
class="img-four"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2014/01/22/19/44/flower-field-250016_960_720.jpg"
alt=""
class="img-five"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2015/04/19/08/32/rose-729509_960_720.jpg"
alt=""
class="img-six"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"
alt=""
class="img-seven"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2014/02/27/16/10/tree-276014_960_720.jpg"
alt=""
class="img-eight"
/>
</a>
</div>
</div>
</div>
</div>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"
></script>
</body>
</html>
我应该做什么,使所有的图像都是相同的高度,或者占据全部高度的挠性容器?
发布于 2022-02-09 07:11:12
在height:100%标签上添加a
.tile a{
height:100%;
}
* {
margin: 0px;
padding: 0px;
}
html,
body {
position: relative;
}
body {
overflow-y: auto;
min-height: 100vh;
}
.container {
margin-top: 20px;
}
.tile {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
border-radius: 8px;
overflow: hidden;
position: relative;
}
.tile a{
height:100%;
}
.tile img {
width: 100%;
height: 100%;
object-fit: cover;
transition: all 0.2s;
}
.tile img:hover {
filter: brightness(50%);
transform: scale(1.1);
}<!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" />
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="styles.css" />
<title>Document</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
class="img-one"
src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg"
alt=""
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2013/07/02/22/20/bouquet-142876_960_720.jpg"
alt=""
class="img-two"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2013/10/02/23/03/mountains-190055_960_720.jpg"
alt=""
class="img-three"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2015/06/19/20/13/sunset-815270_960_720.jpg"
alt=""
class="img-four"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2014/01/22/19/44/flower-field-250016_960_720.jpg"
alt=""
class="img-five"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2015/04/19/08/32/rose-729509_960_720.jpg"
alt=""
class="img-six"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"
alt=""
class="img-seven"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2014/02/27/16/10/tree-276014_960_720.jpg"
alt=""
class="img-eight"
/>
</a>
</div>
</div>
</div>
</div>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"
></script>
</body>
</html>
发布于 2022-02-09 07:14:31
您需要添加.tile .picture {高度和宽度继承},并且可以为.tile img {高度和宽度:继承}添加相同的内容--它将工作。我也为你做了演示。
* {
margin: 0px;
padding: 0px;
}
html,
body {
position: relative;
}
body {
overflow-y: auto;
min-height: 100vh;
}
.container {
margin-top: 20px;
}
.tile {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
border-radius: 8px;
overflow: hidden;
position: relative;
}
.tile .picture {
height: inherit;
width: inherit;
}
.tile img {
width: inherit;
height: inherit;
object-fit: cover;
transition: all 0.2s;
}
.tile img:hover {
filter: brightness(50%);
transform: scale(1.1);
}<!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" />
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="styles.css" />
<title>Document</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
class="img-one"
src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg"
alt=""
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2013/07/02/22/20/bouquet-142876_960_720.jpg"
alt=""
class="img-two"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2013/10/02/23/03/mountains-190055_960_720.jpg"
alt=""
class="img-three"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2015/06/19/20/13/sunset-815270_960_720.jpg"
alt=""
class="img-four"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2014/01/22/19/44/flower-field-250016_960_720.jpg"
alt=""
class="img-five"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2015/04/19/08/32/rose-729509_960_720.jpg"
alt=""
class="img-six"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"
alt=""
class="img-seven"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2014/02/27/16/10/tree-276014_960_720.jpg"
alt=""
class="img-eight"
/>
</a>
</div>
</div>
</div>
</div>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"
></script>
</body>
</html>
发布于 2022-02-09 07:13:38
您可以使用高100%,包括'a‘标签与’标题‘的父母。
* {
margin: 0px;
padding: 0px;
}
html,
body {
position: relative;
}
body {
overflow-y: auto;
min-height: 100vh;
}
.container {
margin-top: 20px;
}
.tile , a{
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
border-radius: 8px;
overflow: hidden;
position: relative;
}
.tile img {
width: 100%;
height: 100%;
object-fit: cover;
transition: all 0.2s;
}
.tile img:hover {
filter: brightness(50%);
transform: scale(1.1);
}<!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" />
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="styles.css" />
<title>Document</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
class="img-one"
src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg"
alt=""
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2013/07/02/22/20/bouquet-142876_960_720.jpg"
alt=""
class="img-two"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2013/10/02/23/03/mountains-190055_960_720.jpg"
alt=""
class="img-three"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2015/06/19/20/13/sunset-815270_960_720.jpg"
alt=""
class="img-four"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2014/01/22/19/44/flower-field-250016_960_720.jpg"
alt=""
class="img-five"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2015/04/19/08/32/rose-729509_960_720.jpg"
alt=""
class="img-six"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"
alt=""
class="img-seven"
/>
</a>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-3 mb-4">
<div class="tile">
<a class="picture" href="#">
<img
src="https://cdn.pixabay.com/photo/2014/02/27/16/10/tree-276014_960_720.jpg"
alt=""
class="img-eight"
/>
</a>
</div>
</div>
</div>
</div>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"
></script>
</body>
</html>
https://stackoverflow.com/questions/71045273
复制相似问题