2012-07-08 61 views
0

如何防止最后一个div(类)不在?我把margin-right放在.artist_wrap上。我想当我把overflow: hidden它会留在#music_videos_wrap,但它消失。感谢任何会帮助我的人。div class last div goes html html css

HTML:

<div id="music_videos_wrap"> 
    <div class="artist_wrap"></div> 
    <div class="artist_wrap"></div> 
    <div class="artist_wrap"></div> 
    <div class="artist_wrap"></div> 
</div> 

CSS:

#music_videos_wrap{ 
    float:left; 
    margin:0 0 0 23px; 
    width:944px; 
    height: 257px; 
    background-color: red; 
    /*overflow:hidden;*/ 
} 
.artist_wrap{ 
    float:left; 
    width:190px; 
    height:257px; 
    background-color: green; 
    margin:0 62px 0 0; 
} 
+6

[你能指出什么是错在这的jsfiddle ?](http://jsfiddle.net/hBF2x/)。我目前没有看到任何“发生”效应。 – Ohgodwhy 2012-07-08 15:35:36

+0

它应该是4.artist_wrap对不起 – Aldin 2012-07-08 15:46:57

+0

是否有可能“unmargin-right”最后一个.artist_wrap? – Aldin 2012-07-08 15:50:34

回答

2

首先,你的测量结果有些不对,你需要包装宽度为946px以适合你想要的元素,或者改变.artist_wrap的宽度。修复之后,您可以将margin-left:62px设置为.artist-wrapp而不是右边距。在第一胎0(这是不是最后的孩子更多的跨浏览器):这种方法你可以使用保证金左

.artist_wrap:first-child { margin-left:0; } 

见的jsfiddle:http://jsfiddle.net/Rkp3Z/

+0

YAYYY谢谢youuuuu:第一个孩子isssss awesomee非常感谢你,我爱你的男人!酷伪东西 – Aldin 2012-07-08 16:03:33

+0

很高兴它的工作:) – 2012-07-08 16:08:57

1

您.artist_wrap宽度太大

,你应该使用Firebug,并调整它看到什么是最大值可以适应父母的宽度

here you go with 150px as width

或从父母计算它的宽度减去保证金,边框和贴

944px parents width/4 divs = 236 width per artist child 

,如果你把右页边距每个.artist_wrap你需要从宽度减去该余量,使之适合在父944 PX宽度

这意味着236 - 62 = 174px作为宽度artist_wrap

you can also apply margin:0 31px for artist_wrap to have a symmetric layout

+0

我需要那些4 .artist_wrap以适应它应该适合,因为im从psd切片它,我只是想最后.artist_wrap是“unmargin-right”,以便它不会去... – Aldin 2012-07-08 15:57:46

+0

它不会适合您的初始css,看我更新的回答 – 2012-07-08 16:16:28