css - 将最后一个单元格设置为右对齐

标签 css

我正在将我的 div 显示设置为这样的表格单元格。

HTML

<div id="parent">
    <div class="child">1</div>
    <div class="child">2</div>
    <div class="child">3</div>
    <div class="lastchild">4</div>
</div>

CSS

.child{
    background: red;
    width: 20px;
    display: table-cell;
}

.lastchild {
    background: blue;
    width: 20px;
    display: table-cell;
    margin-right: 0;            
}

.parent {
    width:200px;
}

http://jsfiddle.net/Lx1p3y93/

我想知道是否有任何方法可以将最右边的单元格设置为右对齐?

最佳答案

将 CSS 更改为:

.lastchild {
   background: blue;
   width: 20px;
   display: table-cell;
   margin-right: 0;   
   float:right;
}

.child {
    background: none repeat scroll 0 0 red;
    display: table-cell;
    float: left;
    width: 20px;
}

关于css - 将最后一个单元格设置为右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26603405/

相关文章:

用于 RangeSlider 的 JavaFX ControlsFX CSS

HTML/CSS - 改变滚动条?

javascript - 在页面调整大小时记录隐藏元素的高度

Android 应用程序使用 css 实现页面的通用 View

html - 在所有页面上打印页眉/页脚(打印模式)

html - 显示 :inline-block not line oriented 的布局

php - 了解 woocommerce 主题 - 使用我自己的主题

html - 悬停子菜单没有完全对准我光标指向的菜单

javascript - 在同一个 div 上多次单击时恢复更改

javascript - 是否可以在移动设备旋转时使用 Javascript/CSS 交换样式表?