我試圖應用背景圖像漸變在圖像上設置它的父div
,但它沒有效果,這是奇怪的,所以我以前這樣做。背景圖像漸變不適用
<header id="hero">
<div id="hero-image">
<a href="#"><img src="http://placeholdit.imgix.net/~text?txtsize=44&txt=Hero%20Image&w=1920&h=500" /></a>
</div>
</header>
header#hero {
margin: 0 auto;
width: 100%;
font-size: 1rem;
}
header#hero #hero-image {
background-image: linear-gradient(transparent 50%, black 100%);
}
header#hero #hero-image img {
display: block;
width: 100%;
max-height: 500px;
object-fit: cover;
}
演示:http://codepen.io/ourcore/pen/xgqNZJ
我同意,但不幸的是,我不能在我的web應用程序中使用此方法,因爲圖像將由CMS動態插入。 –
@MarioParra您可以使用內聯樣式查看上面的更新信息。 – Stickers
@MarioParra我不知道答案是否有幫助,請標記或評論。 – Stickers