0

I'm trying to center align a div that is located within another div. I want to vertically center the "options" div that is located inside the "plan-container"

Thanks in advance.

.plan-container {
    width: 960px;
    height: auto;
    margin-top: 62px;
    overflow: hidden;
    background-color: red;
}

.options {
    float: left;
    width: 151px;
    height: 100px;
    background-color: green;
}

.plan {
    float: left;
    width: 220px;
    height: 600px;
    margin-left: 23px;
    background-color: purple;
}

.plan:last-child {
    float: right;
}

.plan-featured{
    width: 300px;
    height: 600px;
    background-color: purple;
}
<div class="plan-container">
  <div class="options">Options</div>
  <div class="plan">Box one</div>
  <div class="plan plan-featured">Box two</div>
  <div class="plan">Box three</div>
</div>
Richard Rodgers
  • 617
  • 1
  • 7
  • 17

3 Answers3

1

Vucko's answer is correct. I wanted to add a comment, but since I don't have enough reputation yet, I'll just post it as an answer.

You can use the vertical-align property on the inner div that needs centering. This property only works on elements that have display:inline-block or display:table. Refer to the actual spec here.

Repeating Vucko's answer:

.options {
    display: inline-block;
    vertical-align: middle;
}
Awol
  • 345
  • 2
  • 13
0

Try it-

.plan-container {
    display: flex;
    flex-wrap: wrap; /* optional. only if you want the items to wrap */
    justify-content: center; /* for horizontal alignment */
    align-items: center; /* for vertical alignment */
}
Neeraj Prajapati
  • 541
  • 5
  • 24
0

You can use inline-block instead of float, and than you can use the vertical-align property:

.plan-container>div{
  display: inline-block;
  vertical-align: middle;
}

JSFiddle

However, beware of the whitespace issue.

Community
  • 1
  • 1
Vucko
  • 20,555
  • 10
  • 56
  • 107