CSS- ckeck并添加右箭头,其中李娜UL(CSS- ckeck and add right a

2019-10-29 13:22发布

我想补充的CSS右箭头,其中UL拥有UL孩子? 下面是三角形正确的CSS。 我想在我的菜单中添加,让用户知道该菜单,子菜单。

怎么可能在纯CSS来检测,如果li有ul.children的孩子?

我想下面的三角形右箭头添加到我的CSS。 PLZ帮助。

对于菜单的PHP代码:

<?php
$stmt = $pdo->query('SELECT * FROM `category` where `parent_id` = 0');
$stmt->execute();
?>

<ul class="top-level-menu">
    <?php while($menu1 = $stmt->fetch()){ ?>
        <li><a href="<?php echo $menu1['category_link'] . "\n"; ?>"><?php echo $menu1['product'] . "\n"; ?></a>

            <?php   $stmt1 = $pdo->prepare('SELECT * FROM category WHERE parent_id = ?');
                    $stmt1->execute([$menu1['id']]);
                    ?>
                    <ul class="second-level-menu">
                        <?php while($menu2 = $stmt1->fetch()){ ?>
                        <li><a href="<?php echo $menu2['category_link'] . "\n"; ?>"><?php echo $menu2['product'] . "\n"; ?></a>
                                    <?php
                                    $stmt2 = $pdo->prepare('SELECT * FROM category WHERE parent_id = ?');
                                    $stmt2->execute([$menu2['id']]);
                                    ?>
                                <ul class="third-level-menu">
                                    <?php while($menu3 = $stmt2->fetch()){ ?>
                                   <li><a href="<?php echo $menu3['category_link'] . "\n"; ?>"><?php echo $menu3['product'] . "\n"; ?></a>
                                   </li>
                                   <?php } ?>
                                </ul>

                        </li>

                        <?php } ?>
                    </ul>


        </li>
<?php } ?>
</ul>

CSS菜单栏

<style>
/* Menu Styles */

.third-level-menu
{
    position: absolute;
    top: 0;
    right: -220px;
    width: 220px;
    list-style: none;
    padding: 0;
    margin: 0;
    display: none;
}

.third-level-menu > li
{
    height: 30px;
    background: #999999;
}
.third-level-menu > li:hover { background: #CCCCCC; }

.second-level-menu
{
    position: absolute;
    top: 30px;
    left: 0;
    width: 200px;
    list-style: none;
    padding: 0;
    margin: 0;
    display: none;
}

.second-level-menu > li
{
    position: relative;
    height: 30px;
    background: #999999;
}
.second-level-menu > li:hover { background: #CCCCCC; }

.top-level-menu
{
    list-style: none;
    padding: 0;
    margin: 0;
}

.top-level-menu > li
{
    position: relative;
    float: left;
    height: 30px;
    width: 100px;
    background: #999999;
}
.top-level-menu > li:hover { background: #CCCCCC; }

.top-level-menu li:hover > ul
{
    /* On hover, display the next level's menu */
    display: inline;
}


/* Menu Link Styles */

.top-level-menu a /* Apply to all links inside the multi-level menu */
{
    font: bold 14px Arial, Helvetica, sans-serif;
    color: #FFFFFF;
    text-decoration: none;
    padding: 0 0 0 10px;

    /* Make the link cover the entire list item-container */
    display: block;
    line-height: 30px;
}
.top-level-menu a:hover { color: #000000; }
</style>

检查我的菜单里没有箭,其中李娜UL

Answer 1:

所以这是真正的CSS无父选择,但你这个标记与jQuery,我们可以使用:有()选择做很多相同的行为。 基本上,如果李EL包含UL,我们应当承担UL是一个子菜单,我将在“JS-有-A-子”类添加到我们使用的菜单项的锚EL。 我已经与“js-”前缀它只是反映它不是一个静态应用类,但一个我们只能通过JS使用。

这里的代码实际上是从我已经在commments引用的菜单示例获取的,但后来我发现,他们会硬编码的向下箭头进入菜单,从而真正打破你想要做什么,从我了解。 所以我删除的向下箭头,并使用jQuery的应用类。 要了解自己的菜单,请不要再去读这个 ,因为我觉得它非常好(粉色的不是一个球迷,但它的CSS)。

 $("li:has(ul)").find("a:eq(0)").addClass("js-has-a-submenu"); 
 body { background: #333; } .clearfix:after { display: block; clear: both; } /*----- Menu Outline -----*/ .menu-wrap { width: 100%; box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.2); background: #3e3436; } .menu { width: 1000px; margin: 0px auto; } .menu li { margin: 0px; list-style: none; font-family: 'Ek Mukta'; } .menu a { text-decoration:none; transition: all linear 0.15s; color: #919191; } .menu li:hover > a, .menu .current-item > a { text-decoration: none; color: #be5b70; } .menu .arrow { font-size: 11px; line-height: 0%; } /*----- Top Level -----*/ .menu > ul > li { float: left; display: inline-block; position: relative; font-size: 19px; } .menu > ul > li > a { padding: 10px 40px; display: inline-block; text-shadow: 0px 1px 0px rgba(0, 0, 0, 0.4); } .menu > ul > li:hover > a, .menu > ul > .current-item > a { background: #2e2728; } /*----- Bottom Level -----*/ .menu li:hover .sub-menu { z-index: 1; opacity: 1; } .sub-menu { width: 160%; padding: 5px 0px; position: absolute; top: 100%; left: 0px; z-index: -1; opacity: 0; transition: opacity linear 0.15s; box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.2); background: #2e2728; } .sub-menu li { display: block; font-size: 16px; } .sub-menu li a { padding: 10px 30px; display: block; } .sub-menu li a:hover, .sub-menu .current-item a { background: #3e3436; } .js-has-a-submenu::after { content: " \2193"; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="menu-wrap"> <nav class="menu"> <ul class="clearfix"> <li><a href="#">Home</a></li> <li> <a href="#">Movies </a> <ul class="sub-menu"> <li><a href="#">In Cinemas Now</a></li> <li><a href="#">Coming Soon</a></li> <li><a href="#">On DVD/Blu-ray</a></li> <li><a href="#">Showtimes &amp; Tickets</a></li> </ul> </li> <li><a href="#">TV Shows</a></li> <li><a href="#">Photos</a></li> <li><a href="#">Site Help</a></li> </ul> </nav> </div> 



Answer 2:

如果你不会隐瞒什么了UL,但是李? 然后,你可以使用::之前得到的css之前你UL插入一个小箭头。

请看看我的小提琴https://jsfiddle.net/dL758uba/

/* Menu Styles */

ul {display: inline;}

ul.third-level-menu::before {
content: '-';
position: relative;
left: -200px;
top: 10px;
}

ul::before {
content: '-';
position: relative;
left: 0px;
top: -20px;
}

.third-level-menu
{
    position: absolute;
    top: 0;
    right: -220px;
    width: 220px;
    list-style: none;
    padding: 0;
    margin: 0;

}

.third-level-menu > li
{
    height: 30px;
    background: #999999;
    display: none;
}
.third-level-menu > li:hover { background: #CCCCCC; }

.second-level-menu
{
    position: absolute;
    top: 30px;
    left: 0;
    width: 200px;
    list-style: none;
    padding: 0;
    margin: 0;

}

.second-level-menu > li
{
    position: relative;
    height: 30px;
    background: #999999;
    display: none;
}
.second-level-menu > li:hover { background: #CCCCCC; }

.top-level-menu
{
    list-style: none;
    padding: 0;
    margin: 0;
}

.top-level-menu > li
{
    position: relative;
    float: left;
    height: 30px;
    width: 100px;
    background: #999999;
}
.top-level-menu > li:hover { background: #CCCCCC; }

.top-level-menu li:hover > ul >li
{
    /* On hover, display the next level's menu */
    display: block;
}


/* Menu Link Styles */

.top-level-menu a /* Apply to all links inside the multi-level menu */
{
    font: bold 14px Arial, Helvetica, sans-serif;
    color: #FFFFFF;
    text-decoration: none;
    padding: 0 0 0 10px;

    /* Make the link cover the entire list item-container */
    display: block;
    line-height: 30px;
}
.top-level-menu a:hover { color: #000000; }

这是一个有点粗糙,但我认为它会帮助你在正确的方向。



文章来源: CSS- ckeck and add right arrow where li has ul