微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Flexbox创建导航栏

如何解决使用Flexbox创建导航栏

我只学习了几周的代码,所以我有非常基础的知识。 我在尝试使用flexBox构建导航栏时遇到了麻烦。

由于某种原因,我无法将导航按钮(

  • )垂直放置。 我一直在尝试并重新编写代码,但无法弄清楚。

    这是我的代码链接https://codepen.io/kokazp/pen/xxORovj?editors=1100

    谢谢。

    body{
        font-family: 'Yanone Kaffeesatz',sans-serif;
        background-color: lightGray;
    }
    
    navbar {
        background: white;
        Box-shadow: 0px 0px 10px var(--clr-gray200);
        padding: 1rem 0;
        border-radius: var(--radius);
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        align-items: center;
      }
    
    #header-img{
        height: 70px;
        width: 70px;
        margin-right: auto;
        margin-left: 10px;
    }
    
    ul{
        list-style: none;
        margin: 0;
        padding: 0;
    }
        
    li,a{
        background-color:white;
        text-decoration: none;
        padding: 8px;
        color:black;
    }
            
    li a:hover{
        background-color: black;
        color: white;
    }
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <Meta charset="UTF-8">
            <Meta name="viewport" content="width=device-width,initial-scale=1.0">
            <title>Document</title>
            <link href="https://fonts.googleapis.com/css2?family=Yanone+Kaffeesatz:wght@300&display=swap" rel="stylesheet">
            <link rel=StyleSheet HREF="estilo.css">
        </head>
        
        <body>
    
            <header id="header">
                <navbar id="nav-bar">
                    <ul>
                        <li><img src="https://blog.spoongraphics.co.uk/wp-content/uploads/2017/craft-brewery-logos/1.jpg" id="header-img" alt="Company logo"></li>
                        <li><a href="#form">Contact</a></li>
                        <li><a href="#beers">Beers</a></li>
                        <li><a href="#video">Video</a></li>
                    </ul>
                </navbar>
            </header>
        </body>
    </html>
  • 解决方法

    让我们清楚地说明,当您使用伸缩框时,它适用于子级,而不适用于子级;当您将default应用于导航栏时,它将使 ul 变为伸缩子级,因此 li标签不能弯曲,其次,您要使其成为纵列,以便使其以垂直方式显示。 解决方案:您可以制作ul

        /* Stop at This Frame
        The Animate timeline will stop/pause at the frame where you insert this code.
        Can also be used to stop/pause the timeline of movieclips.
        */
        
        stop();
        
        var offset:int = 10
        
        PP1.buttonMode = true;
        PP1.addEventListener(MouseEvent.MOUSE_DOWN,startdragging);
        PP1.addEventListener(MouseEvent.MOUSE_UP,stopdragging);
        
        var PP1StartX:int = 30
        var PP1StartY:int = 343
        var PP1EndX:int = 617
        var PP1EndY:int = 97
          
        //------------------------------
        
        function startdragging(e:MouseEvent):void {
            e.currentTarget.startDrag();
        }
        function stopdragging(e:MouseEvent):void{
            e.currentTarget.stopDrag();
                switch(e.currentTarget){
        }
    }
    

    默认情况下,它将使li转到行方向

    版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。