我有以下HTML代码
<div id="left">
<div id="coverage">
<h3>coverage</h3>
<!-- first div -->
<div>
<div>
<span>left->coverage->div 1->inner div 1->span text</span>
</div>
<div>
<span>left->coverage->div 1->inner div 2->span text</span>
</div>
</div>
<!-- second div -->
<div>
<!-- div to be accessed -->
<div>
<span>left->coverage->div 2->inner div 1->span text</span>
</div>
</div>
</div>
</div>
我需要访问嵌套在第二个div中的第一个div。我试过这个,但它没有工作
#left #coverage div:first-child
{
color: red;
}
答案 0 :(得分:2)
您可以使用div
获得第二个:first-child
和#left #coverage > div:nth-of-type(2) div:first-child {
color: red;
}
以获得第一个div。
<div id="left">
<div id="coverage">
<h3>coverage</h3>
<!-- first div -->
<div>
<div>
<span>left->coverage->div 1->inner div 1->span text</span>
</div>
<div>
<span>left->coverage->div 1->inner div 2->span text</span>
</div>
</div>
<!-- second div -->
<div>
<!-- div to be accessed -->
<div>
<span>left->coverage->div 2->inner div 1->span text</span>
</div>
</div>
</div>
</div>
&#13;
public class ImportFragment extends Fragment {
ListView listView;
@Nullable
@Override
enter code here
Button butt1=(Button)findViewById(R.id.btn1);
butt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent int1=new Intent(MainActivity.this,newactivity.class);
startActivity(int1);
finish();
}
});
return rootView;
}
}
&#13;
答案 1 :(得分:1)
foo = [
foorule("a"),
foorule("b"),
]
应该适用于您的目的:
deadbeaf-0011-...
#left #coverage>div:nth-of-type(2)>div