Skip to content

Commit c57595d

Browse files
committed
Add support for background images in CSS
1 parent adb93e3 commit c57595d

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

config/webpack.common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ module.exports = {
6363
extensions: ['.js', '.jsx', '.json'],
6464
alias: {
6565
'@': paths.src,
66+
assets: paths.public,
6667
},
6768
},
6869
}

public/example.jpg

-92.3 KB
Binary file not shown.

public/example.png

13.4 KB
Loading

src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,13 @@ logo.src = webpackLogo
1414
const heading = document.createElement('h1')
1515
heading.textContent = example()
1616

17+
// Test a background image url in CSS
18+
const imageBackground = document.createElement('div')
19+
imageBackground.classList.add('image')
20+
21+
// Test a public folder asset
22+
const imagePublic = document.createElement('img')
23+
imagePublic.src = '/assets/example.png'
24+
1725
const app = document.querySelector('#root')
18-
app.append(logo, heading)
26+
app.append(logo, heading, imageBackground, imagePublic)

src/styles/_scaffolding.scss

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,23 @@ html {
33
font-family: $font-family;
44
background: $background-color;
55
color: $font-color;
6-
max-width: $page-width;
76
line-height: 1.4;
87
}
98

109
body {
11-
margin: 0;
12-
width: 100vw;
10+
margin: auto;
11+
text-align: center;
12+
max-width: $page-width;
1313
}
1414

15-
#root {
16-
display: flex;
17-
align-items: center;
18-
justify-content: center;
19-
flex-direction: column;
20-
align-self: center;
21-
height: 100vh;
15+
h1 {
16+
margin: 0 0 2rem;
2217
}
2318

24-
h1 {
25-
margin: auto;
26-
text-align: center;
27-
max-width: 90vw;
19+
.image {
20+
display: inline-block;
21+
height: 100px;
22+
width: 100px;
23+
background-image: url('~assets/example.png');
24+
background-size: cover;
2825
}

0 commit comments

Comments
 (0)