我试图对同一类的4个div(彼此相邻)进行样式设置, margin-right为35px以均匀分割它们,除了最后一个div以外,所以它不会为已分配给30px margin添加额外的边距包装的右侧。
现在,我不是编码方面的专家,所以我可能在这里是错误的,但我认为我可以添加margin-right: 0; 内联到最后一个div来覆盖样式表中的属性值35px 。
这会工作吗? 还是有不同的解决方案,我没有看到?
编辑:谢谢大家,最后一个孩子伪选择器工作! :-)
I'm trying to style 4 divs (next to each other) of the same class with a margin-right of 35px to divide them evenly, except for the last div so it doesn't add extra margins to the 30px margin already assigned to the right side of the wrapper.
Now, I'm not an expert at coding yet so I might be wrong here, but I was thinking that I could add margin-right: 0; inline to the last div to override the property value 35px in my stylesheet.
Would this work? Or is there a different solution that I'm not seeing?
Edit: thanks to you all, the last-child pseudo selector worked! :-)
最满意答案
这将覆盖风格和工作。 但是另一种解决方案是使用工作表中的:last-child伪选择器。
欲了解更多关于last-child : http : //www.w3schools.com/cssref/sel_last-child.asp
This would override the style and work. But another solution would be to use the :last-child pseudo selector in the sheet.
For more on last-child: http://www.w3schools.com/cssref/sel_last-child.asp
更多推荐
发布评论