簡體   English   中英

如何在背景中放置封面圖像?

[英]How to position a cover image in the background?

我使用以下代碼將圖像放置在div的背景中:

background: url(../images/cover-image.jpg) no-repeat 50% 100% fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 30rem;

但是我現在的問題是,我想在div中移動圖像的可見部分。 圖片的底部應位於div的底部,但我可以更改background:所有內容background: center bottom50% 100%等)語句,什么也沒發生。

有人可以給我提示嗎?

嘗試使用

background-position: center bottom;

您需要刪除“背景”減速中的其他樣式,然后放入:

background-position:bottom;

在這里看到小提琴: https : //jsfiddle.net/xerf3z5j/

作為一行,這將是:

background: transparent url(../images/cover-image.jpg) center bottom / cover no-repeat fixed;

background-size:cover表示背景圖像將始終占據div的整個寬度和高度。

如果您卸下這些部分,則應該可以使用:

-webkit-background-size: cover;
-moz-background-size: cover;
 -o-background-size: cover;
 background-size: cover;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM