我目前正在定制一个 wordpress 主题。
在我的案例中,通过一个小部件,我生成了一个包含多个类的 div :
<div class="col-lg-3 focus-box item-1">...</div>
父主题和 Bootstrap 样式表已经分别在 focus-box 和 col-lg-3 类上应用了属性。
好吧,我在我的 child 主题样式表中添加了这个:
.item-1 { background-color: orange; }
这行不通……什么也没发生,但我试图在我的子主题 CSS 中这样做:
.col-lg-3 (or focus-box) { background-color: orange; }
.item-1 { background-color: orange; }
这种方式行得通......我真的不明白这里发生了什么。
我的 Child-theme 样式表是最后一个加载的,所以它应该覆盖所有其他样式表,不是吗?
如果有人有线索,我将不胜感激:-)
预先感谢您的帮助。
小美
最佳答案
感谢您的回答。
首先,我已经尝试使用 !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 元素的位置会影响结果(我知道如果你重写一个属性,这个位置会影响,但在这里它看起来不像这样......)
再次感谢您的帮助。
关于html - WordPress : Child-theme CSS weird behavior,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33076797/