对齐问题与垂直对齐

时间:2014-08-29 11:28:39

标签: html css html5

我使用下面引用的HTML和CSS来创建气泡类型div。其heightwidth应根据内容进行调整。

除了我希望以垂直顺序看到所有div s之外,每件事情都很完美,我在这里缺少什么?

使用JSFiddle的答案将不胜感激。

HTML:

<div class="chat">
<div class="bubble me">Hello there!</div>

<div class="bubble me">Awesome.</div>
</div>
<div class="bubble me">Awesome.</div>
</div>
<div class="bubble me">Awesome. Awesome. Awesome. Awesome. Awesome.</div>
</div>
<div class="bubble me">Awesome.</div>
</div>

CSS:

.chat {
    width: 400px;
}

.bubble{
    background-color: #F2F2F2;
    border-radius: 5px;
    box-shadow: 0 0 6px #B2B2B2;
    display: inline-block;
    padding: 10px 18px;
    position: relative;
    vertical-align: top;
}

.bubble::before {
    background-color: #F2F2F2;
    content: "\00a0";
    display: block;
    height: 16px;
    position: absolute;
    top: 11px;
    transform:             rotate( 29deg ) skew( -35deg );
        -moz-transform:    rotate( 29deg ) skew( -35deg );
        -ms-transform:     rotate( 29deg ) skew( -35deg );
        -o-transform:      rotate( 29deg ) skew( -35deg );
        -webkit-transform: rotate( 29deg ) skew( -35deg );
    width:  20px;
}

.me {
    float: left;   
    margin: 5px 45px 5px 20px;         
}

.me::before {
    box-shadow: -2px 2px 2px 0 rgba( 178, 178, 178, .4 );
    left: -9px;           
}

JSFiddle example here

2 个答案:

答案 0 :(得分:4)

您可以在此课程中添加clear:left

.me {
    float: left;   
    margin: 5px 45px 5px 20px;   
    clear: left;/*Add clear left*/
}

fiddle

另请查看Controlling flow next to floats: the 'clear' property

答案 1 :(得分:1)

clear: both添加到冒泡... 更新小提琴:http://jsfiddle.net/mek5Z/1782/