Google字体及页眉背景图片无法生效问题技术求助
Hey Sean, let's break down and troubleshoot your issues one by one—you've got a couple of clear red flags in the CSS you shared, plus some common pitfalls to check for the header background image.
1. Fixing the Google Fonts Not Loading Issue
Looking at your CSS, there are two critical errors causing the font to fail:
- Typos in the import URL: Your link has an extra
xxxat the end (Julius+Sans+Onexxx), which breaks the font request. The correct import should be:@import url('https://fonts.googleapis.com/css?family=Julius+Sans+One'); - Incorrect font-family syntax: You used
'Julius+Sans+One'in the font declaration—browsers expect spaces instead of plus signs here. Change it to:font-family: 'Julius Sans One', sans-serif; - Bonus tip: Always place the
@importstatement at the very top of your CSS file, before any other styles, to ensure it loads with proper priority.
2. Fixing General Text Display Glitches
Your global body styles have two issues causing abnormal text rendering:
- Missing semicolon: You wrote
font-size:100% line-height:1.5px;—this is invalid CSS. Add a semicolon afterfont-size:100%. - Unusable line-height:
line-height:1.5pxis way too small (it forces lines to stack almost on top of each other). Use a unitless value likeline-height:1.5(it scales with your font size) or1.5emfor better readability. - Remove duplicate
font-familydeclarations: You have twofont-familylines on thebodyselector—delete the incompletefont-family: sans...line to avoid conflicts.
3. Troubleshooting Header Background Image Not Showing
For background images, start with these checks:
- Verify the image path: If it's a local image, double-check the relative path (e.g.,
../assets/header-bg.jpgvsassets/header-bg.jpg—depends on where your CSS file is stored). For external images, confirm the URL is valid and accessible. - Ensure the header has dimensions: If your
<header>has no content or no explicit height set, it will collapse to 0 height, hiding the background image. Add amin-heightor fixed height:header { min-height: 300px; /* Adjust based on your design */ } - Complete the background property: Add values for repeat, position, and sizing to ensure the image displays correctly:
header { background: url('your-image-path.jpg') no-repeat center center / cover; }
Corrected CSS Example
Here's a cleaned-up version of your CSS incorporating all fixes:
/* Google Font import (top of file) */ @import url('https://fonts.googleapis.com/css?family=Julius+Sans+One'); /* Global reset */ * { margin: 0; padding: 0; box-sizing: border-box; /* Optional: Makes box model easier to work with */ } /* HTML5 element display fix */ header, main, nav, footer, video { display: block; } body { font-size: 100%; line-height: 1.5; /* Unitless value for responsive line height */ font-family: 'Julius Sans One', sans-serif; } /* Example header styling */ header { min-height: 300px; background: url('your-header-image-path.jpg') no-repeat center center / cover; }
Final Checks
- Clear your browser cache (Ctrl+Shift+R on Windows, Cmd+Shift+R on Mac) to ensure you're loading the updated CSS.
- Open your browser's developer tools (F12) and check the Console tab for 404 errors (indicating broken font/image paths) or CSS syntax errors.
内容的提问来源于stack exchange,提问作者Sean
相关产品推荐
相关产品推荐

