html - img 标签中的渐变属性
问题描述
我正在尝试渐变我的图像,但它从未显示
.asdf img {
background: rgb(2,0,36);
background: linear-gradient(0deg, rgba(2,0,36,1) 0%, rgba(9,9,121,1) 35%, rgba(0,212,255,1) 100%);
}
<div class="asdf text-center tx-white">
<img style="height: 200px;" class="w-100 shadow-sm bd" src="{{url($xd->banner)}}"alt="">
</div>
在图像上显示渐变的正确方法是什么?
解决方案
您可以将其作为背景图像,而不是作为 img。
.asdf img {
object-fit: cover;
}
.asdf .img { background-image:
linear-gradient(to bottom, rgba(245, 246, 252, 0.52), rgba(117, 19, 93, 0.73)),
url('https://cdn.the-scientist.com/assets/articleNo/66864/aImg/35078/foresttb-l.jpg');
width: 80%;
height: 500px;
background-size: cover;
}
<div class="asdf text-center tx-white">
<div class="w-100 shadow-sm bd img" ></div>
</div>
使用 img 标签更新的线性渐变:
img {
max-width: 100%;
}
.hero-image {
max-width: 100%;
width: 800px;
margin: auto;
}
.hero-image::after {
display: block;
position: relative;
background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0, #fff 100%);
margin-top: -150px;
height: 150px;
width: 100%;
content: '';
}
<div class="hero-image">
<img src='https://cdn.the-scientist.com/assets/articleNo/66864/aImg/35078/foresttb-l.jpg' />
</div>
推荐阅读
- html - 如何将开关按钮与表单连接
- mysql - CREATE TABLE SPONSORSHIP 中的 UNIQUE CONSTRAINT 含义
- git - 如何在 Qt Creator 中正确切换 git 的分支?
- ios - 自动缩小多个 ui 标签的文本大小
- xslt-2.0 - saxon9HE 中的指数或幂计算
- excel - 使用求和积函数 Excel 逐行递增一列
- sql - 使用 SQL 检查 CosmosDB JSON 中是否存在字段 - nodeJS
- unicode - 为什么 Unicode 被限制为 0x10FFFF?
- java - @JsonValue 和 @ApiModelProperty 冲突
- jquery - Jquery 自动完成组合框 - 如何从数据库加载数据?