如何将图像扩展到网页的宽度?

huangapple go评论81阅读模式
英文:

how to spread the image to be in the width of the web page?

问题

如何将图像扩展到网页的宽度?

你可以查看网站Poklanjam

如果可能的话,我想要放大的图像是左侧的城市图像。

需要写入的附加CSS是什么?

谢谢。

英文:

how to spread the image to be in the width of the web page?

you can check the website Poklanjam

the image I want to enlarge if possible, this image of the city on the left.

what should be written as additional css

Thank you

答案1

得分: 2

只是一个建议

图片的大小与创建的元素不符,请尝试使用repeat和centre。

.banner-search {
    background-image: url(https://www.poklanjamvam.com/wp-content/uploads/2022/11/city.svg);
    background-position: center;
    background-size: 35%;
    background-repeat: revert;
}
英文:

Just a suggestion

The size of the image is not according to the elements created, try repeat and centre.

.banner-search {
    background-image: url(https://www.poklanjamvam.com/wp-content/uploads/2022/11/city.svg);
    background-position: center;
    background-size: 35%;
    background-repeat: revert;
}

答案2

得分: 1

你可以尝试以下方法,使图像覆盖整个页面。

.banner-search {
    background-image: url(https://www.poklanjamvam.com/wp-content/uploads/2022/11/city.svg);
    height: 100%;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}

或者,你也可以通过在两侧添加内边距来调整位置,以便在其他设备上显示更好。

英文:

You can try this to make the image cover the entire page.

.banner-search {
    
    background-image: url(https://www.poklanjamvam.com/wp-content/uploads/2022/11/city.svg);
    
     
    /* Full height */
    height: 100%;
            
    /* Center and scale the image nicely */
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    }

Alternatively you can also position it by adding padding on the sides so it appears better on other devices

答案3

得分: 0

以上所有方法都可以将图像居中。

background-size: contain;

将使图像以最完整的视图无失真地显示。这在移动设备和较小的视口上看起来很好,但在桌面上会有很多空白区域。如果你希望在桌面上实现100%宽度且没有图像失真,你需要找到一个宽度为原图4倍的资源。

英文:

All of the above will work to center the image.

background-size: contain;

will allow the image to be its fullest view undistorted. This will look fine on mobile and smaller viewports, but will have a lot of whitespace on either side on desktop. If you're hoping for 100% width and no distorted image on desktop, you'd need to find an asset with 4x the width.

huangapple
  • 本文由 发表于 2023年8月9日 00:07:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76861368.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定