我知道這種類型的問題已被問及一百萬次,看起來有大量的重複,但我一直無法找到文檔或找出如何非常具體:固定高度的全瀏覽器寬度響應背景圖像
- 使圖像100%寬度的瀏覽器窗口。
- 使圖像成爲背景圖像。
- 使圖像響應。
- 使圖像具有可調整的固定高度。 (意味着我可以使它
500px
高大或800px
高大並且它保持其寬高比和全瀏覽器的寬度)
這是可能做與純CSS或是jquery的或javascript需要?
我也對引導技術開放。
目前我有這種技術,但它的侷限性在於我無法真正定義高度,並且在將內容放入內容時圖像會被裁剪。
HTML:
<div class="page-section">
<?php if(get_field('landing_hero_image')): ?>
<div class="hero-img-wrap">
<div class="landing-hero" style="background-image: url(<?php the_field('landing_hero_image'); ?>);">
</div>
</div>
<?php endif; ?>
</div>
CSS:
.page-section {
width:100%;
position: relative;
}
.landing-hero {
padding: 22% 0 20% 0;
margin:auto;
width: 100%;
min-height: 100%;
-webkit-background-size: cover !important;
-moz-background-size: cover!important;
background-size: cover!important;
-o-background-size: cover!important;
}
你爲什麼調用動態背景圖像?是否有理由不能設置'background-image'以及其他CSS屬性? – TheAcolyte
@TheAcolyte我在wordpress中使用高級自定義字段。 – rlm