SASS建站CSS定位异常:文章区块无法置于Header下方求助
Hey there! I get how frustrating it is when a cool interactive feature messes up your whole layout—let’s get this sorted out for you.
The root issue here is almost certainly height collapse in your header container, caused by the mouse-parallax JavaScript effect. When you’re translating the header image on mouse move, if the image is positioned absolutely or the container isn’t set to hold its vertical space properly, the container will shrink to 0 height (or an incorrect size), making your article blocks slide up under it.
Here’s how to fix it step by step:
Lock in your header container’s height:
Make sure your header wrapper has a defined height (or min-height) that matches your header image’s dimensions, and set it toposition: relativeto contain any absolutely positioned elements inside. Addoverflow: hiddento prevent the translated image from spilling outside the header area too..header { position: relative; min-height: 600px; /* Match this to your header image's height */ overflow: hidden; }Check your parallax JS logic:
If your script is modifying the image’stop/leftproperties with absolute positioning, double-check that the header container hasposition: relative(this keeps the image anchored inside the header instead of the whole page). If you’re usingtransform: translate()(the better practice for performance), this won’t break the layout flow, but you still need the header container to have a set height.Debug with browser dev tools:
Hit F12 to open your browser’s developer tools, select the header element, and check the "Computed" tab to see its actual height. If it’s way smaller than expected, that’s the height collapse issue. You can also toggle the parallax JS on/off temporarily to confirm it’s the cause of the layout shift.Avoid layout-breaking properties:
Make sure your JS isn’t accidentally addingfloatorposition: fixedto the header or image without accounting for the space it needs—these properties can yank elements out of the normal document flow and mess up content below.
Once you fix the header container’s height and positioning, your article blocks should sit neatly below it like you want!
内容的提问来源于stack exchange,提问作者Reena Verma

