简体   繁体   English

如何在 bootstrap4 中调整图像大小以满足左侧的高度

[英]how can I resize image to meet height in left in bootstrap4

I want to show the image in right side of the top using bootstrap4, but don't know how to resize the image height to meet the same height (keep ratio) as left part我想使用 bootstrap4 在顶部右侧显示图像,但不知道如何调整图像高度以满足与左侧部分相同的高度(保持比例)

在此处输入图像描述

code (want to remove 200px )代码(要删除200px

<div class="container">
  <div class="row">
    <div class="col-sm">
        <div class="alert alert-success">
           why cannot I still use table for this kind of tasks? why cannot I still use table for this kind of tasks?
        </div>
        <div class="alert alert-info">
           It is end of 2021
        </div>
        <div class="alert alert-info">
           Now I'd updated to div, this contents can have more text
        </div>
    </div>
    <div class="col-sm">
      <img width="200px" src="https://www.codeply.com/images/partner_creativetim.png" />
    </div>
  </div>
</div>

see https://www.codeply.com/p/flP5E5EpWkhttps://www.codeply.com/p/flP5E5EpWk

I approached it a different way although this may require you to edit the height and width of your image a little.我以不同的方式处理它,尽管这可能需要您稍微编辑图像的高度和宽度。

First I removed the image from that Div and added a class bg-smile首先,我从该 Div 中删除了图像并添加了 class bg-smile

<div class="col-sm bg-smile">
  <!-- stays empty -->
</div>

I've also added mb-0 to remove the bottom margin from the 3rd text box so the image exactly lines up at the bottom.我还添加了mb-0以从第三个文本框中删除底部边距,以便图像在底部完全对齐。

Then added a few CSS instructions for the new class and to make the smile image a background of the Div and center it.然后为新的 class 添加了一些 CSS 指令,并将微笑图像作为 Div 的背景并将其居中。

.bg-smile{
  background: url(https://www.codeply.com/images/partner_creativetim.png) 50% 50% no-repeat;
}
    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM