29
linuxxx
5y

Spend quite a while at work trying to get two divs inside a centered div next to each other and especially get them the same height as the parent div.

Got it working after numerous tries, was going to take the code home to continue.

Forgot to take the code home, have to start over again and I hardly understand CSS 😥

Fuck me. (Writing a new service thingy by the way)

Comments
  • 3
  • 1
    Set to inner div

    height:100%

    This should work
  • 3
    @yendenikhil I've done this but no result with that one :/ (I do know the CSS basics)
  • 7
    Flexbox ftw.
    Also; TailwindCSS ftw
  • 3
    I agree with @xewl, take a look at flexbox (or if IE support isn't an issue, even grid) css-tricks is a pretty good ressource for it: https://css-tricks.com/snippets/...
  • 3
    @linuxxx try flexbox ... Rlly
  • 1
    Centering sucks in CSS. Especially vertical centering.
  • 1
    @linuxxx
    1. Is the height defined in the parent (centered) div or one of the inner divs?

    2. Does the height of all have to expand by the content of the inner divs? (no overflow/hiding)

    3. Is the parent centered horizontally and/or vertically?

    There are multiple possibilities depending on your requirements, even without the use of flexbox.
  • 2
    @Kaji It's not that difficult. The problem is rather that it's often either tought badly or not correctly explained.

    There are multiple ways of v-centering stuff:

    - inline/line-height approach
    - absolute pos/translate approach
    - relative pos/translate/neg. margin approach
    - table-cell approach
    - flexbox

    Which you chose depends on other factors such as:
    - whether the outer container should grow in height if v-center content is vertically too big
    - whether the outer countainer has a defined height
    - what kind of other styles have to be applied the the v-center container
    - browser compat.
  • 3
    Grid and Flexbox FTW
  • 4
    Centering in CSS: A Complete Guide

    https://css-tricks.com/centering-cs...
  • 2
    @tyrogge Excellent resource! Used that one several times.
Add Comment