javascript - 下拉菜单不移动内容
问题描述
所以基本上当我使用我的下拉菜单将我的内容移动到下拉菜单下方时,我有点需要我的标题,因为它就在它上面并且有点碍事。
所以我想问问你对我应该怎么做才能把它移到我的下拉菜单下面的意见,因为它看起来不像这样,而且它并不像这样真的合适
* {
text-decoration: none;
list-style: none;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
font-family: 'Quicksand', sans-serif;
}
.logo {
float: left;
}
.nav {
text-align: right;
height: 100px;
line-height: 100px;
flex: 10;
}
.menu {
margin: 0 30px 0 0;
margin-top: 10px;
}
.menu a {
clear: right;
text-decoration: none;
color: gray;
margin: 0 10px;
line-height: 70px;
font-size: 20px;
margin-top: 10px;
}
label {
margin: 0 40px 0 0;
font-size: 26px;
line-height: 70px;
display: none;
width: 26px;
float: right;
margin-top: 10px;
}
#toggle {
display: none;
}
.icons {
display: flex;
float: right;
}
h3,
h4,
h2 {
font-family: 'Roboto', sans-serif;
}
section {
text-align: center;
align-items: center;
align-self: center;
align-content: center;
}
@media only screen and (max-width:820px) {
.logo {
width: 1%;
}
label {
display: block;
cursor: pointer;
margin-top: 10px;
}
.menu {
text-align: center;
width: 100%;
display: none;
}
.menu a {
display: block;
background-color: white;
margin: 0;
}
#toggle:checked+.menu {
display: block;
}
.icons {
display: inline-block;
width: 100%;
}
}
@media only screen and (max-width:250px) {
* {
visibility: hidden;
}
}
<!DOCTYPE html>
<html lang="cs">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="logo.png" />
<link rel="preconnect" href="https://fonts.gstatic.com">
<script src="https://kit.fontawesome.com/6b8781539d.js" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@300&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="./style.css">
<title>Something</title>
</head>
<body>
<header>
<a class="logo" href="something"><img src="logo.png" alt="logo"></a>
<div class="nav">
<label for="toggle">☰</label>
<input type="checkbox" id="toggle">
<div class="menu">
<a href="something.html">Something</a>
<a href="something.html">Something</a>
<a href="something.html">Something</a>
<a href="something.html">Something</a>
<a href="something.html">Something</a>
<div class="icons">
<a href="https://www.facebook.com/something/"> <i class="fab fa-facebook"></i></a>
<a href="tel:+somenumber"> <i class="fas fa-phone"></i></a>
<a href="mailto:somemail@something.xyz"><i class="far fa-envelope"></i></a>
</div>
</div>
</div>
</header>
<section class="Everything">
<div class="Something">
<a class="Something" href="./something.html">
<h1>Something</h1>
<p>
Something, something, something...
</p>
</a>
</div>
<div class="Something">
<a class="Something" href="./something.html">
<h1>Something</h1>
<p>Something, something, something...</p>
</a>
</div>
</section>
</body>
</html>
解决方案
您有一个固定height
的.nav
容器,.menu
因此无论何时打开.menu
,高度都不会改变,也.menu
不会推送内容,因为您已经声明了
.nav {
height: 100px
}
解决方案是min-height
代替height
,请检查以下内容:
* {
text-decoration: none;
list-style: none;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
font-family: 'Quicksand', sans-serif;
}
.logo {
float: left;
}
.nav {
text-align: right;
min-height: 100px;
line-height: 100px;
flex: 10;
}
.menu {
margin: 0 30px 0 0;
margin-top: 10px;
}
.menu a {
clear: right;
text-decoration: none;
color: gray;
margin: 0 10px;
line-height: 70px;
font-size: 20px;
margin-top: 10px;
}
label {
margin: 0 40px 0 0;
font-size: 26px;
line-height: 70px;
display: none;
width: 26px;
float: right;
margin-top: 10px;
}
#toggle {
display: none;
}
.icons {
display: flex;
float: right;
}
h3,
h4,
h2 {
font-family: 'Roboto', sans-serif;
}
section {
text-align: center;
align-items: center;
align-self: center;
align-content: center;
}
@media only screen and (max-width:820px) {
.logo {
width: 1%;
}
label {
display: block;
cursor: pointer;
margin-top: 10px;
}
.menu {
text-align: center;
width: 100%;
display: none;
}
.menu a {
display: block;
background-color: white;
margin: 0;
}
#toggle:checked+.menu {
display: block;
}
.icons {
display: inline-block;
width: 100%;
}
}
@media only screen and (max-width:250px) {
* {
visibility: hidden;
}
}
<!DOCTYPE html>
<html lang="cs">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="logo.png" />
<link rel="preconnect" href="https://fonts.gstatic.com">
<script src="https://kit.fontawesome.com/6b8781539d.js" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@300&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="./style.css">
<title>Something</title>
</head>
<body>
<header>
<a class="logo" href="something"><img src="logo.png" alt="logo"></a>
<div class="nav">
<label for="toggle">☰</label>
<input type="checkbox" id="toggle">
<div class="menu">
<a href="something.html">Something</a>
<a href="something.html">Something</a>
<a href="something.html">Something</a>
<a href="something.html">Something</a>
<a href="something.html">Something</a>
<div class="icons">
<a href="https://www.facebook.com/something/"> <i class="fab fa-facebook"></i></a>
<a href="tel:+somenumber"> <i class="fas fa-phone"></i></a>
<a href="mailto:somemail@something.xyz"><i class="far fa-envelope"></i></a>
</div>
</div>
</div>
</header>
<section class="Everything">
<div class="Something">
<a class="Something" href="./something.html">
<h1>Something</h1>
<p>
Something, something, something...
</p>
</a>
</div>
<div class="Something">
<a class="Something" href="./something.html">
<h1>Something</h1>
<p>Something, something, something...</p>
</a>
</div>
</section>
</body>
</html>
推荐阅读
- javascript - 如何在 Amazon S3 上托管的网站内绘制数据图表
- python - 根据 request.user Django 2.2 过滤表单视图时出现“无属性”错误
- matlab - 可能重叠的曲线之间的插值
- swift - WKWebView 在 OSX 上显示没有输出的空白屏幕
- django - 如何从clickhouse ORM合并多个查询集
- javascript - 为什么这个像素化动画很震撼
- python - 在 Python 中为列表赋值并转换数据
- scala - 返回指定类型的通用 Traversable
- elasticsearch - 如何过滤来自复合聚合的结果?
- database - 我可以通过 DropBox 共享文件夹测试 Solr 吗?