php - 如何使输入宽度适应表格列宽

标签 php html css

我有一个 php forloop,它从数据库生成一个表。 第二行有用于搜索的文本输入。 我的问题是,如何使输入宽度适应列?

我在 jsfiddle 中做了一个例子。 第一张表是我从输入中得到的。 第二个是我希望输入的样子。

说清楚。表 1 应与表 2 类似。

JSfiddle

<table border="1">
<tr>
    <td>Column 1</td><td>Second Column</td><td>3rd Column</td>
</tr>
<tr>
    <td><input type="text" /></td><td><input type="text" /></td><td><input type="text" /></td>
</tr>
<tr>
    <td>Some database content</td><td>more db content</td><td>more content</td>
</tr>
</table>

<br>
<br>

<table border="1">
<tr>
    <td>Column 1</td><td>Second Column</td><td>3rd Column</td>
</tr>
<tr>
    <td>1</td><td>2</td><td>3</td>
</tr>
    <tr>
    <td>Some database content</td><td>more db content</td><td>more content</td>
</tr>
</table>

最佳答案

将以下样式添加到您的 CSS 中的输入:

width:  100%;
margin: 0;
border:  0px none;

Working fiddle

编辑

以上在 Chrome 中不起作用。结合@Johan Perez 的回答可以解决我认为的问题。

CSS:

td input {
    width:  100%;
    margin: 0;
    border:  0px none;
    box-sizing:border-box; 
    -webkit-box-sizing:border-box; 
    -moz-box-sizing: border-box;
}

New working fiddle (在 FF、Chrome、IE11 中测试)

编辑 2 这是 Chrome 中第二 fiddle 的屏幕截图:

chrome screenshot

你能发布你的问题吗?

关于php - 如何使输入宽度适应表格列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23173015/

相关文章:

php - 从数据库加载当前用户

php - 为什么我的注册表单仍然无法将数据输入到我的 MySQL 表中

javascript - 使用chart.js 实现多个动态折线图 | js和html

css - CSS3 中的顶部边框图像

html - 子元素的宽度过渡不适用于父元素

php - 如何在 PHP 中获取特定时间的下一个日期

php - 使用 PHP 创建 Zip 文件?

html - CSS-连字符在 chrome 和 firefox 中不起作用

javascript - jQuery根据节的索引滚动到节

悬停时的 HTML/CSS 菜单和激活的菜单不会显示