首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在CSS图片库中设置统一的框高

在CSS图片库中设置统一的框高
EN

Stack Overflow用户
提问于 2016-10-18 15:00:09
回答 2查看 395关注 0票数 1

这似乎是个简单的问题,但我解决不了。我正在尝试建立一个反应灵敏的图片库,就像在W3Schools上演示的那样。那个画廊看上去很好--直到你改变标题的长度。然后,箱子的高度开始变化,画廊的安排都搞砸了。我如何设置这些盒子的高度,使它们整齐地排列,即使标题范围从2-4行长?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-10-18 15:03:36

你能做的一件事是,你可以给一个min-height并使它固定高度。

代码语言:javascript
复制
div.desc {
  padding: 15px;
  text-align: center;
  min-height: 50px;
}

片段:

代码语言:javascript
复制
div.img {
  border: 1px solid #ccc;
}

div.img:hover {
  border: 1px solid #777;
}

div.img img {
  width: 100%;
  height: auto;
}

div.desc {
  padding: 15px;
  text-align: center;
  min-height: 50px;
}

* {
  box-sizing: border-box;
}

.responsive {
  padding: 0 6px;
  float: left;
  width: 24.99999%;
}

@media only screen and (max-width: 700px){
  .responsive {
    width: 49.99999%;
    margin: 6px 0;
  }
}

@media only screen and (max-width: 500px){
  .responsive {
    width: 100%;
  }
}

.clearfix:after {
  content: "";
  display: table;
  clear: both;
}
代码语言:javascript
复制
<h2>Responsive Image Gallery</h2>
<h4>Resize the browser window to see the effect.</h4>

<div class="responsive">
  <div class="img">
    <a target="_blank" href="img_fjords.jpg">
      <img src="img_fjords.jpg" alt="Trolltunga Norway" width="300" height="200">
    </a>
    <div class="desc">Add a description of the image here</div>
  </div>
</div>


<div class="responsive">
  <div class="img">
    <a target="_blank" href="img_forest.jpg">
      <img src="img_forest.jpg" alt="Forest" width="600" height="400">
    </a>
    <div class="desc">Add a description of the image here</div>
  </div>
</div>

<div class="responsive">
  <div class="img">
    <a target="_blank" href="img_lights.jpg">
      <img src="img_lights.jpg" alt="Northern Lights" width="600" height="400">
    </a>
    <div class="desc">Add a description of the image here</div>
  </div>
</div>

<div class="responsive">
  <div class="img">
    <a target="_blank" href="img_mountains.jpg">
      <img src="img_mountains.jpg" alt="Mountains" width="600" height="400">
    </a>
    <div class="desc">Add a description of the image here</div>
  </div>
</div>

<div class="clearfix"></div>

<div style="padding:6px;">
  <p>This example use media queries to re-arrange the images on different screen sizes: for screens larger than 700px wide, it will show four images side by side, for screens smaller than 700px, it will show two images side by side. For screens smaller than 500px, the images will stack vertically (100%).</p>
  <p>You will learn more about media queries and responsive web design later in our CSS Tutorial.</p>
</div>

票数 1
EN

Stack Overflow用户

发布于 2016-10-18 15:02:37

你可以做两件事。将这两种方法都放在应用于每个块的类中。

代码语言:javascript
复制
overflow-y: hidden;  //Or scroll if you want...
max-height: 400px;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40111699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档