gpt4 book ai didi

html - 你如何在 css 中调整背景图像的大小?

转载 作者:太空宇宙 更新时间:2023-11-04 06:32:48 25 4
gpt4 key购买 nike

下面是我的代码。我不知道如何在一整行代码中调整图像的大小。我是否创建新的代码行并使用标签?我不知道该怎么办。有什么问题吗?

#centerpicture {
min-height: 400px;
background: url("Enderman_wallpaper.jpg") no-repeat;
text-align: center;
color: #ffffff;
}

只显示了 Sprite 的一只眼睛,但它应该显示为 Sprite 的整张脸。

最佳答案

您可以使用以下属性之一来调整背景图片的大小:

background-size: cover; 
background-size: contain;
background-size: 30%; //using percentages
background-size: 100px 200px // using pixels

试用这些属性,看看哪个最适合您。请引用documentation获取更多信息。

要定位背景图片,请使用 background-position属性(property)。

代码风格:

您可以在单独的行中声明 background 属性,或使用 shorthand syntax :

background: bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-attachment initial|inherit;

在你的情况下,你可以使用这个:

background: url('Enderman_wallpaper.jpg') 0%/30% no-repeat; 

关于html - 你如何在 css 中调整背景图像的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54493486/

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