简体   繁体   English

Css选择器无法正常工作

[英]Css selector not working properly

Doing a self practice first time featured sliding bar in Jquery and having a very weird bug and can't seem to find the reason, maybe some of you will see it. 第一次做自我练习在Jquery中有滑动条,有一个非常奇怪的bug,似乎找不到原因,也许你们中的一些人会看到它。

Having the body consists of 2 parts: navigation divs and fragment divs: 主体由2部分组成:导航div和片段div:

<div id="featured">
  <div id="fragment1" class="fragment">This is fragment 1 to show </div>
  <div id="fragment2" class="fragment fragment-hide">This is fragment 2 to show </div>
  <div id="fragment3" class="fragment fragment-hide">This is fragment 3 to show </div>

  <div id="nav-fragment1" class="nav nav-chosen"> This is navigation element 1 </div>
  <div id="nav-fragment2" class="nav"> This is navigation element 2 </div>
  <div id="nav-fragment3" class="nav"> This is navigation element 3 </div>
</div>

There are 2 sets of design classes. 有2套设计类。 The fragment for the chosen fragment and the fragment-hide to hide the fragments not chosen. 所选片段的片段和片段隐藏以隐藏未选择的片段。 There are 2 sets of navigation design classes. 有2套导航设计类。 The nav and the nav-chosen. 导航和导航选择。

This is the CSS: 这是CSS:

#featured{
position:absolute;
top:10px;
left:10px;
width: 800px;
 }

#featured .fragment-hide{   
    display:none;   
}  

#featured .nav-chosen{   
    background-color: #00ff00;  
width:300px;
}  

#featured.nav{
background-color: #ffff00;  
width:300px;
}


#featured .fragment{  
   position:absolute;
   top:0px;
   left:300px; 
   background-color: #ffff00;  
   width:500px;
   height:240px;
}

http://jsfiddle.net/isherwood/URFUS/ http://jsfiddle.net/isherwood/URFUS/

The design works for all element except "featured.nav" no matter what I change (background color, height, width whatever). 无论我改变什么(背景颜色,高度,宽度等),该设计适用于除“featured.nav”之外的所有元素。

It seems like a spelling mistake or a div not closed or something very simple but no matter how many times I read it I just can't locate it. 这似乎是拼写错误或div没有关闭或非常简单的东西,但无论我读了多少次,我都找不到它。 Do you? 你呢?

You'll need a space between #featured.nav should be #featured .nav . 你需要#featured.nav之间的空格应该是#featured .nav Otherwise it will look for a div with the id featured and the class nav . 否则,它将寻找具有id featured nav的div。

You're missing a space between #featured and .nav - the way it is now, you are targeting an element with the ID #featured and the class .nav which is non-existant, based on your HTML. 你错过了#featured.nav之间的空格 - 现在的方式,你的目标是一个ID为#featured的元素一个不存在的类.nav ,基于你的HTML。

#featured .nav{
    background-color: #ffff00;  
   width:300px;
}

There is a huge difference between 两者之间存在巨大差异

#featured.nav{
    background-color: #ffff00;  
    width:300px;
}

and

#featured .nav{
    background-color: #ffff00;  
    width:300px;
}

In the first case - you are styling an element that has both id and class. 在第一种情况-你的造型有两个编号和类的元素。 In the second - a .nav inside of #featured . 在第二个 - #featured里面的.nav

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

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