74
linuxxx
7y

After 3-4 FUCKING hours I finally found a bootstrap thingy which properly centers a div!

In my defense, this shit is all Chinese to me so it's copy-paste-lets-hope-this-works 😅

Comments
  • 22
    display: block;
    margin: auto;

    Done.
  • 1
    @olback What exactly? A main div for example?
  • 0
  • 13
    @linuxxx I know the feels when a non-frontend guy tries frontend
  • 0
    margin-left: 40vw;
    margin-right: 40vw;
  • 0
    Been there done that

    Setting up OAuth in rails app
  • 0
  • 1
    You can also use flex
  • 2
    @olback Tried that but it's stayed left-top. Thanks for the suggestion anyways!

    Going to try one more thing and if that doesn't work, fuck it, bootstrap.
  • 0
    @linuxxx it doesn't work if position is absolute/fixed.
  • 3
    For horizontal, you can achieve without any new css lines if you are using bootstrap.

    div.row
    > div.col-sm-4.col-sm-offset-4
    >> center

    If also considering vertical, you do need css. Yep.

    There is nothing wrong with using bootstrap. 🕺
  • 2
    #div {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translateX(-50%) translateY(-50%);
    }

    If only vertically, remove "left: ..." and "translateX()".
    If only horizontally, remove "top: ..." and "translateY()".

    My favorite solution next to "margin: auto;"
  • 1
    @olback the css file was empty :)
  • 1
    I'm getting somewhere, not the most beautiful solution but hey, it works!
  • 1
    Wrap it with another div.
    .wrapper: {display: flex;}
    .content: {margin auto;}

    Content is now aligned vertically and horinzontally.
  • 0
    I’m not frontend. I hate it with a passion that is still unmatched by a billion exploding suns.

    It’s messy. It’s ridiculous. It’s not internally consistent in any way at all.

    Simple things are stupidly difficult and yet remarkably complex things like flipping something in 3D using CSS is made trivial (wtf?!)

    I feel your pain. So hard.
  • 7
    AlgoRythm{
    body: sexy;
    dick: HUUUUUGE !important;
    eyes: bluegreen;
    }
  • 0
    @Alice I've always agreed that it's not the size, but how you use it.

    But it's a hell of a lot easier to use a big dick
  • 1
    @Alice Yeah, like smashing rocks with a big hammer is easier than with a small one
  • 3
    @AlgoRythm are you crushing rocks with your penis?
  • 0
    @hubiruchi Hell yeah, don't we all?
  • 1
    @Alice I don't think it's appropriate to get graphic and detailed, but if there is more surface area, there is more stimulation. That's where I will end this.
  • 2
    I am the wizard of the north pole@irene
  • 1
    What happened to the container grid system?

    I remember there 12? cells in a row just tell the element to use the middle ones
  • 0
    I think there's a bootstrap class that offsets the div. Something like col-xs-offset-4
Add Comment