55

Ok, people who invented CSS... which seems more intuitive and easier to read?

div {
margin-right: auto;
margin-left: auto;
}

Or

div {
center-this-damn-div: true;
}

Comments
  • 12
    The first
  • 3
    Those answering "first", could that be due to already being used to that syntax? I ran the idea past my wife who isn't a coder and she intuitively chose the second syntax option. I'm of the opinion that this kind of thing is what intimidates people new to coding.
  • 1
    @stackodev except the first makes more sense than the 2nd.. even from a newb stand point. I asked my husband the same question you did and he chose the first so :/
  • 3
    margin: inherit auto;
  • 9
    div {
    margin: 0 auto;
    }

    This is how it should be written .... Also if everything was intuitive then developers won't be needed.
  • 3
    Hahahahaha 😂😂😂
  • 6
    Honestly the new CSS is what started to be funky to me. I remember the days when to center something was as simple as valign:middle; align:center;
  • 1
    Well you got Flexbox for that now.
  • 1
    That's because centering something in this way was not really supported in those days of CSS and the margin: auto thing is more of a widely accepted hack.

    Flexbox, after it got its syntax fixed and standardized now and is supported in all major browsers, is a beautifully intuitive way to center and align anything in everything!
  • 1
    @zareef finally found my soul mate 👊
  • 2
    Use SASS and create a mixin called centerThisDamnDiv()
  • 1
    .parent {
    display: flex;
    justify-content: center; /* Horizontal */
    align-items: center; /* Vertical */
    }

    That's as long as flex-direction is set to "row", which is default.
Add Comment