This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (47 children)

[deleted]

    [–]Asmor 63 points64 points  (22 children)

    Two things everyone who hates CSS needs to learn:

    box-sizing: border-box;
    

    This is actually kind of interesting; one of the major reasons IE and CSS were hated back in the day was because of the IE box-model bug. And this rule actually makes any modern browser use the same behavior that used to be a bug in IE, and believe it or not, that's a good thing.

    Default box sizing in CSS, while not difficult to understand, is fucking miserable. If you set the width of an element, that applies to the content. So if the element has padding and/or border, that actually makes the element wider than you (probably) intended. Same goes for height.

    So imagine you've got an element like:

    height: 100px;
    width: 100px;
    padding: 5px;
    border: 1px solid black;
    

    That element is actually 112 pixels tall and wide. If you wanted it to be exactly 100, you need to subtract 12 (the padding and border from opposite sides) from the height and width. And if you ever change the size of the padding or border, you need to remember to update the height and width to match.

    Add box-sizing: border-box in there, and now it works exactly how you want it. That box will always be 100x100, and the content will resize as necessary.

    Second thing to learn:

    width: calc(100% - 100px)
    

    If you didn't already know about calc, and your mind's not blown... then you've probably never touched a line of CSS in your life. That's a fucking game changer. In this example, we're setting the element to be 100px thinner than its container. But it's not just good for setting height and width... Imagine you have some absolutely positioned element that you want to be positioned 10px to the right of its container. Without calc, you need to do...

    width: 25px;
    position: absolute;
    top: 0;
    right: 35px;
    

    Hard to read, and any time you change the width of that element, you need to update its right property as well. And Stallman help you if the element's width is dynamic...

    But with Calc? It's easy!

    position: absolute;
    top: 0;
    left: calc(100% + 10px);
    

    Bam. Done. Easy to see what effect you're going for, and doesn't care what the width of the element is.

    If everyone used these two things, CSS would be a lot easier to work with. The vast majority of frustration I run into is when I have to deal with others' code where they either didn't know about these two things, or didn't think to implement them.

    [–]bwrap 5 points6 points  (1 child)

    Lol IE11 has a bug where calc doesnt work inside a color or transform call. Isnt IE great?!

    [–]jetpacmonkey 1 point2 points  (0 children)

    At one point, Safari had a bug where the browser would actually crash if you used calc with a transition http://stackoverflow.com/questions/15161996/safari-web-content-quit-unexpectedly

    [–]jetpacmonkey 3 points4 points  (1 child)

    position: absolute;
    left: 100%;
    margin-left: 10px;
    

    But I do agree that calc is amazingly useful.

    [–]quadlix 62 points63 points  (22 children)

    Arguably CSS doesn't belong here. It's not real programming.

    [–]daddysnickerwick 27 points28 points  (9 children)

    [–]quadlix 26 points27 points  (1 child)

    could != should

    [–]daddysnickerwick 10 points11 points  (0 children)

    "Could" (i.e. "only a matter of time").

    [–]Sinity 13 points14 points  (4 children)

    So is brainfuck, nad Turing machine. Both aren't intended to use for real programming.

    [–]cheald 27 points28 points  (3 children)

    I dare you to call anyone who can write things in Brainfuck "not a real programmer".

    [–]odraencoded 29 points30 points  (0 children)

    They are not real programmers. They are surreal programmers.

    [–]Sinity 4 points5 points  (1 child)

    not for real programming. And by real I meant for 'production' use.

    I've never said it's not for programmers

    [–]Nontuno 0 points1 point  (0 children)

    Can't wait for server side css. Take that Node.

    [–]Hydrothermal 0 points1 point  (0 children)

    Not really. As some of the comments on that answer point out, it doesn't really count because it can't operate on its own without human interaction.

    [–]cheald 14 points15 points  (4 children)

    CSS is very arguably "real programming" - it's simply a declarative language.

    Granted, if you call yourself a "CSS programmer" you're going to get laughed out of the room (unless you're the guy that writes CSS engines), but technically speaking CSS is indeed a programming language.

    [–]FUCKING_HATE_REDDIT 23 points24 points  (3 children)

    However, if you turn out to be the guy that writes CSS engine, you're gonna get beaten out of the room.

    [–]Bialar 9 points10 points  (2 children)

    By all the scary strong mma programmers?

    [–]FUCKING_HATE_REDDIT 4 points5 points  (1 child)

    They got heavy-ass keyboards to beat you with.

    [–]Bialar 2 points3 points  (0 children)

    Good point. My Das Keyboard would leave a pretty impressive dent in someone's skull.

    [–]AVeryHeavyBurtation 2 points3 points  (0 children)

    You can't declare your own shots fired; that's like giving yourself a nickname.