gpt4 book ai didi

html - header 隐藏/影响 div 在其之后

转载 作者:太空宇宙 更新时间:2023-11-04 00:59:03 26 4
gpt4 key购买 nike

我的标题 CSS 让我很痛苦。它正在影响它之后发生的事情。我只想在内容中心放置 3 个链接/按钮。但是当我尝试做到的时候。不能正常工作。 p 标签或 h1 标签并不重要,总是卡在标题后面。我使用了 clear fix 但不是很有效。我不确定为什么下一个 div 卡在标题后面。而且当我尝试将 css 提供给行 div 内的 a 标签时。也不生效。

body {
margin: 0;
font-family: Helvetica, sans-serif;
background-color: #f4f4f4;
}

a {
color: #000;
}

/* header */

.header {
background-color: #fff;
box-shadow: 1px 1px 4px 0 rgba(0,0,0,.1);
position: fixed;
width: 100%;
}

.header ul {
margin: 0;
padding: 0;
list-style: none;
overflow: hidden;
background-color: #fff;
}

.header li a {
display: block;
padding: 20px 20px;
border-right: 1px solid #f4f4f4;
text-decoration: none;
}

.header li a:hover,
.header .menu-btn:hover {
background-color: #f4f4f4;
}

.header .logo {
display: block;
float: left;
font-size: 2em;
padding: 10px 20px;
text-decoration: none;
}

/* menu */

.header .menu {
clear: both;
max-height: 0;
transition: max-height .2s ease-out;
}

/* menu icon */

.header .menu-icon {
cursor: pointer;
display: inline-block;
float: right;
padding: 28px 20px;
position: relative;
user-select: none;
}

.header .menu-icon .navicon {
background: #333;
display: block;
height: 2px;
position: relative;
transition: background .2s ease-out;
width: 18px;
}

.header .menu-icon .navicon:before,
.header .menu-icon .navicon:after {
background: #333;
content: '';
display: block;
height: 100%;
position: absolute;
transition: all .2s ease-out;
width: 100%;
}

.header .menu-icon .navicon:before {
top: 5px;
}

.header .menu-icon .navicon:after {
top: -5px;
}

/* menu btn */

.header .menu-btn {
display: none;
}

.header .menu-btn:checked ~ .menu {
max-height: 240px;
}

.header .menu-btn:checked ~ .menu-icon .navicon {
background: transparent;
}

.header .menu-btn:checked ~ .menu-icon .navicon:before {
transform: rotate(-45deg);
}

.header .menu-btn:checked ~ .menu-icon .navicon:after {
transform: rotate(45deg);
}

.header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:before,
.header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:after {
top: 0;
}


html {
font-family: Helvetica Neue;
}


.clearfix:after {
content: ".";
visibility: hidden;
display: block;
height: 0;
clear: both;
}

.row {
margin: auto;
text-align: center;
width: 85%;
color: black;
}

.button a:link {
text-decoration: none;
background-color: black;
border: 1px solid red;
padding: 15px;
}

a:visited {
text-decoration: none !important;
}

/* 48em = 768px */

@media (min-width: 48em) {
.header li {
float: left;
}
.header li a {
padding: 20px 30px;
}
.header .menu {
clear: none;
float: right;
max-height: none;
}
.header .menu-icon {
display: none;
}
}
<header class="header">
<a href="" class="logo">GO</a>
<input class="menu-btn" type="checkbox" id="menu-btn" />
<label class="menu-icon" for="menu-btn"><span class="navicon"></span></label>
<ul class="menu">
<li><a href="#">Menu 1</a></li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
</ul>
</header>

<div class="clearfix"></div>
<div class="row">
<a href="#" class="button">Click</a>
</div>

知道为什么会这样吗?

最佳答案

padding-top 添加到您的 body 并将 header 粘贴到 toptop: 0;

见下文:

body {
margin: 0;
font-family: Helvetica, sans-serif;
background-color: #f4f4f4;
padding-top: 80px; /* added padding-top */
}

a {
color: #000;
}



.header {
background-color: #fff;
box-shadow: 1px 1px 4px 0 rgba(0,0,0,.1);
position: fixed;
width: 100%;
top: 0; /* stick to top */
}

.header ul {
margin: 0;
padding: 0;
list-style: none;
overflow: hidden;
background-color: #fff;
}

.header li a {
display: block;
padding: 20px 20px;
border-right: 1px solid #f4f4f4;
text-decoration: none;
}

.header li a:hover,
.header .menu-btn:hover {
background-color: #f4f4f4;
}

.header .logo {
display: block;
float: left;
font-size: 2em;
padding: 10px 20px;
text-decoration: none;
}

/* menu */

.header .menu {
clear: both;
max-height: 0;
transition: max-height .2s ease-out;
}

/* menu icon */

.header .menu-icon {
cursor: pointer;
display: inline-block;
float: right;
padding: 28px 20px;
position: relative;
user-select: none;
}

.header .menu-icon .navicon {
background: #333;
display: block;
height: 2px;
position: relative;
transition: background .2s ease-out;
width: 18px;
}

.header .menu-icon .navicon:before,
.header .menu-icon .navicon:after {
background: #333;
content: '';
display: block;
height: 100%;
position: absolute;
transition: all .2s ease-out;
width: 100%;
}

.header .menu-icon .navicon:before {
top: 5px;
}

.header .menu-icon .navicon:after {
top: -5px;
}

/* menu btn */

.header .menu-btn {
display: none;
}

.header .menu-btn:checked ~ .menu {
max-height: 240px;
}

.header .menu-btn:checked ~ .menu-icon .navicon {
background: transparent;
}

.header .menu-btn:checked ~ .menu-icon .navicon:before {
transform: rotate(-45deg);
}

.header .menu-btn:checked ~ .menu-icon .navicon:after {
transform: rotate(45deg);
}

.header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:before,
.header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:after {
top: 0;
}


html {
font-family: Helvetica Neue;
}


.clearfix:after {
content: ".";
visibility: hidden;
display: block;
height: 0;
clear: both;
}

.row {
margin: auto;
text-align: center;
width: 85%;
color: black;
}

.button:link {
text-decoration: none;
background-color: black;
border: 1px solid red;
padding: 15px;
color: white; /* added for demonstration */
}

a:visited {
text-decoration: none !important;
}

/* 48em = 768px */

@media (min-width: 48em) {
.header li {
float: left;
}
.header li a {
padding: 20px 30px;
}
.header .menu {
clear: none;
float: right;
max-height: none;
}
.header .menu-icon {
display: none;
}
}
<header class="header">
<a href="" class="logo">Reactive Design</a>
<input class="menu-btn" type="checkbox" id="menu-btn" />
<label class="menu-icon" for="menu-btn"><span class="navicon"></span></label>
<ul class="menu">
<li><a href="#">Menu 1</a></li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
</ul>
</header>

<div class="clearfix"></div>
<div class="row">

<a href="#" class="button">Click</a>

</div>

关于html - header 隐藏/影响 div 在其之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53919995/

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