【问题标题】:Use css nth-child infinitely无限使用 css nth-child
【发布时间】:2013-10-10 06:38:51
【问题描述】:

我需要把margin-right:0px每3个div。

其实我用的是这段代码,但是因为 wordpress 太疯狂了,所以在 index.php 和 archive.php 中不能正常工作:

.post {position:relative !important;float:left !important;width:207px !important;margin-right:24px;}
.post:nth-child(4n+0) {margin-right:0px !important;}

但只在前第三个 div 中这样做,而不是在 6、9、12.... 为什么?

<div class="post"></div> */ margin-right:24px;
<div class="post"></div> */ margin-right:24px;
<div class="post"></div> */ margin-right:0px;
<div class="post"></div> */ margin-right:24px;
<div class="post"></div> */ margin-right:24px;
<div class="post"></div> */ margin-right:0px;
<div class="post"></div> */ margin-right:24px;
<div class="post"></div> */ margin-right:24px;
<div class="post"></div> */ margin-right:0px;

我有 9 个逐页发帖,是否可以放入 css 指定的 div:first div.second .... 使用不同的 css?

我不能使用 nth-child,因为在我的 wordpress 中不能正常工作

【问题讨论】:

    标签: css wordpress css-selectors


    【解决方案1】:

    使用:nth-child(3n) 定位第 3 / 6 / 9 等。

    它按预期工作..也许由于布局而你没有看到它..

    演示地址 http://jsfiddle.net/tY2Dh/


    更新(更新问题后

    您的 CSS 规则以分配了 category-pro 类的元素为目标。

    但是您的 html 元素分配了一个 post 类。

    您需要将category-pro 类添加到这些元素,或者将您的规则更改为

    .post{..}
    .post:nth-child(3n){...}
    

    【讨论】:

    • 不要在我的 wordpress 中工作,我不知道为什么。我有 9 个逐页帖子,可以放入 css 指定的 div:first div.second .... 使用不同的 css?
    • @vektor,你能发个链接吗?
    • @vektor,:nth-child() 也无法在 IE8 上运行(如果您在那里看到问题..
    • 我在本地工作:(这是我第一次在本地使用 XAMPP。一秒钟并编辑问题
    • @vektor div 元素上的类是 post 并且您的 css 目标是“category-pro”。要么更改html中的类,要么更改CSS中的类名
    猜你喜欢
    • 2018-07-30
    • 2013-12-31
    • 2023-03-30
    • 1970-01-01
    • 2016-09-19
    • 2012-03-14
    • 2021-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多