floated div pushed down
我正在尝试将墙拆分为两列:
如你所见,
这是代码:
1 2 3 4 5 6 7 8 9 10 11 | /* this is DIV NUMBER 1 */ <img src="/images/male_profile.png" class="postImg"> <h4>roberto mancino</h4> <h5>tryewklekwleklweklwkelkweklweklweklwkelwkelkwelkwlekwlekwlekwelkwelkwelwkelkwelkwelkwlekwleklweklwkelweklwkelwkelwkelwkelweklwkewleklwkelwkelwekwe</h5><h6>today - <span>about 10 minutes ago</span></h6>cancel /* this is DIV NUMBER 2 */ <img src="/images/male_profile.png" class="posting"> <h4>roberto mancino </h4><h5>try</h5><h6>today - <span>about 10 minutes ago</span></h6>cancel /* this is DIV NUMBER 3 */ <img src="/images/male_profile.png" class="posting"> <h4>roberto mancino </h4><h5>try</h5><h6>today - <span>about 10 minutes ago</span></h6>cancel /* this is DIV NUMBER 4 */ <img src="/images/male_profile.png" class="posting"> <h4>roberto mancino </h4><h5>try</h5><h6>today - <span>about 10 minutes ago</span></h6>cancel |
CSS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | .wall{ margin-top: 20px; width: 100%; height: 100%; } .post{ clear: left; background-color: lime; display: block; z-index: 2; position: relative; padding:20px 20px 20px 20px; width: 42%; margin: 20px 10px 0px 10px; background-color: #edeff4; float: left; border: 1px solid rgb(216,216,216); box-shadow: 0px 0px 15px rgba(0,0,0,0.1); -moz-box-shadow: 0px 0px 15px rgba(0,0,0,0.1); -webkit-box-shadow: 0px 0px 15px rgba(0,0,0,0.1); } .post:nth-child(2n) { float: right; clear: right; } .formatted-text{ margin-left:80px; word-wrap: break-word; /* or"normal" */ overflow-wrap: break-word; } |
如果可以更改HTML,可以使用
1 2 3 4 5 6 | ul { /*styles*/ -moz-column-count: 2; -webkit-column-count: 2; column-count: 2; } |
演示小提琴1
我在下面的评论中做了一个复制样式的小提琴。检查它:
演示小提琴2/全屏观看我在底部发布的jfiddle中所做的是添加两个div容器,一个rightfloat和一个leftfloat,每个容器包含两个罗伯托大厦div(它们可以包含任何数字),然后添加第三个整体容器,其中两个容器具有自动页边距,以使其居中。CSS如下(请注意,我删除了第n个子CSS样式):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | .wall { margin-top: 20px; width: 100%; height: 100%; } .post { background-color: lime; z-index: 2; padding:20px 20px 20px 20px; margin: 20px 10px 0px 10px; background-color: #edeff4; border: 1px solid rgb(216, 216, 216); box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.1); -moz-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.1); -webkit-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.1); } .leftFloat { float: left; clear: left; width: 50%; display: block; position: relative; } .rightFloat { float: right; clear: right; width: 50%; display: block; position: relative; } .container { margin-left:auto; margin-right:auto; width: 100%; } .formatted-text { margin-left:80px; word-wrap: break-word; /* or"normal" */ overflow-wrap: break-word; } |
HTML:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <img src="/images/male_profile.png" class="postImg"> <h4>roberto mansion</h4> <h5>tryewklekwleklweklwkelkweklweklweklwkelwkelkwelkwlekwlekwlekwelkwelkwelwkelkwelkwelkwlekwleklweklwkelweklwkelwkelwkelwkelweklwkewleklwkelwkelwekwe</h5> <h6>today - <span>about 10 minutes ago</span></h6>cancel <img src="/images/male_profile.png" class="posting"> <h4>roberto mansion</h4> <h5>try</h5> <h6>today - <span>about 10 minutes ago</span></h6>cancel <img src="/images/male_profile.png" class="posting"> <h4>roberto mansion</h4> <h5>try</h5> <h6>today - <span>about 10 minutes ago</span></h6>cancel <img src="/images/male_profile.png" class="posting"> <h4>roberto mansion</h4> <h5>try</h5> <h6>today - <span>about 10 minutes ago</span></h6>cancel |
jspiddle:http://jsfiddle.net/tslz6/5/