html - 使用bootstrap使图像垂直和水平居中

标签 html css bootstrap-4

<分区>

我有一个使用 bootstrap 显示内容的页面,我已经在我想要的位置获得了大部分内容,除了我的图像,即使垂直居中,也没有水平居中。

我正在尝试做到这一点,如果有人添加了一个小图像或一个大图像,它总是包含在列/行中并且响应该容器,但我也想确保如果图像比容器小,它正好位于容器的中间。

除非另有说明,否则我在这里缺少什么来确保图像居中和居中对齐?

    html,
    body {
      height: 100vh;
      width: 100vw;
      overflow: hidden;
    }

    iframe{
      height:100% !important;
      width:100% !important;
    }

    .middle p{
      max-height:100%;
    }

    img {
      max-width: 100%; 
      height:auto;
      margin:0 auto;
    }
    .my-container {
      display: flex;
      flex-direction: column;
      justify-content: center;
      height: 100vh;
      width:100vw;
    }

    .my-container>.top [class^="col-"],
    .my-container>.bottom [class^="col-"] {
      background-color: #778899  ;
      color: white;
      text-align: center;
    }

    .my-container>.middle {
      flex-grow: 1;
      padding:30px;
      /*background-image: url('images/bg_green.svg');*/
      background-size: cover;
    }

<div class="row middle" id="middle" style="background-image: url();">
    <div class="col-lg-12" id="fullColumn">
        <div class="fullContent" id="fullContent" style="height: 100%; ">
        </div>
    </div>
</div>

更新:

这是当前情况的图像(图像太高,但垂直居中)和我试图实现的输出(无论图像大小,它都垂直和水平居中) enter image description here

更新:

多个 DIVS

.topLeftContent{
      display:flex;
      justify-content:center;
      align-items:center;
    }
    .bottomLeftContent{
      display:flex;
      justify-content:center;
      align-items:center;
    }
    .rightQtrContent{
      display:flex;
      justify-content:center;
      align-items:center;
    }
    <div class="col-lg-6" id="rightColumnQtrHalf" >
        <div id="rightQtrContent" style=" height: 100%; ">
        </div>
    </div>

最佳答案

请检查以下链接。这可能对你有帮助。我已将 flex 属性添加到父 div。谢谢

https://jsfiddle.net/fzod273t/15/ 输入

关于html - 使用bootstrap使图像垂直和水平居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54140137/

上一篇:javascript - 以变​​换样式修改值

下一篇:html - 动态引导表列 : same width for each column (without Java Script)

相关文章:

javascript - 如何使用 jquery 将列表框的值转移到另一个列表框

PHP JSON 和 Android

Jquery 可折叠面板 - 更改字体颜色

javascript - 音乐播放器 "easy"Div prob

html - 在小屏幕上需要从右到左下方流动(右固定宽度,左可变宽度)

git - 安装 popper 失败(git 命令失败)

html - 我该如何修复这个页脚?

html - &lt;!DOCTYPE> html/模板

html - Outlook 中的 HTML 电子邮件失真

html - 如何在引导轮播中调整图像大小?