如何使图像响应并自动缩小高度
How to make image responsive and auto scale down the height
我有两个不相等的响应列,右边较小的是文本,左边较大的是图像。当我调整浏览器 window 以查看列如何适合页面时,它工作正常,直到达到最大宽度 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>
任何帮助将不胜感激:)
删除高度并添加 min-height
.left {
min-height: auto;
}
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>
尝试将 img 添加到您的 html 中 max-width:100%
和 height:auto
用于小屏幕,div 和 background
用于大屏幕!
感谢您的主题,我同意 Chris 的观点,如果我们能获得更多信息,就更容易知道如何提供帮助。
你也可以在你的 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>
我有两个不相等的响应列,右边较小的是文本,左边较大的是图像。当我调整浏览器 window 以查看列如何适合页面时,它工作正常,直到达到最大宽度 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>
任何帮助将不胜感激:)
删除高度并添加 min-height
.left {
min-height: auto;
}
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>
尝试将 img 添加到您的 html 中 max-width:100%
和 height:auto
用于小屏幕,div 和 background
用于大屏幕!
感谢您的主题,我同意 Chris 的观点,如果我们能获得更多信息,就更容易知道如何提供帮助。 你也可以在你的 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>