gpt4 book ai didi

css - 响应式图片不适合手机屏幕

转载 作者:行者123 更新时间:2023-11-28 12:08:43 24 4
gpt4 key购买 nike

我有一小段代码(其中的一小段)。问题是,图像不适合屏幕,即使我正在使用媒体查询。谁能告诉我如何解决这个问题,以适应屏幕?我使用的图像比屏幕大,所以它会越过屏幕并迫使人们水平滚动,这是不应该的 - 它应该自动适合屏幕。

这是我的代码:

.portfolio img {
max-width: 100%;
width: 100%;
height: auto !important;
}


@media only screen and (min-width: 1025px)
{
#myBackground
{
min-height: 1000px;
}

#produkter
{
min-height: 1000px;
}
.portfolio img {
max-width: 440px;
max-height: 440px;
}

}

@media only screen and (max-width: 1024px)
{
#myBackground
{
min-height: 800px;
}

#produkter
{
min-height: 800px;
}
.portfolio img {
max-width: 300px;
max-height: 300px;
}


}

@media only screen and (max-width: 640px)
{
#myBackground
{
min-height: 600px;
}

#produkter
{
min-height: 600px;
}
.portfolio img {
max-width: 240px;
max-height: 240px;
}


}

@media only screen and (max-width: 368px)
{
#myBackground
{
min-height: 500px;
}

#produkter
{
min-height: 500px;
}
.portfolio img {
max-width: 100px;
max-height: 100px;
}


}
<head>
<meta name="viewport" content="width=device-width">
</head>

<body>
<img class="portfolio" src="images/bock1.png"/>
</body>

最佳答案

你的问题是投资组合类在图像上,而在代码中你有 .portfolio img 这意味着图像在具有投资组合类的 div 中,试试这个:

 <div class="portfolio">

<img class="portfolio_img" src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg"/>

</div>

只需从图像中删除类组合并将图像包装在具有类组合的 div 中,其他解决方案是放入您的 css

body .portfolio 

代替

.portfolio img

关于css - 响应式图片不适合手机屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36305382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com