【问题标题】:Wordpress : Child-theme CSS weird behaviorWordpress:儿童主题 CSS 奇怪的行为
【发布时间】:2016-01-09 16:14:33
【问题描述】:

我目前正在定制一个 wordpress 主题。

在我的例子中,通过一个小部件,我生成了一个包含多个类的 div:

<div class="col-lg-3 focus-box item-1">...</div>

父主题和引导样式表已经分别在 focus-box 和 col-lg-3 类上应用属性。

好吧,我在我的子主题样式表中添加了这个:

.item-1 { background-color: orange; }

这不起作用...什么也没发生,但我尝试在我的子主题 CSS 中这样做:

.col-lg-3 (or focus-box) { background-color: orange; }
.item-1 { background-color: orange; }

这种方式行得通……我真的不明白这里发生了什么。

我的子主题样式表是最后一个要加载的样式表,所以它应该覆盖所有其他样式表,不是吗?

如果有人有线索,我将不胜感激:-)

提前感谢您的帮助。

苏米

【问题讨论】:

    标签: html css wordpress twitter-bootstrap


    【解决方案1】:

    感谢您的回答。

    首先,我已经尝试使用!important,它不起作用,使用更强的选择器也是如此。

    我知道如何使用我的浏览器检查代码,这就是为什么我告诉你我的子主题 css 是最后一个加载的,因为我检查了它。

    在我看来,真正奇怪的是,无论我是否在样式表中输入col-lg-3,结果都会有所不同。

    我的代码中的其他 HTML 元素也有类似的问题。

    总结一下:

    • 我的 Child-Theme CSS 是在 parent-one 之后加载的
    • 我在浏览器开发工具中检查过
    • 我还注意到我的 CSS 属性改变结果的地方,如果我把它放在我的子主题 css 的末尾,它有时会起作用:

    {

    /* IF I PUT THE SELECTOR .focus-box .service-icon here It doesn't work */
    /* SEE THE LAST ELEMENT BELOW */
    
    .focus-box:nth-child(4n+1) .service-icon:hover {
        border: 5px solid #e96656;
    }
    
    .focus-box:nth-child(4n+2) .service-icon:hover{
        border: 5px solid #34d293;
    }
    .focus-box:nth-child(4n+3) .service-icon:hover {
        border: 5px solid #3ab0e2;
    }
    .focus-box:nth-child(4n+4) .service-icon:hover{
        border: 5px solid #f7d861;
    }
    .focus-box:nth-child(4n+1) .red-border-bottom:before {
        background: #e96656;
    }
    .focus-box:nth-child(4n+2) .red-border-bottom:before {
        background: #34d293;
    }
    .focus-box:nth-child(4n+3) .red-border-bottom:before {
        background: #3ab0e2;
    }
    .focus-box:nth-child(4n+4) .red-border-bottom:before {
        background: #f7d861;
    }
    .focus-box h5 {
        margin-bottom: 15px;
        color: #404040;
        position: relative;
        display: inline-block;
        text-transform: uppercase;
        margin-bottom: 30px;
        font-weight: bold;
        font-size: 17px;
        float: none;
        width: 100%;
        background-color: rgba(224,82,6,0.2);
    }
    
    .other-focuses {
        background: url(images/lines.png) repeat-x center;
        margin-bottom: 25px;
    }
    .other-focuses .section-footer-title {
        padding: 0 15px;
        color: #404040;
        font-weight: bold;
    }
    .other-focus-list {
        padding-top: 5px;
        margin-bottom: -17px;
    }
    .other-focus-list ul li {
        display: inline-block;
        margin-right: 50px;
        padding-bottom: 15px;
        text-transform: uppercase;
    }
    .other-focus-list ul li:last-child {
        margin-right: 0;
    }
    .other-focus-list ul li i {
        margin-right: 8px;
    }
    
    
    .item-dashboard {
    
        padding: 20px 0 20px 0;
    
    }
    
    .focus-box p {
        font-size: 14px;
        color: black;
    
    }
    
    /* IF I PUT IT THERE THEN IT WORKS */
    .focus-box .service-icon {
        margin-bottom: 30px;
        width: 145px;
        height: 145px;
        margin: auto;
        border-radius: 50%;
        border: 0px solid #ececec;
        margin-bottom: 20px;
        position: relative;
        -webkit-transition: all 0.2s ease-in-out;
        transition: all 0.2s ease-in-out;
    }
    

    焦点框 HTML 代码:

        <div class="col-lg-3 col-sm-3 focus-box item-dashboard" data-scrollreveal="enter left after 0.15s over 1s">
    
            <div class="service-icon">
    
    
                    <a href="#">
                        <i class="pixeden" style="background:url(#/wordpress/wp-content/uploads/2015/10/cle_main_2.png) no-repeat center;width:100%; height:100%;"></i> <!-- FOCUS ICON-->
                    </a>
    
    
    
            </div>
    
            <!-- FOCUS HEADING -->
    
    
    
        </div>
    

    问题是为什么我的子主题 CSS 没有正确覆盖父主题?为什么我的 css 元素的位置会影响结果(我知道如果你覆盖一个属性,这个位置会影响,但在这里它看起来不像这样......)

    再次感谢您的帮助。

    【讨论】:

    • 我刚刚在上一个答案中添加了它:-)
    【解决方案2】:

    通过查看样式表加载优先级等,我终于克服了这个问题。

    谢谢大家。

    【讨论】:

      猜你喜欢
      • 2015-10-24
      • 2020-07-03
      • 1970-01-01
      • 1970-01-01
      • 2017-06-06
      • 1970-01-01
      • 1970-01-01
      • 2020-03-06
      • 2013-12-03
      相关资源
      最近更新 更多