Bootstrap Vertical Center contents in row

后端 未结 1 1095
情深已故
情深已故 2021-01-23 00:24

I have a simple table-esque layout in Bootstrap 3 as such (it\'s a \"property grid):

相关标签:
1条回答
  • 2021-01-23 00:38

    Vertically centering float-based content is very problematic. There are a handful of hacks to do it (using transformations or negative bottom margins), but it is far easier to use display table or flexbox for the layout.

    Change the row to flexbox like this:

    .pgRow {
      background:yellow;
      display: flex;  /* make the row a flex container */
      align-items: center; /* vertically center each flex item in the container */
    }
    

    Be sure to remove the height from the .va! Generally, you should not set heights on containers in CSS; doing so will only introduce a load of other problems.

    For more options, check out http://howtocenterincss.com/. To get a handle on flexbox, check out this article on CSS Tricks. To really get a handle on all these things and how they work together (shameless plug alert), checkout my book.

    0 讨论(0)
提交回复
热议问题