【问题标题】:How can I get my gif to display in the first row and 2 columns of this grid?如何让我的 gif 显示在此网格的第一行和 2 列中?
【发布时间】:2020-04-24 10:21:19
【问题描述】:

我正在尝试制作卡片,其中第一行和两列是 gif,说明卡片适合带边框的单元格内。但是,没有显示任何内容,单元格只是显示为空。

这是我正在使用的代码:

.detailsgrid {
  display:grid;
  grid-template-columns: 35px 1fr;
  grid-template-rows: 200px 40px 1fr 35px;
  border: solid 1px;
}

.detailsimg {
  grid-row-start: 1;
  grid-column-start: 1;
  grid-row-end: 2;
  grid-column-end: 3;
  object-fit: cover;
}
<div class="detailsgrid">
  <img class="detailsimg" src="https://picsum.photos/100/100" width= 300px>
  </div>
  <div class="detailsname">
    Honing
  </div>
  <div class="detailsdescription">Straightening the blade so it stays sharp (no material is taken off the blade). </div>
  <i class="far fa-clock detailstimeicon"></i>
  <div class="detailstime">
    This is how often you should do it
  </div>
</div>

我尝试放置 200 像素,以便 gif 有空间显示,但理想情况下,我希望该区域由 GIF 大小确定。

一张图片来说明我想要实现的目标:

我怎么能这样做?

【问题讨论】:

  • 请添加您想要的设计/输出截图(无法猜测)。
  • 你不能有src for div 它应该带有img 标签。
  • 刚刚将图片添加到帖子中! @EzraSiton
  • @Manjuboyz 你是对的......我已经更新并且图像出现了。我怎样才能让网格始终采用内部 gif 的大小?

标签: html css image css-grid


【解决方案1】:

你可以这样做:

.detailsgrid {
  display: flex;
  border: solid 1px;
  flex-direction: column;
  margin: 5px;
  width: 303px;
}

.detailsname {
  display: inline-block;
  height: 50px;
  width: 300px;
  background-color: #1E343A;
  color: white;
  text-align: center;
  padding-top: 15px;
}

.detailsdescription {
  border: 1px solid red;
  display: inline-block;
  height: 50px;
  width: 300px;
  padding: 5px;
}

.detailstime {
  margin: 5px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

<div class="detailsgrid">
  <div class="details"> <img src="http://placekitten.com/301/301" width=300px>
  </div>

  <div class="detailsname">
    Honing
  </div>

  <div class="detailsdescription">Straightening the blade so it stays sharp (no material is taken off the blade). </div>
  <i class="far fa-clock detailstimeicon"></i>
  <div class="detailstime">
    This is how often you should do it
  </div>
</div>

关于font-icon的第二个问题。

.detailsgrid {
  display: flex;
  border: solid 1px;
  flex-direction: column;
  margin: 5px;
  width: 302px;
}

.detailsname {
  display: inline-block;
  height: 50px;
  width: 300px;
  background-color: #1E343A;
  color: white;
  text-align: center;
  padding-top: 15px;
}

.detailsdescription {
  display: inline;
  height: 50px;
  width: 300px;
  padding: 5px;
}

.timeBlock {
  display: flex;
  width: 300px;
  border-top: 1px solid black;
  height: 50px;
  position: relative;
}

.fa-clock-o {
  height: 50px;
  width: 50px;
  padding-top: 7px;
  padding-left: 7px;
}

.detailstime {
  padding-top: 12px;
  height: 50px;
  margin-left: 5px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">

<div class="detailsgrid">
  <div class="details"> <img src="http://placekitten.com/301/301" width=300px>
  </div>

  <div class="detailsname">
    Honing
  </div>

  <div class="detailsdescription">Straightening the blade so it stays sharp (no material is taken off the blade). </div>

  <div class="timeBlock">
    <div class="timeIcon">
      <i class="fa fa-clock-o" aria-hidden="true" style="font-size:36px;background-color:#1E343A;color:white;"></i>

    </div>

    <div class="detailstime">
      This is how often you should do it
    </div>
  </div>



</div>

【讨论】:

  • 我不确定是否可以使用 flex,因为我在 squarespace 中使用代码块。我希望小图标有不同的颜色laioliving.knives
  • flex 在所有开发中都很常见,所以不用担心,它只是一个属性。关于第二个问题,您说的是哪个小图标?顺便说一句,我无法打开链接,因为它在我的 ofc 笔记本电脑上被阻止了!
  • 如果您回顾原始帖子,我添加了一个 img,其中包含我希望它的外观。我在左下角有一个小图标,它是蓝色背景上的白色手表。
  • 这是字体很棒的图标,如果您观察您的代码,该图像也没有填充到您的代码中,这意味着您可能有错误的图标或其他东西,您可能需要找到正确的图标并实施。
  • @Agie971 我已经为您搜索了一个字体图标(如果这不是您想要的字体图标,请按照您的意愿进行更改并保持代码不变)。我根据您的要求添加了第二个 sn-p 希望它现在可以工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-06
  • 1970-01-01
  • 2016-04-23
  • 1970-01-01
相关资源
最近更新 更多