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

CSS媒体查询规则未生效,指定选择器未被检测求助

Hey Steve, let’s work through why your media query rule isn’t taking effect and fix it step by step:

  • Validate the actual DOM nesting structure
    Even though div#tdr-gallery-our-work exists in your source code, plugins like Isotope often dynamically rearrange gallery items in the DOM after page load. Open your browser’s DevTools, locate the target .isotope-item, and trace up its parent elements—confirm it’s still nested directly under #tdr-gallery-our-work. If the plugin moved the item outside this container, your selector will never match.

  • Check selector specificity and CSS loading order
    Your media query uses an ID selector (#tdr-gallery-our-work) combined with classes, which should have higher specificity than the default .wpb_image_grid .wpb_image_grid_ul .isotope-item rule. To eliminate any edge cases:

    • Ensure your media query CSS loads after the default gallery styles. If it loads earlier, some browsers might prioritize later-loaded rules (even with lower specificity, though this is rare).
    • Boost the selector specificity further to guarantee it overrides the default rule. Modify your media query like this:
      @media (min-width: 981px) {
        body #tdr-gallery-our-work .wpb_image_grid .wpb_image_grid_ul .isotope-item {
          max-width: 9.09090909% !important;
          position: relative !important;
          left: auto !important;
          top: auto !important;
        }
      }
      
  • Scan for syntax errors in surrounding CSS
    A missing closing bracket } in a rule above line 449 can cause the browser to ignore your entire media query block. Double-check the CSS immediately before your media query for unclosed rules or invalid syntax that might break parsing.

  • Debug with an inline style test
    To confirm the issue is with the selector/media query (not the value itself), temporarily add an inline style to one .isotope-item:

    <li class="isotope-item" style="max-width:9.09090909% !important;"></li>
    

    If this works, the problem is definitely that your selector isn’t matching the element.

  • Clear browser cache
    Outdated cached CSS can prevent new rules from applying. Force a hard refresh (Ctrl+F5 on Windows/Linux, Cmd+Shift+R on macOS) to load the latest version of your stylesheet.

内容的提问来源于stack exchange,提问作者Steve

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 16:42:29