首页 新闻 赞助 找找看

css中text宽度问题

0
悬赏园豆:20 [已解决问题] 解决于 2009-12-14 15:50

我现在想实现这样一个功能,

第一个text是90px,第二个text是200px.

页面上还有其他很多<input type='text'>元素,不方便每个text上都用id或者class来定义.

但是页面上大部分都是90px的,只大约4个text是要定义200px的.

我用了下面的定义,可是不成功,两个text宽度是一致的为什么是这样?有什么解决办法?

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
input[type='text']
{
border
: solid 1px silver;
background-color
:#e6f0f9;
width
:90px;
}

.longtxt
{
width
:200px;
}

</style>
</head>
<body>
<input type="text" /><br />
<input type="text" class="longtxt" />
</body>
</html>

 

请各位伸手帮助,我css很不熟悉.

Pwd的主页 Pwd | 初学一级 | 园豆:158
提问于:2009-12-11 09:05
< >
分享
最佳答案
1

两个样式因为都是作用域text文本框的,你这样加可能会有冲突,如果你是想给所有文本框先加一种样式,再在此基础上给个别文本框加样式的话,建议你的 .longtxt这个样式直接写在标签里而不要写在头里边了,会有一个优先级问题,你试试吧

收获园豆:10
死神的背影 | 小虾三级 |园豆:667 | 2009-12-11 09:16
这样是可以的,但是不想这样写,想把样式写在一个css文件里
Pwd | 园豆:158 (初学一级) | 2009-12-11 14:19
在CSS文件中的.longtxt前添加一个input标签即可 因为属性选择器"[type='text']"和类选择器".longtxt"优先级一样,当属性选择器加上一个标签在前面后,优先级就超过了类选择器。 (CSS优先级参见此文http://yiminghe.javaeye.com/blog/254094)
Destiny1986 | 园豆:170 (初学一级) | 2010-06-19 00:59
其他回答(4)
0

特殊的兩個單據寫CSS

 <input type="text"  STYLE='WIDTH:90PX;'/><br />
   
<input type="text"  STYLE='WIDTH:200PX;'/>

 

 其他就用樣式

  <input type="text"  class='longtext' />

woody.wu | 园豆:3621 (老鸟四级) | 2009-12-11 09:16
... 不是要这样的效果- -.
支持(0) 反对(0) Pwd | 园豆:158 (初学一级) | 2009-12-11 14:21
0

改一下试试:

input[type='text']  .longtxt {width:200px;}

Biny | 园豆:205 (菜鸟二级) | 2009-12-11 09:20
这样是不可以的..
支持(0) 反对(0) Pwd | 园豆:158 (初学一级) | 2009-12-11 14:20
0

是一个优先级的问题:

这样改:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
input[type='text']
{
border
: solid 1px silver;
background-color
:#e6f0f9;
width
:90px;
}

#longtxt
{
width
:200px;
}

</style>
</head>
<body>
<input type="text" /><br />
<input type="text" id="longtxt" />
</body>
</html>
收获园豆:10
铁拐李 | 园豆:195 (初学一级) | 2009-12-13 22:51
确实可以,不过,我还有其他的text也是需要很200px的才可以,不能写成下面这个样子吧. #longtxt1,#longtxt2 { ... }
支持(0) 反对(0) Pwd | 园豆:158 (初学一级) | 2009-12-14 15:49
0

这个有好多方法可以解决的

方法:

(1)定义两个样式 .txt1 { width:90px; border: solid 1px silver; background-color:#e6f0f9;

   .txt2 { width:90px; border: solid 1px silver; background-color:#e6f0f9; }

 <input type="text" class=“txt1” /><br />
<input type="text" class="txt2" />

(2) .txt { border: solid 1px silver; background-color:#e6f0f9; }

.w-90{ width:90px; } .w-200 { width: 200px; }

<input type="text" class=“txt w-90” /><br />
<input type="text" class="txt w-200" />


limanclear | 园豆:262 (菜鸟二级) | 2011-06-22 13:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册