table-cell布局

参考:https://blog.csdn.net/messagebox_/article/details/82380913
html:





    
    dddd
    



    

css

body {
    padding: 0px;
    margin: 0px;
}

div {
    height: 98px;
    background-color: gray;
    display: table;
    vertical-align: middle;
    text-align: center;
    width: 950px;
}

div div {
    display: table-cell;
}

.div2 {
    background-color: bisque;
}

.div3 {
    background-color: aqua;
}

.icon {
    width: 48px;
    height: 48px;
    border-radius: 30px;
    margin: 0 auto;
}

.icon3 {
    width: 48px;
    height: 48px;
    border-radius: 30px;
    margin: 0 auto;
}

#name {
    position: relative;
    background-color: blue;
    margin-left: 20px;
    max-width: 80px;
    word-break: break-all;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
}

div button {
    background-color: white;
    color: rgb(117, 189, 143);
    border: 1px solid rgb(117, 189, 143);
    border-radius: 10px;
    height: 25px;
    padding: 3px 12px;
}

显示效果:

table-cell布局_第1张图片

均分了宽度.

如果我们给最后一个图片添加float:right,如果把float添加在div3上面,

.div3 {
    background-color: aqua;
    float: right;
}

显示效果:

table-cell布局_第2张图片

如果把浮动改到icon3上面:


.icon3 {
    width: 48px;
    height: 48px;
    border-radius: 30px;
    margin: 0 auto;
    float: right;
}

显示效果:

table-cell布局_第3张图片

修改text-align也可以达到这个效果

.div3 {
    background-color: aqua;
    text-align: right;
}

 

你可能感兴趣的:(html,css)