为什么fit-content()在CSS-Grid中不适用于网格 - 板行属性,但在网格板柱上效果很好?

发布于 2025-02-01 04:30:45 字数 1093 浏览 0 评论 0原文

我举一个例子,在哪里有两个图像。它们的尺寸为168px宽度和180个高度。我只允许使用高达300px的高度,但是它垂直呈现目标两个图像,而网格 - 板块柱并非如此,一切正常。

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>HAYTI</title>
  <style>
   
.grid {
  display: grid;
  border: 2px solid black;
  grid-template-columns: 200px 1fr;
  grid-template-rows: fit-content(300px) 100px ;
  height: 600px;


  background: orange;
  
}

.itemm {
border: 2px solid black;
}

.item1 {
font-size: 20px;
 background: lime;
 padding: 5px;

}

.item2 {
  background: red;
  font-size: 20px;
}
  
  </style>
 </head>
 <body>
   
<section class="grid">
  <div class="itemm item1"><img  src="https://i.sstatic.net/28qba.jpg"> <img  src="https://i.sstatic.net/28qba.jpg"></div>
  <div class="itemm item2">item2</div>
  <div class="itemm item2">item3</div>
  <div class="itemm item2">item3</div>
</section>


 </body>
</html>

I'll give one example, where have two images. size of them is 168px-width and 180-height. I only allowed to use up to 300px height, but it renders the target two images vertically, which is not the case with grid-template-columns, where everything works fine.

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>HAYTI</title>
  <style>
   
.grid {
  display: grid;
  border: 2px solid black;
  grid-template-columns: 200px 1fr;
  grid-template-rows: fit-content(300px) 100px ;
  height: 600px;


  background: orange;
  
}

.itemm {
border: 2px solid black;
}

.item1 {
font-size: 20px;
 background: lime;
 padding: 5px;

}

.item2 {
  background: red;
  font-size: 20px;
}
  
  </style>
 </head>
 <body>
   
<section class="grid">
  <div class="itemm item1"><img  src="https://i.sstatic.net/28qba.jpg"> <img  src="https://i.sstatic.net/28qba.jpg"></div>
  <div class="itemm item2">item2</div>
  <div class="itemm item2">item3</div>
  <div class="itemm item2">item3</div>
</section>


 </body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文