Does any have an idea how to do so? I created this fiddle http://jsfiddle.net/matusko/2pctr9ok/3/ and all I want to do is, that the input behave the same way as the upper divs.
CSS:
.left {
float:left;
width:180px;
background-color:#ff0000;
}
.right {
width: 100%;
background-color:#00FF00;
display: block;
}
HTML:
<div>
<div class="left">
left
</div>
<div class="right">
right
</div>
</div>
<br/>
<div>
<div class="left">
left
</div>
<input type="text" placeholder="right" class="right"/>
</div>
I dont understand why input doesnt behave like div, even when propriety inspector says that its display is block.
The width property is used to fill a div remaining horizontal space using CSS. By setting the width to 100% it takes the whole width available of its parent.
To add space inside a form's text field, use the CSS padding property.
The height attribute specifies the height of the <input> element. Note: The height attribute is used only with <input type="image"> . Tip: Always specify both the height and width attributes for images. If height and width are set, the space required for the image is reserved when the page is loaded.
You can use calc in CSS to dynamically calculate the width for you.
Sample below:
.left {
float: left;
width: 180px;
background-color: #ff0000;
}
.right {
width: calc(100% - 180px);
background-color: #00FF00;
display: inline-block;
}
input[type="text"] {
box-sizing: border-box;
width: 100%;
}
<div>
<div class="left">left</div>
<div class="right">right</div>
</div>
<br/>
<div>
<div class="left">left</div>
<div class="right">
<input type="text" placeholder="right" />
</div>
</div>
For < IE9 I would suggest the following http://jsfiddle.net/2pctr9ok/4/
Putting the left bottom in position:absolute
, the whole bottom block in overflow:hidden
and apply a padding-left:180px
on the input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With