1

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:

  • HTML skeleton:

    <div class="selection"> <div class="selection_empty"> <p>No selection.</p> <p>Click the button below to start the process.</p> <span class="selection_icon ico_add_medium"></span> </div> </div> 

Rendered HTML

  • CSS style:

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

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

1
  • 1
    You should change your post to say "vertically center" a div, rather than "center", as that usually implies horizontal alignment. Commented Feb 15, 2016 at 15:01

1 Answer 1

4

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/

Sign up to request clarification or add additional context in comments.

4 Comments

Hey, don't downvote if you don't know about this topic. It works perfectly, see the fiddle: jsfiddle.net/qL5sf9uo
Dont put the fiddle here. Up There ^^^^
I edit the answer 1 minute ago with the link, however, I'm not meritory of your downvote. I hope this helps to OP
Thank you, it worked like a charm. You determined me to study more carefully the display: table properties.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.