CSS, Motha-&#@%er do you speak it?



  • Consider this snippet of CSS. This is similar to what I found today in our code.

    html {
    /* There is nothing important here, other than whatever the user stylesheet puts in */
    }
    
    body  {
        background: url('somebackground.png') no-repeat top left;
        font-family: 'Open Sans', 'Arial', sans-serif;
        height: 100%;
        line-height: 20px;
        overflow: scroll !important;
        position: static !important;   
        z-index: -2;
    }
    
    

    Lets consider how dumb this is:

    • Position static is the default for everything unless specified otherwise. Also the only style in inherits in regular bootstrap, which isn't setting a position property other than static. So redundant.
    • The z-index property only works if the position isn't static. So it is redundant also.
    • The html tag doesn't have a height specified therefore the browser can't calculate the body height because the browser is saying "100% of what?, Well I will just make it as big as it needs to be". So this is redundant.
    • Overflow scroll needs a height (doesn't have one)
    • The browser already provides a scrollbar for top level elements, unless specifically told not to do so e.g like google maps.

    0_1520882083874_1d951091-f628-44e5-a72e-1c219f71dabf-image.png

    EDIT: I can understand some dumb stuff near the end of the style sheet, but this was the first rule in the sheet.


  • Considered Harmful



  • @pie_flavor FFS I haven't seen that movie in over 20 years.




Log in to reply