gpt4 book ai didi

html - 在移动 View 中删除不必要的边距

转载 作者:行者123 更新时间:2023-11-27 23:14:35 24 4
gpt4 key购买 nike

我在移动 View 上处理我的网站导航,一个纯 css 汉堡菜单,我的问题是标题(包括 Logo 和汉堡菜单)和我的导航的下拉列表之间存在间隙。

/*
html5doctor.com Reset Stylesheet
v1.6.1
Last Updated: 2010-09-17
Author: Richard Clark - http://richclarkdesign.com
Twitter: @rich_clark
*/

html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code,
del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var,
b, i,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, figcaption, figure,
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {
margin:0;
padding:0;
border:0;
outline:0;
font-size:100%;
vertical-align:baseline;
background:transparent;
}

body {
line-height:1;
}

article,aside,details,figcaption,figure,
footer,header,hgroup,menu,nav,section {
display:block;
}

nav ul {
list-style:none;
}

blockquote, q {
quotes:none;
}

blockquote:before, blockquote:after,
q:before, q:after {
content:'';
content:none;
}

a {
margin:0;
padding:0;
font-size:100%;
vertical-align:baseline;
background:transparent;
}

/* change colours to suit your needs */
ins {
background-color:#ff9;
color:#000;
text-decoration:none;
}

/* change colours to suit your needs */
mark {
background-color:#ff9;
color:#000;
font-style:italic;
font-weight:bold;
}

del {
text-decoration: line-through;
}

abbr[title], dfn[title] {
border-bottom:1px dotted;
cursor:help;
}

table {
border-collapse:collapse;
border-spacing:0;
}

/* change border colour to suit your needs */
hr {
display:block;
height:1px;
border:0;
border-top:1px solid #cccccc;
margin:1em 0;
padding:0;
}

input, select {
vertical-align:middle;
}

/*--------------MY CODE----------*/

/*--------------MY CODE----------*/

/*MOBILE VIEW*/
* {
text-decoration: none;
font-family: Catamaran, sans-serif;
}

header {
background-color: #dbd3d34b;
height: 100px;
box-shadow: 1px 1px rgb(177, 175, 175);
z-index: 1;
}

.logo {
display: block;
float: left;
margin: 27px 0;
}

.logo img{
width: 200px;
height: 50px;
}

nav ul {
overflow: hidden;
}
nav ul li a {
display: block;
background-color: #f2f2f2;
font-family: Roboto, sans-serif;
font-size: 16px;
padding: 20px;
font-weight: 400;
color: #111;
border-bottom: 1px solid rgb(8, 189, 53);
position: relative;
z-index: 1;
}
nav ul li a:hover {
color: rgb(8, 189, 53);
}

/*-------HAMBURGER MENU-------------*/
nav ul {
border: 1px solid red;
}
nav .menu {
clear: both;
max-height: 0;
transition: max-height .2s ease-out;
}
nav .menu-icon {
margin: 30px 0;
padding: 20px 15px;
position: relative;
float: right;
}
nav .menu-icon .nav-icon {
background-color: #111;
display: block;
height: 3px;
width: 25px;
position: relative;
transition: background .2s ease-out;
}
nav .menu-icon .nav-icon:before {
background-color: #111;
content:"";
height: 100%;
width: 100%;
position: absolute;
transition: all .2s ease-out;
top: 7px;
}
nav .menu-icon .nav-icon:after {
background-color: #111;
content:"";
height: 100%;
width: 100%;
position: absolute;
transition: all .2s ease-out;
bottom: 7px;
}
.menu-btn {
display: none;
}

nav .menu-btn:checked ~ .menu {
max-height: 260px;
}

nav .menu-btn:checked ~ .menu-icon .nav-icon {
background-color:transparent;
}
nav .menu-btn:checked ~ .menu-icon .nav-icon:before {
transform: rotate(-45deg);
top:0;
}
nav .menu-btn:checked ~ .menu-icon .nav-icon:after {
transform: rotate(45deg);
top:0;
}
/*----END OF HAMBERGER MENU*/

/*---------DESKTOP DISPLAY*/
@media only screen and (min-width: 1000px) {
.menu-btn {
display: none;
}
nav .menu {
clear: none;
max-height: none;
}
nav .menu-icon {
display: none
}
.logo {
display: block;
float: left;
margin: 4px 0;
}

.logo img{
width: 380px;
height: 86px;
}

nav {
float : right;
width: 600px;
height: 100px;
margin-right: 80px;
}
nav ul {
height: inherit;
display: flex;
flex-flow: row;
justify-content: space-between;
align-items: center;
}

nav ul li a {
font-size: 24px;
font-weight: 600;
color: #111;
border-bottom: none;
}


.main {
background-image: url("img/header.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
width: 100%;
height: 400px;
margin-top: 1px;

display: flex;
justify-content: center;
align-items: center;
}

.main .header-text{
width: 600px;
text-align: center;
}

.main .header-text h1{
font-size: 68px;
color: #f2f2f2;
text-shadow: 1px 1px #111, -0.5px -0.5px #111;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0 , maximum-scale=1.0, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" type ="text/css" href="main-page.css">
<title>Portfolio Michael</title>
</head>
<body>
<header class="header">
<div class="logo">
<img src="img/logo.png" alt="Web Page Logo">
</div>
<nav>

<input class="menu-btn" type="checkbox" id="menu-btn">
<label class="menu-icon" for="menu-btn"><span class="nav-icon"></span></label>

<ul class="menu">
<li><a href="#">Excercises</a></li>
<li><a href="#">Projects</a></li>
<li><a href="#">About</a></li>
</ul>

</nav>
</header>

<main>
<section class="main">
<div class="header-text">
<h1>Hi! I'm Michael! And this is my Website</h1>
</div>
</section>
</main>

</body>
</html>
如果你运行这段代码,你可以在移动 View 中看到标题和我的主页之间有一个小间隙,我用红色边框突出了这个间隙。

我试图在我的“导航菜单”中添加负边距顶部和边距 0,但没有任何反应。

最佳答案

问题出在 nav .menu

您只需在 CSS 中指定 0 的边距即可解决此问题。

nav .menu {
clear: both;
max-height: 0;
transition: max-height 0.2s ease-out;
margin: 0;
}

enter image description here

关于html - 在移动 View 中删除不必要的边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58326034/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com