老师,导航栏和Logo如何调换位置?

老师,导航栏和Logo如何调换位置?

问题描述:

导航栏和Logo如何调换位置?我的按钮的样式也有点问题,后面那个红色的扇形如何实现?

相关代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/grid.css">
    <link rel="stylesheet" href="css/index.css">
</head>

<body>
    <header class="header-container">
        <div class="container">
            <div class="row">
                <div class="header-btn-container col-4 d-md-none">
                    <button type="button" class="btn-toggle" id="btn-toggle">
                        <span class="btn-toggle-bar"></span>
                        <span class="btn-toggle-bar"></span>
                    </button>
                </div>
                <div class="header-logo-container col-8 col-md-8">
                    <a href="./index.html" class="header-logo">
                        <img src="img/logo.png" alt="logo">
                    </a>
                </div>
                <nav class="header-nav-container col-md-4 d-none d-md-block">
                    <ul class="header-nav">
                        <li class="header-nav-item">
                            <a href="###" class="header-nav-link">
                                首页
                            </a>
                        </li>
                        <li class="header-nav-item">
                            <a href="###" class="header-nav-link">
                                关于
                            </a>
                        </li>
                        <li class="header-nav-item">
                            <a href="###" class="header-nav-link">
                                商业合作
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </header>

    <nav id="nav" class="nav-container d-md-none">
        <ul class="container">
            <li>
                <a href="###" class="nav-link">首页</a>
            </li>
            <li>
                <a href="###" class="nav-link">关于</a>
            </li>
            <li>
                <a href="###" class="nav-link">商业合作</a>
            </li>
        </ul>
    </nav>

    <script>
        var nav = document.getElementById('nav');
        var navExtendedClassName = 'nav-container-extended';

        document.getElementById('btn-toggle').onclick = function () {
            // nav.className += ' ' + navExtendedClassName;
            if (nav.classList.contains(navExtendedClassName)) { // 收起
                nav.classList.remove(navExtendedClassName);
            } else { // 展开
                nav.classList.add(navExtendedClassName);
            }
        };
    </script>
</body>

</html>

相关代码:

​/* 布局 start */

/* header */
.header-container {
background-color: #fff;
border-bottom: 1px solid #dadada;
}

.header-logo-container,
.header-btn-container,
.header-nav-container {
height: 70px;
}

.header-btn-container {
display: flex;
justify-content: flex-start;
align-items: center;
background-color: red;
}
.nav-container {
overflow: hidden;
position: relative;
top: -1px;
height: 0;
border-bottom: 1px solid #dadada;
transition: height 0.5s;
}

.nav-container-extended {
top: 0;
height: 180px;
}
.nav-container li {
background-color: #DDDDDD;
border-bottom: 1px solid #999;
padding: 10px 35px;
}
/* 布局 end */

/* 组件 start */
/* btn-toggle */
.btn-toggle {
background-color: transparent;
border: none;
border-radius: 4px;
cursor: pointer;
}

.btn-toggle-bar {
display: block;
width: 30px;
height: 3px;
background-color: white;
border-radius: 2px;
}

.btn-toggle-bar+.btn-toggle-bar {
margin-top: 10px;
}

/* 组件 end */

/* 内容 start */
/* header */
.header-logo {
display: flex;
align-items: center;
height: 100%;
width: 136px;
}
.header-nav,
.header-nav-item,
.header-nav-link {
height: 100%;
}
.header-nav {
display: flex;
justify-content: flex-start;
font-size: 14px;
}

.header-nav-item {
margin-left: 24px;
}

.header-nav-item:first-child {
margin-left: 0;
}

.header-nav-link {
display: flex;
align-items: center;
font-weight: bold;
}

/* nav */
.nav-link {
display: block;
height: 40px;
line-height: 40px;
font-weight: bold;
}
/* 内容 end */


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
好帮手慕言 2021-07-17 13:59:30

同学你好,同学的代码中,点击事件是给#btn-toggle添加的,也就是鼠标点击下方蓝色区域是可以触发点击事件的。

http://img1.sycdn.imooc.com//climg/60f270ba095a3d8402790126.jpg

如果同学觉得点击范围太小了,可以给.header-btn-container元素添加点击事件。祝学习愉快~

好帮手慕言 2021-07-16 18:15:54

同学你好,如下:

1、可以通过定位调整导航位置,如下:
http://img1.sycdn.imooc.com//climg/60f1520109dac9fe03640392.jpg

2、调整按钮的样式

http://img1.sycdn.imooc.com//climg/60f1532e09da107e04970248.jpg

同学可以根据效果图自己再修改下样式,祝学习愉快~

  • 提问者 一心励志当码农 #1

    老师,这样修改的话,按钮就没有点击事件了

    2021-07-17 10:02:06
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师