Style input element to fill remaining width of its container
2016-04-28 07:03
555 查看
div总长一定,button长度会变化,需要input填满剩下的长度。
http://stackoverflow.com/a/11815907/2177408
Here is a simple and clean solution without using JavaScript or table layout hacks. It is similar to this answer: Input
text auto width filling 100% with other elements floating
It is important to wrap the input field with a span which is
Next thing is that the button has to come first and the the input field second.
Then you can float the button to the right and the input field fills the remaining space.
HTML
CSS
A simple fiddle: http://jsfiddle.net/v7YTT/90/
http://stackoverflow.com/a/11815907/2177408
Here is a simple and clean solution without using JavaScript or table layout hacks. It is similar to this answer: Input
text auto width filling 100% with other elements floating
It is important to wrap the input field with a span which is
display:block.
Next thing is that the button has to come first and the the input field second.
Then you can float the button to the right and the input field fills the remaining space.
HTML
<form method="post"> <button>Search</button> <span><input type="text" title="Search" /></span> </form>
CSS
form { width: 500px; overflow: hidden; background-color: yellow; } input { width: 100%; } span { display: block; overflow: hidden; padding-right:10px; } button { float: right; }
A simple fiddle: http://jsfiddle.net/v7YTT/90/
相关文章推荐
- 并查集
- 基于BootStarp的Dailog
- mybaits 插入数据时 如果是日期类型 一定要指明
- replication factor: 1 larger than available brokers: 0 问题解决方案
- UVA 10245 The Closest Pair Problem【分治】
- UVA 10245 The Closest Pair Problem【分治】
- UVA 10245 The Closest Pair Problem【分治】
- 【BZOJ3670】[Noi2014]动物园【KMP】【fail树】
- 219. Contains Duplicate II
- leetcode 217. Contains Duplicate
- hosting company 的 mail , localhost send 不到
- if __name__=='__main()__:
- LightOJ 1038 Race to 1 Again
- leetcode-172. Factorial Trailing Zeroes
- 解读(三):分析MainActivity, 程序的界面主体框架
- 启动apache遇到错误:httpd: Could not reliably determine the server's fully qualified domain name
- 启动apache遇到错误:httpd: Could not reliably determine the server's fully qualified domain name
- 【Realflow】Domain 节点翻译
- 人工智能大拿解答机器学习30个问答
- 【渲染】解决三维出图黑白边缘溢出问题:直通(STRAIGHT)与预乘(PREMULT)ALPHA剖析