Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 缩小视口时如何使图像居中?_Css_Responsive Design - Fatal编程技术网

Css 缩小视口时如何使图像居中?

Css 缩小视口时如何使图像居中?,css,responsive-design,Css,Responsive Design,因此,我有三个图像包含在flexbox中。它完全居中,但一旦我缩小视口,图像似乎会粘在左侧,而不会自动居中。flexbox的示例显示了调整大小以适应屏幕的图像,我不太知道哪里出了问题 您需要使用display:inlineblock而不是float:left (显然,您必须将text align:center添加到容器中)如果没有图像或至少没有您在其中使用的确切图像大小,我们将如何测试它?除此之外,只需添加text align:center到。悬停li尝试img{width:100%;} &

因此,我有三个图像包含在flexbox中。它完全居中,但一旦我缩小视口,图像似乎会粘在左侧,而不会自动居中。flexbox的示例显示了调整大小以适应屏幕的图像,我不太知道哪里出了问题

您需要使用
display:inlineblock
而不是
float:left

(显然,您必须将
text align:center
添加到容器中)

如果没有图像或至少没有您在其中使用的确切图像大小,我们将如何测试它?除此之外,只需添加
text align:center
。悬停li
尝试img{width:100%;}
<div class="services">
  <div class="three">
    <ul class="hover">
      <li>
        <img src="img/pictures/landing/1.jpg" alt="landscape">
        <h2>Landscaping</h2>
        <span class="h1"></span>
        <span class="h2"></span>
        <span class="h3"></span>
      </li>
      <li>
        <img src="img/pictures/landing/3.jpg" alt="tree">
        <h2>Tree Services</h2>
        <span class="h1"></span>
        <span class="h2"></span>
        <span class="h3"></span>
      </li>
      <li>
        <img src="img/pictures/landing/2.jpg" alt="plow">
        <h2>Storm Cleanup</h2>
        <span class="h1"></span>
        <span class="h2"></span>
        <span class="h3"></span>
      </li>
    </ul>
  </div>
.services {
  width: 100%;
  height: 100vh;
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-flow: row wrap;
  justify-content: space-around;
  background-color: #2e2e2e;
}
.three {
  max-width: 950px;
  margin: auto;
  width: 100%;
  display: table;
  margin-top: 25vh;
}
.three:after {
  content: "";
  clear: both;
}
.hover {
  margin: 0;
  padding: 0;
  list-style-type: none;
}
.hover li {
  position: relative;
  max-width: 293px;
  background-color: #4f4f4f;
  width: 100%;
  height: 400px;
  margin: 10px;
  float: left;
  overflow: hidden;
  cursor: pointer;
  background-position: center;
}
.h1,
.h2,
.h3 {
  position: absolute;
  top: 0;
  left: 0;
  width: 0%;
  height: 135px;
  background-color: #c5ddb5;
  transition-duration: 0.8s;
}
.h2 {
  top: 133px;
  width: 100%;
  left: 293px;
  background-color: #68d793;
  transition-duration: 0.8s;
}
.h3 {
  top: 266px;
  transition-duration: 0.8s;
}
.hover li:hover .h1,
.hover li:hover .h3 {
  width: 100%;
}
.hover li:hover .h2 {
  left: 0;
}
.hover li h2 {
  position: absolute;
  top: 187px;
  color: #fff;
  text-transform: uppercase;
  font-size: 25px;
  z-index: 1;
  left: -110px;
  transform: translate(-50%);
  width: 134px;
  letter-spacing: 1px;
  transition-duration: 1.5s;
}
.hover li:hover h2 {
  left: 50%;
}