怎样写CSS设置多行文本框的显示行数?

html-css016

怎样写CSS设置多行文本框的显示行数?,第1张

楼主你好!一般textarea 5行写法就是上面写的那个默认状态下:<textarea cols=5></textarea>

但楼主说要用css实现,其实也可以,方法代码如下:

<style type="text/css">

.areaclass{width:200pxheight:75pxline-height:15px}

</style>

<textarea class="areaclass">

内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容

</textarea>

如果内容超过了五行的话,就会显示下拉滚动条!

用css设置textarea代码如下:

<textarea style="width:200pxheight:100pxborder:solid 1px #f00border-radius:20pxresize:none"></textarea>

border-radius:20px;

resize:none

1.overflow内容溢出时的设置(设定被设定对象是否显示滚动条)

overflow-x水平方向内容溢出时的设置

overflow-y垂直方向内容溢出时的设置

以上三个属性设置的值为visible(默认值)、scroll、hidden、auto。

2.scrollbar-3d-light-color立体滚动条亮边的颜色(设置滚动条的颜色)

scrollbar-arrow-color上下按钮上三角箭头的颜色

scrollbar-base-color滚动条的基本颜色

scrollbar-dark-shadow-color立体滚动条强阴影的颜色

scrollbar-face-color立体滚动条凸出部分的颜色

scrollbar-highlight-color滚动条空白部分的颜色

scrollbar-shadow-color立体滚动条阴影的颜色

我们通过几个实例来讲解上述的样式属性:

1.让浏览器窗口永远都不出现滚动条

没有水平滚动条

<body style= "overflow-x:hidden ">

没有垂直滚动条

<body style= "overflow-y:hidden ">

没有滚动条

<body style= "overflow-x:hiddenoverflow-y:hidden ">或 <body

style= "overflow:hidden ">

2.设定多行文本框的滚动条

没有水平滚动条

<textarea style= "overflow-x:hidden "></textarea>

没有垂直滚动条

<textarea style= "overflow-y:hidden "></textarea>

没有滚动条

<textarea style= "overflow-x:hiddenoverflow-y:hidden "></textarea>

或 <textarea style= "overflow:hidden "></textarea>

3.设定窗口滚动条的颜色

设置窗口滚动条的颜色为红色 <body style= "scrollbar-base-color:red ">

scrollbar-base-color设定的是基本色,一般情况下只需要设置这一个属性就可以达到改变滚动条颜色的目的。

加上一点特别的效果:

<body style= "scrollbar-arrow-color:yellowscrollbar-base-color:lightsalmon ">

4.在样式表文件中定义好一个类,调用样式表。

<style>

.coolscrollbar{scrollbar-arrow-color:yellowscrollbar-base-color:lightsalmon}

</style>

这样调用:

<textarea class= "coolscrollbar "></textarea>

直接使用css的标签选择器就可以实现

td input[type='text'] {.../*设置需要的样式*/}

举个例子:

创建Html元素

<table>

<tr>

<td>name</td>

<td><input type="text"></td>

<td>sex</td>

<td><input type="radio" name="sex" checked>男<input type="radio" name="sex">女</td>

</tr>

<tr>

<td>tel.</td>

<td><input type="text"></td>

<td>addr.</td>

<td><input type="text"></td>

</tr>

</table

设置css样式

table{border-collapse: collapse}

td{border:1px solid #cccpadding:5px}

/*设置单元格中文本框的样式*/

td input[type='text']{border:1px solid greenborder-radius:3pxheight:30px}

观察显示效果