如何使用Code Igniter更改输入字段的大小/宽度


How to change the size/width of an input field with Code Igniter?

如何使用codeigniter确保我的input field是某个大小?我正在使用'size'属性,但它不起作用。

当前代码:

$dataArray= array(
'name'=> 'test',
'id'=> 'test',
'value'=>'10',
'size'=> '2',
);

echo form_input($dataArray);

然而,输入框仍然占据了屏幕的整个宽度。

您可以设置,如:

$dataArray= array(
'name'=> 'test',
'id'=> 'test',
'value'=>'10',
'size'=> '2',
'class'=>'custom_input'// here i have added a class
);

echo form_input($dataArray);

然后在css文件中使用它,如style.css:

.custom_input{
width:50px;/*use according to your need*/
height:30px;/*use according to your need*/
}

在你的<head>部分添加这一行,如:

<link rel="stylesheet" type="text/css" href="yourpath/style.css">

如果您不想要外部CSS,请使用以下内容:

$dataArray= array(
'name'=> 'test',
'id'=> 'test',
'value'=>'10',
'size'=> '2',
'style'=>'width:50px;height:50px'// here i have added a class
);

echo form_input($dataArray);

size元素可能不一定会根据CSS中的设置更改输入的宽度或高度。

我建议使用"样式"选项手动设置样式:

$dataArray= array(
    'name'=> 'test',
    'id'=> 'test',
    'value'=>'10',
    'style'=> 'width: 100px;',
);

在这里,您可以添加类似的样式属性

$dataArray= array(
'name'=> 'test',
'id'=> 'test',
'value'=>'10',
'size'=> '2',
'style'=>'width:30px;height:300px'// here i have added a class
);

echo form_input($dataArray);

或者你可以在其他文件中完成,并将其链接到你的页面