选择其他div中的元素

时间:2017-04-22 13:24:57

标签: css css-selectors

让我们先看看代码bolow

<p>

我希望div-main选择div1 div2。假设我有div1而不是<p>。在这种情况下,我如何选择div-main {1}}

的{1}}

我试过了:

div1+div-main p{}

但它应该不起作用。那里有任何工作功能吗?

4 个答案:

答案 0 :(得分:0)

使用.div-main > p {...}选择p元素中的.div-main标记

但是如果您只想在.div1元素(?)后面选择那些,请使用:

&#13;
&#13;
.div1+.div-main p { color: red; }
&#13;
<div class="div1">
   <p>Hello There</p>
</div>
<div class="div-main">
   <p>Hello There</p>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

使用std::future定位课程int main() { using namespace std::literals; { auto fut1 = std::async(std::launch::async, [] { std::this_thread::sleep_for(5s); std::cout << "work done 1!\n"; }); // here fut1 in its destructor will force a join on a thread associated with above task. } std::cout << "Work done - implicit join on fut1 associated thread just ended\n\n"; std::cout << "Test 2 start" << std::endl; { std::async(std::launch::async, [] { std::this_thread::sleep_for(5s); std::cout << "work done 2!" << std::endl; }); // no future so it should not join - but - it does join somehow. } std::cout << "This shold show before work done 2!?" << std::endl; }

使用.div1查找下一个div1

使用~定位儿童.div-main

>
p

答案 2 :(得分:0)

首先,类选择器必须以点&#34; .div-main&#34;开头。和&#34; .div1&#34;。代码:

&#13;
&#13;
.div1+.div-main p {
  color:red;
}

.div2+.div-main p {
  color:green;
}
&#13;
<div class="div1">
   <p>next red</p>
</div>
<div class="div-main">
   <p>Hello There</p>
</div>

<div class="div2">
   <p>next green</p>
</div>
<div class="div-main">
   <p>Hello There</p>
</div>

<div class="div-main">
   <p>Green ? no!</p>
</div>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

<强> HTML

    <body>  
   <div class="div1">
       <p>Hello There</p>
    </div>
    <div class="div-main">
       <p>Hello There</p>
    </div>
    </body>

<强> CSS

    <style>
    .div-main p {
        color:Blue;
    }
    </style>

https://www.w3schools.com/code/tryit.asp?filename=FEVSB2EMHKLD