Mihai
Mihai

Reputation: 2937

Vertically center a div inside a display: table-cell element?

I am trying to center a div inside a table-cell element. I really tried all the previous answers but I simply could not figure it out. Here is the code I am using:

Rendered HTML

As I mentioned, I tried everything I found on but nothing did the trick. I would really appreciate your help! Thank you!

Upvotes: 1

Views: 765

Answers (1)

Marcos Pérez Gude
Marcos Pérez Gude

Reputation: 22158

Add vertical-align: middle because is a table cell style, if you change the table cell style the trick will be other, but without changing nothing:

.selection {
  display: table-cell;  
  width: 50%;
  padding: 0 10px 0 10px;
  vertical-align: middle;
}

I add the fiddle link to show this works:

https://jsfiddle.net/qL5sf9uo/

Upvotes: 4

Related Questions