73

A story of the backend dev. from our client:

"I used !important once now I'm not allowed to do frontend anymore :("

Comments
  • 1
    Ive used it a few times, but for printviews and the like. The only reasons you are allowed to use important
  • 0
    @Codex404 I also use this for certain stuff in desktop layout while the mobile layout has some JavaScript depending on the scroll direction. Now if the browser gets resized to desktop, the !important overrides whatever the JS in mobile layout had been doing so that I don't need the resize handler.
  • 2
    @Fast-Nop thats bad practice though
  • 1
    @Codex404 what would be better practice? Using a resize handler? That would cost performance.
  • 2
    🤣🤣🤣 Must have been important.
  • 1
    @DivSyntax you mean !important
  • 0
    @irene Well of course, that is also there. But media queries alone don't allow to blend the menu in/our depending on the scrolling direction because that is dynamic behaviour.

    Suppose the following sequence:
    - window width "mobile"
    - scrolling down (JS sets menu position to "auto")
    - window width enlarged to "desktop" mode
    - desktop media query kicks in and selects position "sticky"
    - but because it had been set to "auto" via JS, it stays with "auto" since JS has precedence.

    Therefore, I set the desktop menu position to "sticky" with "!important" so that it will override possible previous JS activities. Alternative would be to catch the resize, but I don't want to use an unnecessary handler just to avoid "!important".
  • 0
    @Fast-Nop if you dont use javascript to do styling there is no need for CSS hacks.
  • 0
    @Codex404 OK, then how do I blend in/out the menu depending on the scrolling direction without use of JavaScript?
  • 1
    Ill make an example this weekend
  • 1
    @Codex404 yeah OK, but please also include a slight hystereris so that it takes a bit of scroll reversal to trigger an actual direction change. Otherwise, a tattering finger would make the menu blend in/out rapidly, which would be confusing.
  • 0
    @Codex404 did you get around to the example? If not, some search engine keywords would probably suffice to get me on the track, but which ones do you recommend?
  • 0
    I think I may have a bad coworker. I see that keyword a lot and don't know exactly what it means, but judging by the comments I feel like I'm in a pickle.
  • 1
    @Charon92 i feel ya. I’ve seen this many times and still don’t get it what people think when they coding :|
  • 0
    It’s a great feature for debugging css styles.

    But lol! Try something. Be told it is wrong. Never be allowed to learn and correct. Inconceivable! 😂
  • 0
    @irene apologies. I guess that was only funny to me. As that was my experience. Couldn’t read javascript without if blocks having curly braces. After a week I could. But too late.
  • 0
Add Comment