如何使图像响应并自动缩小高度

时间:2019-07-02 12:39:10

标签: html css image responsive

我有两个不相等的响应列,右边的较小的是文本,左边的较大的是图像。当我调整浏览器窗口的大小以查看各列如何适合页面时,它可以正常工作,直到达到最大宽度700px且各列相互堆叠为止。底部一栏很好,但是顶部一栏(图像)没有显示完整的图像,而仅沿页面的宽度显示了一个细条。如何获得自动调整高度以显示完整图像的功能?

我尝试将左列的高度设置为自动,但是这没有用,并且只显示一个小条。

.column {
      float: left;
      padding: 10px;
      height: 300px;
  
  
    }

    .left {
      width: 60%;
      background-image: url('http://i.imgur.com/k5gf0zz.jpg');
      background-size: cover;
      background-position: center;

    }

    .right {
      width: 40%;
    }

    /* Clear floats after the columns */
    .row:after {
     content: "";
     display: table;
     clear: both;
    }


    /* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */
    @media screen and (max-width: 700px) {
      .column {
        width: 100%;
      }
     
 
    }
<body>

    <div class="row">
      <div class="column left";>
    
  
      </div>
      <div class="column right" style="background-color:#FDE4EC;">
      <center> <p><font size="8">We Provide Quality Skin Care</font></p>
     <p style = "font-family: Verdana, Geneva, sans-serif">Let us help you feel beautiful!</p> 
 
     <br> 
 
     <button class="button2"><b>BOOK NOW</b></button> </center>

  
  
       </div>
    </div>


    </body>

任何帮助将不胜感激:)

3 个答案:

答案 0 :(得分:0)

删除高度并添加最小高度

  .left {
  min-height: auto;
  }

答案 1 :(得分:0)

img{
  max-width:100%;
  height:auto;
  display:none;
}
.left {
  width: 60%;
background:url("http://i.imgur.com/k5gf0zz.jpg") no-repeat center;
background-size:cover;
}


.right {
  width: 40%;
  padding: 10px 0px;
}
.row{
  display:flex;
  flex-wrap:wrap;
}

@media screen and (max-width: 700px) {
  .column {
    width: 100%;
  }
  img{
    display:block;
  }
  .left {
  background:none;

  }

}
<div class="row">
  <div class="column left";>
<img src="http://i.imgur.com/k5gf0zz.jpg">

  </div>
  <div class="column right" style="background-color:#FDE4EC;">
  <center> <p><font size="8">We Provide Quality Skin Care</font></p>
 <p style = "font-family: Verdana, Geneva, sans-serif">Let us help you feel beautiful!</p> 

 <br> 

 <button class="button2"><b>BOOK NOW</b></button> </center>



   </div>
</div>

对于小屏幕,尝试使用max-width:100%height:auto将img添加到您的html中,对于大屏幕,尝试使用background将div添加到您的html中!

答案 2 :(得分:0)

感谢您的话题,我同意克里斯的看法,如果我们能获得更多信息,那么知道如何提供帮助会更容易。 您还可以在html文件中使用类似的图片,两个不同大小的图片,并为每个页面尺寸使用特定的图片。

<picture id="pic">
<source media="(min-width: 650px)" srcset="image.jpg">
<img src="image2.jpg" alt="same pic bigger size" style="width:auto;">
</picture>
相关问题