You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SASS建站CSS定位异常:文章区块无法置于Header下方求助

Fixing Layout Shift Caused by Header Mouse-Parallax Effect

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 to position: relative to contain any absolutely positioned elements inside. Add overflow: hidden to 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’s top/left properties with absolute positioning, double-check that the header container has position: relative (this keeps the image anchored inside the header instead of the whole page). If you’re using transform: 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 adding float or position: fixed to 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:21:18