我有包含多个项目的页面。 其宽度为33.33%,填满了页面的整个宽度。 但是,我想在项目之间添加20px的边距,但是在每个连续项目的右侧添加20px的边距,然后放弃整个页面。 ()请删除小提琴上注释掉的CSS,看看我的意思。
其中,问题是如何添加20px保证金,使所有. item div保持相同大小? 可以使用宽度百分比,将. item删除宽度添加为边距,但这是一个百分比,因此不会达到稳定的20px。
HTML
1 2 3 4 5 6 7 8 9 10 11 12 CSS
#main .item {
height: 100px;
width:33.33%;
浮点:左;
文本对齐3360中心;
}
#main.item:nth-child(3n1 ) {
后台: red;
}
#main.item:nth-child(3n3) {
后台: yellow;
}
#main.item:nth-child(3n2 ) {
后台:轻型蓝色;
}
/*.item:nth-child(3n1 )、 item : nth-child (3N2 ) ) ) ) ) ) ) )。
玛姬- right : 20px! 导入;
() /