Display: table-cell problems in chrome

后端 未结 3 1573
时光取名叫无心
时光取名叫无心 2021-01-14 00:24

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

相关标签:
3条回答
  • 2021-01-14 00:37

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

    Change to

    vertical-align: middle;
    

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

    0 讨论(0)
  • 2021-01-14 00:51

    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/

    0 讨论(0)
  • 2021-01-14 01:00

    Set this:

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

    Updated Fiddle

    0 讨论(0)
提交回复
热议问题