0

JSFiddle

HTML:

<div>
    abc
    <input />
</div>

CSS:

div {
    width:80%;
    background-color:yellow;
}
input {
    width:90%;
}

I would like to know if there is a pure CSS way to modify an input element width, adjusting to the available space left.

Thanks.

2
  • 1
    "links to jsfiddle.org must be accompanied by code" Commented Feb 5, 2014 at 16:13
  • I added code and JSFiddle from the link he partially gave. Commented Feb 5, 2014 at 16:14

1 Answer 1

3

As a pure CSS solution, you could wrap around the <input> by a container <div> and hide the horizontal overflow of the box with overflow-x: hidden;.

Then float the text to the left, using a <label> element:

HTML:

<label>abc</label>
<div class="wrapper">
    <input />
</div>

CSS:

.wrapper { overflow-x: hidden; }
label { float: left; }
input { width:100%; box-sizing: border-box; }

JSFiddle Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.