【问题标题】:img does not respondimg 没有反应
【发布时间】:2016-06-17 14:48:35
【问题描述】:

请帮助我对此感到疯狂 我正在尝试为 Web 应用程序设置一个图像,它应该是响应式的,但是当我更改浏览器大小时它会拉伸而不是调整大小 这是代码和CSS

<div class="row">
    <ul class="lista_de_categorias">
        @foreach (var categories in Model)

        {
            <li class="categorieslist">
                <a href="#">  

                    <div class="col-md-4 colum4">
                        <div class="categoriesdiv">
                            <h2 class="categoriesheading">Category Name</h2>
                        </div>

                        <img class="catImages" src="@categories.ImagePath" alt="images of different window blinds"/>

                    </div>

                </a>
            </li>
        }
    </ul>
</div>

这里是 img 的 CSS 代码

.catImages{

     display:flex;
    flex-wrap:wrap;
    width:100%;

    justify-content:center;
    margin-left:0px;
    margin-right:0px;
    height: auto;

}

但这不起作用 我也试过max-width:100%,但没有

【问题讨论】:

  • 你的意思是图像没有调整大小吗?尽管codepen.io/vincentccw/pen/yOYymR,它在我身边工作
  • @shark 最好将您的工作放在 jsfiddle 中并展示您的问题。这样更好地解决这个问题

标签: html css image twitter-bootstrap twitter-bootstrap-3


【解决方案1】:

查看您的课程.col-md-4 和HTML 结构,我可以看到您正在使用。所以只需按照Docs 中的说明使用.img-responsive

添加了.container 以包装.row,其结构也应符合Docs。

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="row">
    <ul class="lista_de_categorias">
      <li class="categorieslist">
        <a href="#">

          <div class="col-md-4 colum4">
            <div class="categoriesdiv">
              <h2 class="categoriesheading">Category Name</h2>
            </div>

            <img class="img-responsive catImages" src="//lorempixel.com/1600/900" alt="images of different window blinds" />

          </div>

        </a>
      </li>
    </ul>
  </div>
</div>

【讨论】:

  • 我看到您回复的代码正在按照我希望我的代码工作的方式工作,但我找不到导致我的代码错误的错误
  • 我把那门课放在 BS 上,但拉伸效果仍然很差
  • 现在我添加了容器类,显然没有该类就无法工作。图像现在没有向一个方向拉伸或收缩,而是完全缩放
猜你喜欢
  • 2022-06-24
  • 2019-12-26
  • 2016-06-05
  • 2021-11-11
  • 1970-01-01
  • 2021-08-07
  • 2015-05-14
  • 2020-10-28
  • 2020-10-22
相关资源
最近更新 更多