[英]How to scale a background image to fit the full width of the screen while maintaining aspect ratio? Height is cut off when I use "cover"
客觀的
這是我的網站https://saddhustore.com.br/moda/ 。 我希望頂部的主圖像按比例縮小以適應 1366x768 屏幕,就像在我的 1920x1080 中一樣,顯示所有圖像,而不會扭曲縱橫比。
我嘗試了什么
我在 WordPress 中使用 Elementor。 在“自定義 CSS ”部分中,我嘗試添加以下代碼:
selector {
background-size: cover; OR background-size: contain; OR background-size: 100% auto;
}
使用封面時,我嘗試添加background-attachment: fixed
和height: 100%
無濟於事。
應用 MAGGI 的建議后的結果
注意最底部被切斷
出於某種原因,它在 Elementor 中看起來很完美
在 css 中添加以下代碼(注意:像這樣將選擇器的高度設置為手動):
selector { background-size: cover; background-repeat:no-repeat; background-position:center; height: 50vh /*manual add*/; width:100vw; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.