简体   繁体   English

无法搁置类以WordPress style.css响应CSS

[英]Unable to get aside class to respond to CSS in WordPress style.css

I am creating my website on WordPress and am trying with no success to style the sidebar. 我正在WordPress上创建我的网站,并且尝试对边栏进行样式设置没有成功。 The HTML shows <aside class="sidebar sidebar-primary widget-area" [etc.]> . HTML显示<aside class="sidebar sidebar-primary widget-area" [etc.]>

For the life of me, I cannot get a border radius on this class. 为了我的一生,我在这堂课上找不到边界半径。 I've tried using 我试过使用

.sidebar .sidebar-primary .widget-area { border-radius: 5px; } 

with no avail. 无济于事。 I've tried nesting it under its parent div but that didn't work either. 我试过将其嵌套在其父div下,但这也不起作用。

I got the main content area to respond, but this one seems to be a bigger pain. 我得到了主要内容方面的回应,但是这似乎是一个更大的痛苦。 Is there something I'm missing for aside classes? 上课时我缺少什么吗? What am I doing wrong? 我究竟做错了什么?

Solution: 解:

Since the HTML code has multiple classes, you can target it with Multiple class selector : 由于HTML代码具有多个类,因此可以使用Multiple class selector来定位它:

.sidebar.sidebar-primary.widget-area {
   border-radius: 5px;
}

Problem: 问题:

Remember that you were trying to use Descendant selector 记住,您尝试使用Descendant selector

Your code .sidebar .sidebar-primary .widget-area would have worked for: 您的代码.sidebar .sidebar-primary .widget-area适用于:

<aside class="sidebar">
   <div class="sidebar-primary"> 
      <div class="widget-area"> 
         // Contents of widget area
      </div>
   </div>
</aside>

Edit: 编辑:

After you posted your live demo, it seems you wanted to add border-radius to each individual widget. 在发布实时演示之后,您似乎想为每个小部件添加边框半径。 My suggested solution will not work again for that. 我建议的解决方案将无法再次使用。 It targets the whole widget area. 它以整个小部件区域为目标。 Below is the CSS rule you are looking for: 以下是您要查找的CSS规则:

.sidebar .widget { border-radius: 5px; }
.sidebar .sidebar-primary .widget-area { border-radius: 5px; } 

means you are are targeting a class of .widget-area that exists under .sidebar-primary that exists under .sidebar. 表示您要定位的是.sidebar-primary下存在的.widget-area类。 In order to achieve the effect you actually want 为了达到您真正想要的效果

.sidebar.sidebar-primary.widget-area { broder-radius: 5px; } 

which means you are targeting a class of sidebar that also has classes of .sidebar-primary and widget-area 这意味着您要定位的侧边栏类别也具有.sidebar-primary和widget-area类别

.sidebar.sidebar-primary.widget-area { border-radius: 5px; } 

...is what you want (note the lack of spaces between the class selectors). ...就是您想要的(注意类选择器之间缺少空格)。

Depending on your specificity requirements, you might only need: 根据您的特异性要求,您可能只需要:

.sidebar-primary.widget-area { border-radius: 5px; }

Or: 要么:

.widget-area { border-radius: 5px; }

You only nest selectors when your HTML is nested. 仅在嵌套HTML时嵌套选择器。 Your HTML isn't nested, you just have multiple classes on the same DOM node :) 您的HTML没有嵌套,在同一个DOM节点上只有多个类:)

Nested HTML would look like: 嵌套的HTML如下所示:

<aside class="sidebar">
    <div class="sidebar-primary">
        <div class="widget-area">
        ...
        </div>
    </div>
</aside>

In addition to above answers, you can target it like 除了上述答案外,您还可以像

aside.sidebar-primary {   // or aside.widget-area depending on your needs
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    -o-border-radius: 5px;
    -ms-border-radius: 5px;
    border-radius: 5px;
}

The first four lines are vendor-prefixed properties offered by rendering engines (-webkit for Chrome, Safari; -moz for Firefox, -o for Opera, -ms for Internet Explorer) to avoid cross-browser inconsistencies. 前四行是渲染引擎(用于Chrome,Safari的-webkit;用于Firefox的-moz;用于Opera的-o;用于Internet Explorer的-ms)提供的供应商前缀属性,以避免跨浏览器不一致。

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

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