简易CSS3仿照微信对话框
惯例,直接上代码
HTML代码:
<div class="say-box say-left"> <div class="say-avatar"> <img src="头像" /> </div> <div class="say-body"> <div class="say-userinfo"> <span class="say-time">2016-12-33</span> 头像在左 </div> <div class="say-content"> <div class="say-arrow"></div> <div class="say-message">这就是我说的内容啦</div> </div> </div> </div> <div class="say-box say-right"> <div class="say-avatar"> <img src="头像" /> </div> <div class="say-body"> <div class="say-userinfo"> <span class="say-time">2016-12-33</span> 头像在右 </div> <div class="say-content"> <div class="say-arrow"></div> <div class="say-message">这就是我说的内容啦</div> </div> </div> </div>
CSS代码:
/*对话框*/ .say-box { padding: 10px 20px; } .say-box .say-avatar { display: block; width: 60px; height: 60px; } .say-box .say-avatar img { width: 60px; height: 60px; border-radius: 3px; } .say-box .say-body .say-userinfo { color: #555; } .say-box .say-body .say-userinfo .say-time { color: #777; } .say-box .say-body .say-content { position: relative; width: 100%; height: auto; border-radius: 5px; } .say-box .say-body .say-content .say-message { padding: 10px; } .say-box .say-body .say-content .say-arrow { position: absolute; top: 5px; width: 0; height: 0; font-size: 0; border: solid 8px; } /*左侧样式,颜色*/ .say-box.say-left .say-avatar { float: left; } .say-box.say-left .say-body { margin-left: 80px; } .say-box.say-left .say-body .say-userinfo { text-align: left; } .say-box.say-left .say-body .say-userinfo .say-time { float: right; } .say-box.say-left .say-body .say-content { background: #f8f8f8; } .say-box.say-left .say-body .say-arrow { left: -16px; border-color: rgba(0, 0, 0, 0) #f8f8f8 rgba(0, 0, 0, 0) rgba(0, 0, 0, 0); } /*右侧样式颜色*/ .say-box.say-right .say-avatar { float: right; } .say-box.say-right .say-body { margin-right: 80px; } .say-box.say-right .say-body .say-userinfo { text-align: right; } .say-box.say-right .say-body .say-userinfo .say-time { float: left; } .say-box.say-right .say-body .say-content { background: #1AAD19; color: #fff; } .say-box.say-right .say-body .say-arrow { right: -16px; border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #1AAD19; }