html - 如何在html中将图像的位置设置为居中

标签 html css twitter-bootstrap

我正在设计一个网站,我想在 slider 上显示图像,但是因为我在 500 中给出了 divheight,只有部分图像显示
从上到下。我希望图像应该具有相同的高度,但它应该从中心显示

 <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner">
      <div class="item active">
        <img src="../armando-master/assets/img/Relax.jpg" alt="Los Angeles" 
        style="width:100%;" "height: 50%">
      </div>

      <div class="item">
        <img src="assets/img/blog/1.jpg" alt="Chicago" style="width:100%;" 
       "height: 50%">
      </div>

      <div class="item">
        <img src="assets/img/blog/3.jpg" alt="New york" style="width:100%;" 
        "height: 50%">`enter code here`
      </div>
    </div>

最佳答案

<img style="width: 100%; height:100%; object-fit: cover;" />应该做的伎俩。

关于html - 如何在html中将图像的位置设置为居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49795828/

相关文章:

html - 在移动 View 中隐藏 html 按钮

html - Bootstrap 4 改变每行卡片的数量

html - Bootstrap 中心 div 旁边有右侧 div

css - 图像行均匀分布

javascript - 在垂直居中的 DIV 上设置最小顶部

javascript - 使用滚动事件显示基于窗口高度的元素

javascript - Bootstrap 导航栏在滚动时折叠

Javascript - 数字显示为 NaN 且对象未定义

html - 如何制作最细的字体

html - 如何水平对齐这些 div?