2

we must display an input-field and a button with an inner span on the same line. Button resp. its inner span must have width:auto, the input text must fill the remaining width.

Fiddle: http://jsfiddle.net/1xfxpm55/

HTML:

<div class="wrapper">
    <input type="text">
    <button> <span>Auswählen</span>

    </button>
</div>

CSS:

.wrapper {
    width:100%;
    display: table;
}
input {
    display: table-cell;
    width: 100%;
    float: left;
}
button {
    display: table-cell;
    width: auto;
}

Thanks for any hints

Jamie Barker
  • 8,145
  • 3
  • 29
  • 64
Raphael Jeger
  • 5,024
  • 13
  • 48
  • 79

2 Answers2

2

Put the button in a div with a small width:

* {
    box-sizing:border-box;
}
*:before, 
*:after {
    box-sizing:border-box;
}
.c1 {
    display: table-cell;
    padding-right:10px;
}
input{
    width:100%;
}
.c2 {
    display: table-cell;
    padding-left:10px;
    width:1%
}
<div class="wrapper">
    <div class="c1">
        <input type="text">
    </div>
    <div class="c2">
        <button><span>Auswählen</span></button>
    </div>
</div>
PoseLab
  • 1,841
  • 1
  • 16
  • 22
  • already near on our code, thank you! The c2 has too much height at the moment though... will be able to resolve that :) – Raphael Jeger Jun 04 '15 at 11:19
0

Are you allowed to use javascript? If I get the question right, the input text field has to fill the entire line - the width of the input button, correct? Here is a sugestion:

function getRemainingWidth(button, elm) {
    elm.style.width = "calc( 100vw - " + realWidth(button) + "px)";
    alert(elm.style.width);
}

function realWidth(elm) {
    var width = elm.offsetWidth + 
        parseInt(window.getComputedStyle(elm, null).getPropertyValue('padding-left'), 10) +
        parseInt(window.getComputedStyle(elm, null).getPropertyValue('padding-right'), 10) + 
        parseInt(window.getComputedStyle(elm, null).getPropertyValue('margin-left'), 10) + 
        parseInt(window.getComputedStyle(elm, null).getPropertyValue('margin-right'), 10);

    return width + 10;
}

window.onload = getRemainingWidth(document.getElementById('btn'), document.getElementById('textfield'));

Made a working jsfiddle here http://jsfiddle.net/1xfxpm55/4/ (its an update of your provided demo).

RaKXeR
  • 152
  • 2
  • 16