图片不适合。

huangapple go评论64阅读模式
英文:

Image Doesn't Fit

问题

我尝试制作自定义的Instagram动态,使用HTML和CSS,但是我遇到了关于图片大小的问题。会自动添加外部填充,并且图像无法占据整个单元格。

我正在使用Bootstrap 5。

HTML代码:

<div class="container-fluid" style="padding-left: 5px ; padding-right: 5px;">
      <div class="row">
        <div class="col-lg-3 col-md-3 col-sm-0"></div>
        <div class="col-lg-6 col-md-6 col-sm-12">
          <table class="gallery-table" id="gallery-container">
            <tr>
              <td>
                <img src="immagini/questionmark.png" alt="" class="gallery-img" data-bs-toggle="modal" data-bs-target="#image-modal" title="la-citta-pizza">
              </td>
              <td>
                <img src="immagini/questionmark.png" alt="" class="gallery-img" data-bs-toggle="modal" data-bs-target="#image-modal" title="fondane">
              </td>
              <td>
                <img src="immagini/esterna1.jpg" alt="" class="gallery-img" data-bs-toggle="modal" data-bs-target="#image-modal" title="la-citta-pizza1">
              </td>
            </tr>
          </table>
        </div>
        <div class="col-lg-3 col-md-3 col-sm-0"></div>
      </div>
    </div>

CSS代码:

.gallery-img {
    aspect-ratio: 1/1;    
    width: 100%;
    height: auto;
    object-fit:cover;
}

如何去除这个填充?

英文:

I'm trying to make my custom instagram feed with html and css but I have an issue with the images size. An external padding is automatically added and the image doesn't occupy the entire cell.
I'm using bootstrap 5.
图片不适合。

My HTML:

&lt;div class=&quot;container-fluid&quot; style=&quot;padding-left: 5px ; padding-right: 5px;&quot;&gt;
      &lt;div class=&quot;row&quot;&gt;
        &lt;div class=&quot;col-lg-3 col-md-3 col-sm-0&quot;&gt;&lt;/div&gt;
        &lt;div class=&quot;col-lg-6 col-md-6 col-sm-12&quot;&gt;
          &lt;table class=&quot;gallery-table&quot; id=&quot;gallery-container&quot;&gt;
            &lt;tr&gt;
              &lt;td&gt;
                &lt;img src=&quot;immagini/questionmark.png&quot; alt=&quot;&quot; class=&quot;gallery-img&quot; data-bs-toggle=&quot;modal&quot; data-bs-target=&quot;#image-modal&quot; title=&quot;la-citta-pizza&quot;&gt;
              &lt;/td&gt;
              &lt;td&gt;
                &lt;img src=&quot;immagini/questionmark.png&quot; alt=&quot;&quot; class=&quot;gallery-img&quot; data-bs-toggle=&quot;modal&quot; data-bs-target=&quot;#image-modal&quot; title=&quot;fondane&quot;&gt;
              &lt;/td&gt;
              &lt;td&gt;
                &lt;img src=&quot;immagini/esterna1.jpg&quot; alt=&quot;&quot; class=&quot;gallery-img&quot; data-bs-toggle=&quot;modal&quot; data-bs-target=&quot;#image-modal&quot; title=&quot;la-citta-pizza1&quot;&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
          &lt;/table&gt;
        &lt;/div&gt;
        &lt;div class=&quot;col-lg-3 col-md-3 col-sm-0&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;

My CSS:

.gallery-img {
    aspect-ratio: 1/1;    
    width: 100%;
    height: auto;
    object-fit:cover;
}

How I can remove this padding(o?

答案1

得分: 2

去除纵横比,使高度不再依赖于宽度。同时将高度设为100%。

英文:

Remove the aspect ratio so that the height no longer depends on the width. Also make the height 100%.

答案2

得分: 0

将外部div添加相对位置,将内部div添加绝对位置。

英文:

Add position relative to outer and position absolute to inner div's.

huangapple
  • 本文由 发表于 2023年6月12日 17:10:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455129.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定