css - 2列带有<div>,第一列动态宽度

标签 css

我尝试使用“ div”元素转换以下内容:

<table><tbody>
<tr>
<td class="username">matthew</td>
<td class="text">hello world!</td>
</tr>
<tr>
<td class="username">this is a longer username</td>
<td class="text">hey!</td>
</tr>
</tboby></table>
.username{text-align:right;}
.text{padding-left:20px;}


http://jsfiddle.net/wqEq3/1/

仅当第一列为固定宽度时,才可以使用“ div”重现它,就像上面带有“ table”的示例一样,我希望它是动态的。

<div id="container">
    <div class="message">
        <div class="username">matthew</div>
        <div class="text">hello world!</div>
    </div>
    <div class="message">
        <div class="username">this is a longer username</div>
        <div class="text">hey!</div>
    </div>
</div>
​.message {overflow:hidden;}
.username {
    text-align:right;
    /*width:200px; How to get rid of the fixed width?*/
    float:left;
}
.text {
    padding-left:20px;
    float:left;
}


http://jsfiddle.net/cGsyK/2/

最佳答案

如果要保存标记,我认为只能使用display: table*选项来实现,而IE7和更早版本不支持。

演示:http://jsfiddle.net/EgUn4/

关于css - 2列带有<div>,第一列动态宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9515675/

相关文章:

html - 将默认值设置为 html 中的空白表单。(Ruby、Sinatra、CSS)

html - 如何在响应式设计中禁用缩放功能?

html - 我的 anchor 不工作

html - 引导模态未显示在 Action 上

css - Rails 应用程序中的主题

javascript - 带有销毁自动完成的中心表单( Bootstrap token 字段)

css - IE8或IE9中未显示控制栏

php - 难题 - 如何从 PHP 中提取图像的 'colorify' 部分?

css - 在 CSS 中使用图像 url 时,React 应用程序编译失败

css - 智能手机上的 HTML 菜单行为