html - position fixed 将其下方的所有内容向下推以创建空白?

标签 html css

<分区>

嘿,伙计,我正在为一家建筑公司制作一个网站,我刚刚完成了页眉部分。我现在返回并将导航部分设置为 position: fixed; 这样做会将导航部分及其下方的所有内容向下推,如 500 像素,从而创建一些丑陋的空白。我可以在这个问题上得到一些帮助吗?谢谢:)

body, html {
	margin: 0;
	padding: 0;
}

/*---HEADER---*/

header {
	background-image: url(img/wall2.jpeg);
	height: 100vh;
	background-attachment: fixed;
}

nav {
	background-color: white;
	width: 100%;
	display: flex;
	justify-content: space-between;
	align-items: center;
	position: fixed;
}

.logo, ul {
	flex-basis: 30%;
	list-style-type: none;
}

ul {
	margin-right: 30px;
}

li {
	display: inline-block;
	font-size: 1.3rem;
	margin-right: 20px;
	font-family: 'MontSerrat';
	color: rgba(102,102,102,0.75);
}

li:hover {
	cursor: pointer;
	color: #1a1a1a;
	transition: all 0.7s ease;
}

.after:after {
	position: relative;
	left: 12px;
	top: 2px;
	display: inline-block;
	content: "";
	width: 1px;
	height: 20px;
	background-color: rgba(102,102,102,0.25);
}

.logo {
	color: red;
	font-size: 4rem;
	margin: 10px;
	opacity: 1;
	margin-left: 30px;
}

.phrase {
	text-align: center;
	margin-top: 275px;
}

.phrase p {
	color: white;
	font-size: 3.5rem;
	font-family: 'Arvo';
	margin-bottom: 30px;

}

.phrase a {
	background-color: #e62e00;
	border-radius: 25px;
	color: white;
	font-family: 'Bitter';
	font-size: 1.8rem;
	padding-left: 15px;
	padding-right: 15px;
	padding-bottom: 10px;
	padding-top: 10px;
}

.phrase a:hover {
	background-color: #cc2900;
	transition: all 0.5s ease;
	cursor: pointer;
}

.phrase .fas {
	display: block;
	color: white;
	font-size: 3.5rem;
	margin-top: 15px;
}

/*---ABOUT---*/

.stats {
	width: 100%;
	height: 100px;
}
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Kane Concrete And Construction LLC</title>
	<link rel="stylesheet" href="style.css">
	<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
	<link href="https://fonts.googleapis.com/css?family=Arvo|Bitter|Lato|Montserrat|Noto+Sans|Open+Sans|Poppins|Roboto|Sarabun|Ubuntu" rel="stylesheet">
	<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
</head>
<body>
	<header>
		<nav>
			<div class="logo">
				<i class="fab fa-accusoft"></i>
			</div>

			<div class="nav">
				<ul>
					<li class="after">Home</li>
					<li class="after">About</li>
					<li class="after">Services</li>
					<li class="after">Job Openings</li>
					<li class="after">Gallery</li>
					<li>Contact</li>
				</ul>
			</div>
		</nav>
		
		<div class="phrase">
			<p>It all starts at the foundation.</p>
			<a>Get a Quote</a>
			<i class="fas fa-angle-down"></i>
		</div>	
	</header>

	<main>
		<div class="stats">
			<div class="start-year">
				
			</div>

			<div class="projects">
				
			</div>
		</div>
	</main>
</body>
</html>

最佳答案

当您使用 position: absoluteposition: fixed 时,最好使用 topright 来适当定位它leftbottom

因此,您可以在 CSS 中添加:

nav {
  top: 0;
  left: 0;
}

关于html - position fixed 将其下方的所有内容向下推以创建空白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54383492/

上一篇:html - 如何在 Bootstrap 中禁用断点

下一篇:html - 我对这个导航栏有问题。当鼠标悬停在它上面时,所有按钮都在移动

相关文章:

html - 范围 slider 不一致地消失?

css - 对齐卡片内容(图像、文本和按钮)

javascript - 当显示较小时,div 从外部 div 弹出

css - 数据绑定(bind)循环 knockout js,如果我想一次只显示列表中的 2 个名称,然后单击接下来的 2 个名称的按钮

javascript - 网站未加载 jQuery

html - 位于网站两个部分之间的图片

java - 从代码渲染一个 jsp 页面并将渲染后的 html 输出作为字符串

html - 如何在Firebug中获取元素的绝对XPath?

CSS::after - 内容属性在每个浏览器上以相同的样式显示 unicode 图标 (2192)

css - 如何在 flex-box 中定位?