CSS:如何设置窗体控件的宽度,使它们都具有相同的宽度? [英] CSS: how to set the width of form control so they all have the same width?
本文介绍了CSS:如何设置窗体控件的宽度,使它们都具有相同的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请考虑以下示例:
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Strict / / EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
< html xmlns =http://www.w3.org/1999/xhtmlxml:lang =enlang =en>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< style type =text / css>
div {width:15em}
输入,textarea,select {width:100%;
-moz-box-sizing:border-box; -webkit-box-sizing:border-box; box-sizing:border-box}
< / style>
< / head>
< body>
< form>
< div>
< input value =Input>
< / div>
< div>
< textarea>文本区域< / textarea>
< / div>
< div>
< select>
< option>一个< / option>
< option>两个< / option>
< option>三个< / option>
< / select>
< / div>
< / form>
< / body>
< / html>
在支持边框的浏览器
框大小,这是按我想要的呈现:
如何获得相同的渲染
解决方案
这是CSS不可能的。我做了一些研究,我发现同一个问题在这里。解决方案是使用此 boxsizing.htc 文件,并添加以下内容到您的HTML标头:
<! - [if lt IE 8]>< style& {behavior:url(boxsizing.htc); }< / style><![endif] - >
Consider the following example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
div { width: 15em }
input, textarea, select { width: 100%;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box }
</style>
</head>
<body>
<form>
<div>
<input value="Input">
</div>
<div>
<textarea>Text area</textarea>
</div>
<div>
<select>
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
</div>
</form>
</body>
</html>
On browser that support the border-box
box sizing, this is rendered as I want:
On IE 6/7, however, this is rendered as:
How can I get the same rendering in IE 6/7 that I get in other browsers, without resorting to setting sizes in pixels?
解决方案
This is not possible with CSS. I did some research and I found out that the same question was asked before here. The solution is to use this boxsizing.htc file and add the following line to your HTML head:
<!--[if lt IE 8]><style>input, textarea { behavior: url("boxsizing.htc"); }</style><![endif]-->
这篇关于CSS:如何设置窗体控件的宽度,使它们都具有相同的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文