在具有特定类别的div跨度之后将样式应用于ul li

时间:2019-05-16 04:13:14

标签: css css-selectors

我想将div后面的ul li元素应用CSS。使用CSS选择器,如何选择遵循特定div的li元素?我以为是这样,但是它不起作用

div span.survey_one ~ div ul li{
list-style-type:none;
font-size:1.2rem;
}

这是HTML:

<div><span class="survey_one">dddddddddddddd</span>
    <br>
</div>
<div>
    <ul>
        <li>a</li>
        <li>b</li>
        <li>c</li>
        <li>d</li>
    </ul>
</div>

2 个答案:

答案 0 :(得分:2)

您正在使用general sibling combinator

现在成为常规同级选择器的方式是选择<span class="survey_one">dddddddddddddd</span>的同级,而<br>只是div ~ div ul li

尝试将常规兄弟姐妹设置为此div ~ div ul li{ list-style-type:none; font-size:1.2rem; color: red; //added for illustrative purposes }

<div><span class="survey_one">dddddddddddddd</span>
    <br>
</div>
<div>
    <ul>
        <li>a</li>
        <li>b</li>
        <li>c</li>
        <li>d</li>
    </ul>
</div>
PHP Warning:  PHP Startup: Unable to load dynamic library 'mysqli' (tried: /usr/lib/php/20170718/mysqli (/usr/lib/php/20170718/mysqli: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/mysqli.so (/usr/lib/php/20170718/mysqli.so: undefined symbol: mysqlnd_global_stats)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried: /usr/lib/php/20170718/pdo_pgsql (/usr/lib/php/20170718/pdo_pgsql: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_pgsql.so (/usr/lib/php/20170718/pdo_pgsql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/lib/php/20170718/pdo_sqlite (/usr/lib/php/20170718/pdo_sqlite: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_sqlite.so (/usr/lib/php/20170718/pdo_sqlite.so: undefined symbol: php_pdo_unregister_driver)) in Unknown on line 0
PHP Warning:  Module 'pgsql' already loaded in Unknown on line 0
PHP Warning:  Module 'sqlite3' already loaded in Unknown on line 0

答案 1 :(得分:1)

我认为最好将两个div放在父容器中,然后选择li .parent li

或者要实现您的最初目标,请使用javascript 1.使用Survey_one类选择第一个div的父元素 2.横切到父节点的子li

无论哪种方式,都应将两个div放在父容器中