简体   繁体   English

图像宽度不调整宽度:100%

[英]Image width not adjusting width:100%

I have been trying to develop a product page for my website and I have three angles for my product images so I wanted to create a image gallery when you go to the page.我一直在尝试为我的网站开发一个产品页面,我的产品图片有三个角度,所以我想在您访问该页面时创建一个图片库。 The layout I am going with and the code I have so far is at this link https://jsfiddle.net/b1g2f8dh/ .我要使用的布局和到目前为止我拥有的代码位于此链接https://jsfiddle.net/b1g2f8dh/ My issue is I want this to be responsive so I want the .main-image img width to shrink with the page as it collapses until it gets to a min-width in which case the .angle-images div i want to shift below the main-image div and with the thumbnails laid out horizontally.我的问题是我希望它具有响应性,因此我希望 .main-image img 宽度随着页面折叠而缩小,直到达到最小宽度,在这种情况下,我想将 .angle-images div 移动到主图像 div 和水平布局的缩略图。 My first issue is I cannot get the main image to resize despite i have width 100%.我的第一个问题是,尽管我的宽度为 100%,但我无法调整主图像的大小。 I would have thought it would scale it down as the parent container gets smaller.我原以为它会随着父容器变小而缩小。 The second issue is I cannot figure out how to shift the second images beneath.第二个问题是我无法弄清楚如何移动下面的第二个图像。 I am getting my positions all mixed up that nothing seems to work!我把我的位置搞混了,似乎没有任何效果! I plan to figure out some javascript so when you click the thumbnail it makes it the main image but thats a problem for another day ha!我打算找出一些javascript,所以当您单击缩略图时,它会使其成为主图像,但那是另一天的问题哈! Any help would be appreciated.任何帮助,将不胜感激。 The full implementation of my code can be found here in case that helps https://www.printperry.com/home/product-page/index.php我的代码的完整实现可以在这里找到,以防万一https://www.printperry.com/home/product-page/index.php

<div class="product-images">
  <div class="angle-images">
    <li>
      <img data-image="White" src="https://cdn.ssactivewear.com/Images/Color/17130_f_fl.jpg" alt="">  
    </li>
    <li>
      <img data-image="White" src="https://cdn.ssactivewear.com/Images/Color/17130_f_fl.jpg" alt="">  
    </li>
    <li>
      <img data-image="White" src="https://cdn.ssactivewear.com/Images/Color/17130_f_fl.jpg" alt="">  
    </li>
  </div>
  <div class="main-image">
        <img data-image="White" src="https://cdn.ssactivewear.com/Images/Color/17130_f_fl.jpg" alt=""> 
  </div>
</div>

.product-images{
  max-height: 700px;
  max-width: 700px;
  width: 100%;
  display: block;
}
.angle-images{
  padding:5px 0px;
  width: 120px;
  display: inline-block;
  float:left;
  max-height: 700px;
}
.main-image{
  width: 80%;
  height: 600px;
  float: left;
  margin: 10px;
}
.angle-images li{
  list-style: none;
  padding-top: 50px;
}
.angle-images img {
  width: 100px;
  float: right;
  margin:5px 10px;
}
.main-image img {
  width: auto;
  height:700px;
}

There a couple of issues with your CSS preventing it from working as you desire.您的 CSS 存在一些问题,无法按您的意愿工作。 The height, width, max-width, values you have are working against each other in ways that aren't immediately apparent.您拥有的高度、宽度、最大宽度值以不立即显现的方式相互对抗。

It works after making the modifications below.它在进行以下修改后工作。

Using flexbox for the layout mode makes it easy to switch between column and row layouts based on a media query.使用 flexbox 作为布局模式可以很容易地基于媒体查询在列和行布局之间切换。

.product-images{
  max-height: 700px;
  max-width: 700px;
  width: 100%;
  display: flex;
  flex-flow: column nowrap;
  flex-direction: column-reverse;
}
@media (min-width: 768px) {
  .product-images {
    flex-flow: row nowrap;
  }
}
.angle-images{
  padding:5px 0px;
  width: 120px;
  max-height: 700px;
  display: flex;
}
@media (min-width: 768px) {
  .angle-images {
    flex-flow: column nowrap;
  }
}
.main-image{
  width: 80%;
  height: 600px;
  margin: 10px;
}
.angle-images li{
  list-style: none;
  padding-top: 50px;
}
.angle-images img {
  width: 100px;
  margin:5px 10px;
}
.main-image img {
  max-width: 100%;
}

Like Dan mentioned in his post, there were conflicting values.就像丹在他的帖子中提到的那样,存在相互冲突的价值观。 One of the issue I saw, was the size of the parent container, and the child container.我看到的问题之一是父容器和子容器的大小。 I am also learning as well, and one tip I would give you is try to use border-style to help you see visually, it makes problem solving more direct and easy.It really helps when you're working with multiple div container.我也在学习,我给你的一个提示是尝试使用边框样式来帮助你视觉上看,它使解决问题更直接和容易。当你使用多个 div 容器时,它真的很有帮助。 Then play around with what you know, and try to see how to make it fit.然后玩转你所知道的,并尝试看看如何使它适合。 I decided to give a stab at this, and came up with this version.我决定尝试一下,并提出了这个版本。 You would have to use Flex unfortunately, it just made problem solving easier.不幸的是,您将不得不使用 Flex,它使解决问题变得更容易。 The angle and main are responsive together for now unless you were trying to make just the main responsive only, please let me know so I can take some more time later and see if I further assist you, but for now this is what I have.角度和主要现在一起响应,除非您只想使主要响应,请告诉我,以便我稍后花更多时间看看我是否进一步帮助您,但现在这就是我所拥有的。 I hope this leads you to the right path of whatever it is you're trying to achieve.我希望这会引导您走向正确的道路,无论您要实现什么目标。

<div class="product-images">

  <div class="angle-images">

    <ul class="angle-ul">
      <li class="angle-li angle-li-1">
        <img data-image="White" src="https://cdn.ssactivewear.com/Images/Color/17130_f_fl.jpg" alt="">
      </li>
      <li class="angle-li angle-li-2">
        <img data-image="White" src="https://cdn.ssactivewear.com/Images/Color/17130_f_fl.jpg" alt="">
      </li>
      <li class=" angle-li angle-li-3">
        <img data-image="White" src="https://cdn.ssactivewear.com/Images/Color/17130_f_fl.jpg" alt="">
      </li>
    </ul>

  </div>

  <div class="main-Image">
    <img data-image="White" src="https://cdn.ssactivewear.com/Images/Color/17130_f_fl.jpg" alt="">
  </div>
</div>


* {
  margin: 0;
  padding: 0;
}

.product-images {
  height: 700px;
  max-width: 700px;
  width: 100%;
  display: flex;
  flex-direction: row;
  flex-wrap: warp;
  border-style: dotted;
}

.angle-images {
  width: 100px;
  border-style: dotted;
}

.angle-ul {
}

.angle-li img {
  width: 100%;
}
.main-Image img {
  height: 100%;
  width: 100%;
}


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

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