2010-08-06 43 views
2

http://jsfiddle.net/aam7J/什么让我的输入元素像块元素一样显示?

如何在输入元素上引发div样行为?具体而言,我怎样才能让宽度扩大,使其包含边缘的外部宽度填充容器? width: 100%不起作用,因为它没有考虑到其他箱型号属性。

+0

Folowing情况叙述,这个答案没有完成:( http://stackoverflow.com/questions/13413932/how-can-make-input-element-displayed-same-as-block-element – iegik 2012-11-16 09:43:13

回答

1

我用的是“黑客”,以解决输入边框宽度这样的事情...

<div>hello world</div> 
​ 
<div class="adjustForTheInputBorder"> 
    <input type="text" /> 
</div> 


input 
{ 
    width:100%; 
    border-width:2px; 
} 

div.adjustForTheInputBorder 
{ 
    margin-right: 4px; /* or 2x whatever your input border width is */ 
} 

div 
{ 
    background-color: pink; 
} 

adjustForTheInputBorder类往往有其更恰当地传达我的CSS的仇恨虽然名称... :)

PS div默认呈现为display:block,您不需要那里。