![](/img/trans.png)
[英]How to display an image in full screen background using reactJS and css?
[英]How to set a full background image in CSS using reactjs style?
您要查找的CSS屬性是background-size
,不是background-position
。 我通常用於執行此操作的代碼段是:
background-size: cover;
background-repeat: no-repeat;
background-position: center;
background-image: url(path/to/image);
或與React
<div style={{
backgroundSize: 'cover',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
backgroundImage: `url(${pathToImage})`,
}} />
編輯:這可能超出了問題的范圍,但是我建議您在其他地方聲明樣式對象,並在每次您希望具有相同背景效果時將其導入,以便於重用。
這與ReactJS無關,而只是CSS問題。 您應該使用background-size:cover
而不是background-position
因為background position屬性設置背景圖像的起始位置,而不是設置圖像的大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.