固定列对齐

时间:2015-09-16 13:36:10

标签: html css

我希望第1列(注释1)和第2列(注释2)彼此相邻并浮动到左侧。第3栏(评论3)应浮动到右侧。

jsfiddle

我已经尝试了很多,但无法使其与%。

一起使用

HTML:

<div class="comment_one">
    <div class="reitings">
        <div class="rate pluss"><img class="plus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC"> 83</div>
    </div>
</div>
<div class="comment_two">
    <div class="reitings">
        <div class="rate minuss"><img class="minus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC"> 9</div>
    </div>
</div>
<div class="comment_three">
    <div class="reitings">
        <div class="rate minuss"><img class="minus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC">Report</div>
    </div>
</div>

CSS:

.comment_one {
    width:25%;
    float:left;
}
.comment_two {
    width:25%;
    float:left;
}
.comment_three {
    float:right;
    width:40%;
}
.reitings {
    display:table;
    width:50%;
    border:1px solid #e9e9e9;
    -webkit-border-radius:4px;
    -moz-border-radius:4px;
    border-radius:4px;
}
.rate {
    display:table-cell;
    text-align:center;
    vertical-align:middle;
    line-height:1.5em;
    padding:10%;
}
.rate img {
    vertical-align:middle
}
.pluss {
    background:#f5f5f5;
    color:#4d761a
}
.minuss {
    background:#f5f5f5;
    color:#a8404b;
    border-left:1px solid #e9e9e9;
    text-align:center
}

1 个答案:

答案 0 :(得分:0)

结构 HTML:

<div id="comments">
    <div class="c1 rate-plus"></div>
    <div class="c2 rate-plus"></div>
    <div class="c3 rate-minus"></div>
</div>

使用#comments访问#comments div中的所有div。想想div有什么共同之处。把它写在CSS中。例如:

#comments div {
    background: #f5f5f5;
    border-left: 1px solid #e9e9e9;
    padding: 12px;
    margin: 5px;
    text-align: center;
}

使用浮动c1c2,使用浮动c3

完成 CSS

#comments div {
    background: #f5f5f5;
    border-left: 1px solid #e9e9e9;
    padding: 12px;
    margin: 5px;
    text-align: center;
}

.rate-plus {
    color: #4d761a
}

.rate-minus {
    color: #a8404b;
}

.c1, .c2 {
    width: 25%;
    float: left;
}

.c3 {
    width: 37%;
    float: right;
}

完成 HTML

<div id="comments">
    <div class="c1 rate-plus">
        <img class="plus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC">83
    </div>
    <div class="c2 rate-minus">
        <img class="minus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC">9
    </div>
    <div class="c3 rate-minus">
        <img class="minus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC">Report
    </div>
</div>

我对它进行了一些修改。

Demo