html - 如何在横幅图像上应用白色叠加层
问题描述
我正在做一个 React 项目。但这个问题与 React 无关。我遇到了很多解决方案,但没有一个对我有用。这是我的代码。
应用程序.js
...
import bannerimage from "./assets/images/bg-banner.jpeg";
function App() {
const overlayOnBanner = {
width: '100%',
height: '100%',
background: "rgba(229,229,229,0.3)",
backgroundSize: 'cover'
};
const banner = {
width: '100%',
height: '800px',
backgroundImage: `url(${bannerimage})`,
backgroundSize: 'cover'
};
return (
<div className="App">
<div style={overlayOnBanner}>
<div style={banner}>
</div>
</div>
</div>
);
}
export default App;
请指出我的错误。
解决方案
这就是我会做的事情注意我在造型和所有方面都没有太多关注
.overlay {
position: absolute;
top:0;
background: rgb(0, 0, 0);
background: rgba(229,229,229,0.3); /* Black see-through */
color: #f1f1f1;
width: 100%;
transition: .5s ease;
color: white;
height: 300px;
}
.image{
width: 100%;
height: 300px;
}
<img src="https://cdn.pixabay.com/photo/2016/05/05/02/37/sunset-1373171_960_720.jpg" alt="Avatar" class="image">
<div class="overlay"></div>
推荐阅读
- javascript - Python Selenium 按钮没有被点击
- php - If 语句条件 If Element Exists 使用 PHP
- node.js - 如何在 ChoicePrompt 上运行 Luis Recogniser
- ansible - 使用 Ansible Galaxy 自动安装 Ansible 自定义模块
- java - 在 JDK9 及更高版本中使用 tools.jar
- matlab - matlab urlread、webread 和 websave 无法连接到任何 url
- python - 今天和日期python之间的区别
- c - 在我输入 scanf 接受的输入后程序立即退出
- php - 模型回调中的 Codeigniter 表单验证回调不起作用?
- javascript - Web 可访问性 - 屏幕阅读器在鼠标悬停和选项卡上以不同方式读取 HTML 元素