2011-11-11 55 views
0

有没有一种方法(CSS),以确保文本框和搜索按钮的大小不同时div?可变宽度div的可变宽度形式?

这是我的搜索栏的样子:

<div class="userinfo"> 
    <form><table id="search" border="0"><tr> 
      <td valign="top"><input type="text" name="search"></td> 
      <td valign="top"><input type="image" name="search-button" src="img/search.png"></td> 
    </tr></table></form> 
</div> 

而且userinfo

.userinfo { 
    width: 60%; 
    margin-left: auto; 
    margin-right: auto; 
    margin-bottom: 5px; 
} 

.userinfo input[type=text] { 
    width: 70% 
} 

userinfo谎言在页面中间用60%的宽度,但是,我想将userinfo内的文本框设置为相对于userinfo具有一定的宽度。以上不起作用。想法?

回答

1

听起来你应该为搜索输入指定一个百分比宽度。

将搜索按钮保持在固定宽度(尽管不是必需的)也是一个好主意。

编辑:下面是一个例子:

<div class="widget"> 
    <input type="text" name="query"> 
    <input type="submit" name="search" value="Search"> 
</div> 

<style> 
    .widget { width: 30% } 
    .widget input[type=text] { width: 70% } 
</style> 
+0

我该怎么做了'.class'?表单或输入元素? – n0pe

+0

我编辑了我的回复以包含示例。请注意,这使用IE6不支持的CSS属性选择器(如果你关心的话)。 – simshaun

+0

我编辑了我的问题来添加一些代码片段。我似乎缺少一些东西 – n0pe