我有這個網站CSS保證金頂部由同級元素沒有父
<div class="ChatDiv">
<div class="chatdiv_ fm">
<span>uhygtfgyhujiuhygt i uytr yui jhuygtfr</span>
</div>
<div class="chatdiv_ fm" style="margin-top:148;">
<span>t</span>
</div>
<div class="chatdiv_ fm" style="margin-top:214;">
<span>t</span>
</div>
</div>
而這個CSS
.ChatDiv{
width: 800px;
height: 480px;
overflow: auto;
margin-left: 350px;
border-radius: 4px;
background: white;
margin-top: 80px;
position: absolute;
box-shadow: 0px 0px 11px black;
}
.fm{
position: relative;
font-family: Nbutler;
font-size: 20px;
float: right;
background: #2196f3;
max-width: 400px;
color: white;
margin-left: -432px;
margin-right: 20px;
padding: 10px;
border-radius: 5px;
span{
display: block;
height: auto;
width: auto;
max-width: 400px;
}
}
而問題是,當我有餘量頂部上fm
元素需要這個利潤率從頂部。不從兄弟元素和我不會有多少fm
元素我會有,所以我不能把所有fm元素相同的margin-top
一個在的jsfiddle/jsbin減少例子就是幫助很多......你有很多不必要的(和格式錯誤)的代碼,這使得它不必要的困難我們幫你... – MattDiMu
我創建了一個簡單的例子,你可以找到有用的:http://codepen.io/karlisup/pen/RRJGBJ – karlisup