brox
brox

Reputation: 99

Center label vertically within element of calculated height

I have following layout:

<div class="next">
  <div class="main">
    <div class="actions">
      <label><input type="checkbox" checked="">Label1</label>
      <label><input type="checkbox" checked="">Label2</label>
      <button>Button number 1</button>
      <button>Button number 2</button>
    </div>
    <div class="target"></div>
  </div>
</div>

and corresponding style:

.next {
  position: relative;
  min-height: 320px;
  width: 98vw;
  background: #fee;
}
.main {
  display: inline;
  float: left;
  width: 280px;
    margin: 2px 0 6px 4px;
  background-color: #fff;
}
.target {
    background: #ffa;
    clear: both;
    border: 1px solid black;
  border-radius: 5px;
    width: 280px;
    height: 280px;
    margin: 0 auto;
}
.actions {
    width: 280px;
    margin: 0 auto;
  background: #cfc
}
.actions button {
    width: 67px;
    margin-right: 4px;
    margin-bottom: 4px;
  padding: 2px;
  border-radius: 5px;
}
.actions button:last-child {
    margin-right: 0;
}
.actions button:hover {
  background-color: #eee;
}
.actions button:focus {
  outline: 0;
  background-color: #cce;
}
label {
  font: 10pt sans-serif;
}

As you see, "actions" div has remaining height of what is left after subtracting "target" square height from the whole container's height. And now I want controls inside "actions" div to be aligned vertically.
It would align, if buttons had short one-lined names, but they are long and wrap into 2 lines. Usual trick with defining line-height does not work.
Any ideas how to fix it?

http://jsfiddle.net/KgqJS/570/

Upvotes: 0

Views: 44

Answers (1)

Nandl66
Nandl66

Reputation: 284

Something like this? Just use display table (wrapper div) + table-cell (inner div)

.actions {
    display: table;
    ...
}

label {
    display: table-cell;
    vertical-align: middle;
    ...
}

Upvotes: 1

Related Questions