css - 在 div 的背景中对齐 2 个图像
问题描述
我想将 2 张图片作为背景图片放入 div 中。
这是我放的代码,但我只看到第二张图片。
#wrap-header {
max-width: 100%;
height: 400px;
background-image: url("../assets/header_background.png"), url("../assets/circle_header_background.png");
background-repeat: no-repeat;
background-position: center bottom, center top;
}
<div id="wrap-header">
</div>
我想检索一个图像在另一个图像下的效果,或者一个图像作为第一层,第二个在底部。
我找不到办法。你能帮帮我吗?
解决方案
您可以使用 CSS 选择器:after和:before执行此操作
首先,将以下内容添加到#wrap-header:
#wrap-header {
position: relative;
overflow: hidden;
max-width: 100%;
height: 400px;
}
然后使用选择器:
#wrap-header:before {
content: '';
position: absolute;
top: 0;
left: 0;
height: 50%;
width: 100%;
background-image: url('image1');
background-repeat: no-repeat;
background-position: center
}
#wrap-header:after {
content: '';
position: absolute;
bottom: 0;
left: 0;
height: 50%;
width: 100%;
background-image: url('image2');
background-repeat: no-repeat;
background-position: center;
}
推荐阅读
- java - java - 如何在java中使用三个嵌套的for循环来实现带有_的倒金字塔?
- android - 有没有什么特别的方法可以让系统卸载弹出窗口出现在android中的监听器
- android - 想从 firebase 数据库中检索唯一的卢比值吗?
- c# - 当 switch (enum) 不覆盖 COMPILE C# 中的每个枚举值时是否可以发出警告
- bash - 如何在 nextex ssh 会话中设置变量
- android - 从左向右滑动时手势检测器不起作用
- c# - 如何从 JSON 字符串中删除特定的 JSON 属性
- spring-boot - CorruptedTransactionLogException : 发现损坏的日志
- python - 如何在 QML 中使用 QtWebEngine
- node.js - 如何在 Foreach 中同步运行 Mongoose Find