老师,导航栏和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 */
13
收起
正在回答 回答被采纳积分+1
2回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星