F21
F21

Reputation: 33383

Display: table-cell problems in chrome

I have 3 divs that I would like to display as table cells:

<div class="field">
    <div class="row">
        <label for="name">Subdomain</label>
        <input type="text" id="name" name="name">
        <div class="subdomain-base ">test</div>
    </div>
</div>

This is the CSS that I am using:

body{
    font-size: 13px;
}

.field {
    width:450px;
    display: table;
}
.row {
    display: table-row;
    width: 100%;
}
.row > * {
    display: table-cell;
    border: 1px solid red;
}
label {
    width: 125px;
    height: 18px;
}
input {
    max-width: none;
    min-width: 0;
    overflow: auto;
    height: 18px;
    width: 100%;
}
.subdomain-base {
    height: 18px;
    width: 1px;
}
.subdomain-base {
    color: blue;
    font-size: 13px;
}

It works perfectly in Firefox 24: enter image description here

However, it has a height problem in Chrome 30 (latest): enter image description here

I have been trying all sorts of things to fix the problem with Chrome, but it seems like nothing works. Why is chrome getting that extra height?

Jsfiddle: http://jsfiddle.net/ahLMH/

Upvotes: 4

Views: 13692

Answers (3)

F21
F21

Reputation: 33383

The problem appears to be due to display: table-cell on input elements being experimental. See this question for more details: display:table-cell not working on an input element

The solution is to wrap the input in a span and apply display: table-cell to the span and to remove overflow: auto from the input.

The new mark up looks like so:

<div class="field">
    <label for="name">Subdomain</label>
    <span>
        <input type="text" id="name" name="name">
    </span>

    <div class="subdomain-base ">test</div>
</div>

The css now looks like this:

body {
    font-size: 13px;
}
.field {
    width:450px;
    display: table;
}
.field > * {
    display: table-cell;
    border: 1px solid red;
}
span {
    padding: 0 5px;
}
label {
    width: 125px;
}
input {
    width: 100%;
}
.subdomain-base {
    width: 1px;
}
.subdomain-base {
    color: blue;
    font-size: 13px;
}

Jsfiddle: http://jsfiddle.net/ahLMH/6/

Upvotes: 3

ryanlutgen
ryanlutgen

Reputation: 3041

Sadly, don't have enough rep to respond to Dhaval's answer.

Change to

vertical-align: middle;

http://jsfiddle.net/ahLMH/3/

Upvotes: 0

Dhaval Marthak
Dhaval Marthak

Reputation: 17366

Set this:

.row > * {
  display: table-cell;
  border: 1px solid red;
  vertical-align: top; // add this
}

Updated Fiddle

Upvotes: 3

Related Questions