Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
feat(body): add background image with transparency
Browse files Browse the repository at this point in the history
The background image is added to the body element with transparency, which does not affect child elements.
  • Loading branch information
gytxtx committed Sep 4, 2024
1 parent 14c0172 commit 340a783
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 148 deletions.
Binary file added assets/images/121201261_p0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions css/background-image.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* 针对整个页面设置背景图片 */
/* 保留备用 */
body {
background-image: url('./assets/images/121201261_p0.jpg');
/* 替换为你的图片路径 */
background-size: cover;
/* 图片大小覆盖整个屏幕 */
background-position: center center;
/* 背景图片居中显示 */
background-repeat: no-repeat;
/* 不重复背景图片 */
background-attachment: fixed;
/* 背景图片固定不动 */
opacity: 0.8;
/* 设置整体透明度,注意这会影响所有子元素 */
}

/* 针对某个具体的 div 设置背景(备用) */
.background-div {
background-image: url('./assets/images/121201261_p0.jpg');
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
opacity: 0.8;
/* 设置该 div 的透明度 */
}

/* 不影响子元素的透明度 */
/* 针对整个页面设置背景图片 */
body {
background-image: url('./assets/images/121201261_p0.jpg');
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
/* 使用 rgba 定义颜色和透明度,并与背景图片混合 */
background-color: rgba(255, 255, 255, 0.2);
/* 这里以白色为例,可以根据需要调整颜色和透明度 */
background-blend-mode: normal;
/* 根据需要选择混合模式 */
}

/* 针对某个具体的 div 设置背景(备用) */
.background-div {
background-image: url('./assets/images/121201261_p0.jpg');
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
/* 使用 rgba 定义颜色和透明度,并与背景图片混合 */
background-color: rgba(0, 0, 0, 0.5);
/* 这里以黑色为例,可以根据需要调整颜色和透明度 */
background-blend-mode: multiply;
/* 混合模式,根据需要选择 */
}
Loading

0 comments on commit 340a783

Please sign in to comment.