简体   繁体   English

使项目适合容器的宽度

[英]fit items to container's width

I have 10 items in a container and each of them has margin from right hand side. 我在一个容器中有10个项目,每个项目都有右边距。 With jquery, I am removing margin for every fifth item, but as the container's width is in percentage and item's width is in percentage as well, when I minimize or maximize my screen, items don't stretch to the end of container. 使用jquery时,我要删除每五个项目的边距,但是由于容器的宽度是百分比,项目的宽度也是百分比,所以当我最小化或最大化屏幕时,项目不会延伸到容器的末端。 How can I do it? 我该怎么做?

Here is the Fiddle

Just give a percentage to the right margin. 只需给正确的边距一个百分比即可。

The divs total width is 16% x 5 = 80% of the total width. div的总宽度为总宽度的16%x 5 = 80%。 So, the remaining width is 20%. 因此,剩余宽度为20%。 Divide that by 5 (total div margins) and set to 4%: 将其除以5(总div边距)并设置为4%:

margin-right:4%;

Check the DEMO 检查演示

And also, you don't need jquery here to apply margin-right: 0 to the fifth element. 而且,您无需在此处使用jquery即可将margin-right: 0应用于第五个元素。 You can use css as shown below: 您可以如下所示使用css:

li:nth-child(5n){
    margin-right: 0px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM