这是html代码: 我想保持div相同的高度,即使图片的大小很长或文本很长..在CSS中有解决方案吗? 这是代码的链接:https://jsfiddle.net/Youssef_X/81drbgz3/1/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Document</title>
</head>
<body>
<!--=============PRODUCTE ITEMS START HERE=======-->
<section>
<div class="container product-lists">
<!-- ====== FIRST ROW HERE ===== -->
<div class="row">
<div class="col-md-4">
<div class="product-list">
<img src="assets/img/game1.jpg" alt="Planet gaming products" />
<h3 class="title">Eurocoin Interactive</h3>
<p class="description">It is a long established fact that a reader will be distracted.
</p><a href="https://www.google.com" class="btn btn-warning text-uppercase">See more</a>
</div>
</div>
<div class="col-md-4">
<div class="product-list">
<img src="assets/img/game2.png" alt="Planet gaming products" />
<h3 class="title">Eurocoin Interactive</h3>
<p class="description">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy
when an unknown printer took a galley of type and scrambled it to make a type specimen book
</p><a href="https://www.google.com" class="btn btn-warning text-uppercase">see more</a>
</div>
</div>
<div class="col-md-4">
<div class="product-list">
<img src="assets/img/machine3.png" alt="Planet gaming products" />
<h3 class="title">Eurocoin Interactive</h3>
<p class="description"> when an unknown printer took a galley of type and scrambled it to make a type specimen book
</p><a href="https://www.google.com" class="btn btn-warning text-uppercase">see morer</a>
</div>
</div>
<!-- ======= END FIRST ROW ====== -->
</div>
</div>
</section>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
答案 0 :(得分:0)
我建议使用CSS Flexbox(对齐项)。 (https://css-tricks.com/snippets/css/a-guide-to-flexbox/) 我认为这可以解决您的问题?
我看到您正在使用Bootstrap,看起来这可能是您的解决方案: http://getbootstrap.com.vn/examples/equal-height-columns/ 基本上添加.row-eq-height类。
<body>
<!--=============PRODUCTE ITEMS START HERE=======-->
<section>
<div class="container product-lists">
<!-- ====== FIRST ROW HERE ===== -->
<div class="row row-eq-height">
<div class="col-md-4">
<div class="product-list">
<img src="assets/img/game1.jpg" alt="Planet gaming products" />
<h3 class="title">Eurocoin Interactive</h3>
<p class="description">It is a long established fact that a reader will be distracted.
</p><a href="https://www.google.com" class="btn btn-warning text-uppercase">See more</a>
</div>
</div>
<div class="col-md-4">
<div class="product-list">
<img src="assets/img/game2.png" alt="Planet gaming products" />
<h3 class="title">Eurocoin Interactive</h3>
<p class="description">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy
when an unknown printer took a galley of type and scrambled it to make a type specimen book
</p><a href="https://www.google.com" class="btn btn-warning text-uppercase">see more</a>
</div>
</div>
<div class="col-md-4">
<div class="product-list">
<img src="assets/img/machine3.png" alt="Planet gaming products" />
<h3 class="title">Eurocoin Interactive</h3>
<p class="description"> when an unknown printer took a galley of type and scrambled it to make a type specimen book
</p><a href="https://www.google.com" class="btn btn-warning text-uppercase">see morer</a>
</div>
</div>
<!-- ======= END FIRST ROW ====== -->
</div>
</div>
</section>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
答案 1 :(得分:0)
嘿兄弟,因为您正在使用BS-4,这适用于弹性框属性,并且行内的所有cols自动获得相同的高度。 我认为您有一个有效的代码 但我添加了一些颜色使其更清晰
注意:-如果要使所有的中心线对齐,只需在行上添加“ align-items-center”类
.container.product-lists > .row{background-color:grey}
.container.product-lists > .row .col-md-4{border:1px solid #dddddd}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Document</title>
</head>
<body>
<!--=============PRODUCTE ITEMS START HERE=======-->
<section>
<div class="container product-lists">
<!-- ====== FIRST ROW HERE ===== -->
<div class="row">
<div class="col-md-4">
<div class="product-list">
<img src="assets/img/game1.jpg" alt="Planet gaming products" />
<h3 class="title">Eurocoin Interactive</h3>
<p class="description">It is a long established fact that a reader will be distracted.
</p><a href="https://www.google.com" class="btn btn-warning text-uppercase">See more</a>
</div>
</div>
<div class="col-md-4">
<div class="product-list">
<img src="assets/img/game2.png" alt="Planet gaming products" />
<h3 class="title">Eurocoin Interactive</h3>
<p class="description">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy
when an unknown printer took a galley of type and scrambled it to make a type specimen book
</p><a href="https://www.google.com" class="btn btn-warning text-uppercase">see more</a>
</div>
</div>
<div class="col-md-4">
<div class="product-list">
<img src="assets/img/machine3.png" alt="Planet gaming products" />
<h3 class="title">Eurocoin Interactive</h3>
<p class="description"> when an unknown printer took a galley of type and scrambled it to make a type specimen book
</p><a href="https://www.google.com" class="btn btn-warning text-uppercase">see morer</a>
</div>
</div>
<!-- ======= END FIRST ROW ====== -->
</div>
</div>
</section>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>