所以我正在我的投资组合网站上工作,我正在使用 Bootstrap 5 并编写一些自定义 CSS。现在发生的是我的垂直滚动条没有出现。我在这里做错了什么?我按照 youtube 教程创建了使用 GSAP 的导航栏。
这是我的 HTML
<!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">
<!-- Bootstrap 5 -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.iife.js"></script>
<!-- font -->
<link rel="stylesheet" href="static/fonts/gracheva/Gracheva.otf">
<link rel="stylesheet" href="static/fonts/uncut-sans/Uncut-Sans-Bold.otf">
<!-- custom css -->
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css')}}">
<title>{{title}}</title>
</head>
<body>
<header>
<div>
<button class="header__button nav-btn-js" type="button"></button>
<nav class="header__nav nav-js" data-active="false">
<ul class="header__menu">
<li class="header__menu-item"><a href="#">Home</a></li>
<li class="header__menu-item"><a href="#">works</a></li>
<li class="header__menu-item"><a href="#">About</a></li>
</ul>
</nav>
</div>
</header>
<div class="container">
<div class="first">
<h1 class="heading">Product designer with passion for user research and visual design</h1>
<p id="para">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Maiores, quas, explicabo ad doloremque nulla labore possimus magnam minima qui a consequuntur tenetur debitis iure accusamus nisi iste porro. Aperiam, sed!</p>
</div>
</div>
<div class="container">
<div class="works">
<h1 class="heading">Selected works</h1>
<hr class="line">
<div class="row">
<div class="col-6">
<h1 class="heading2">Self elevate</h1>
</div>
<div class="col-6">
<p id="para">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Maiores, quas, explicabo ad doloremque nulla labore possimus magnam minima qui a consequuntur tenetur debitis iure accusamus nisi iste porro. Aperiam, sed!</p>
</div>
</div>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
const revealerNav = window.revealer({
revealElementSelector: ".nav-js",
options: {
anchorSelector: ".nav-btn-js",
},
});
const actionBtn = document.querySelector(".nav-btn-js");
actionBtn.addEventListener("click", () => {
if (!revealerNav.isRevealed()) {
revealerNav.reveal();
actionBtn.setAttribute("data-open", true);
} else {
revealerNav.hide();
actionBtn.setAttribute("data-open", false);
}
});
});
</script>
</body>
</html>
这是我的 CSS
body {
margin: 0;
padding: 40px 30px;
height: 100vh;
color: #fff;
background-color: #fff;
font-family: 'Gracheva';
font-size: 60px;
line-height: 1.2;
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: space-between;
box-sizing: border-box;
}
header {
position: relative;
display: flex;
justify-content: space-between;
}
.header__button {
z-index: 2;
width: 40px;
height: 40px;
border-radius: 50%;
background-color: #6046FF;
border: 0;
cursor: pointer;
position: absolute;
right: 0;
top: -18px;
margin: 20px;
outline: none;
animation-duration: 300ms;
animation-timing-function: ease;
}
.header__button[data-open="true"] {
background-color: #fff;
animation-name: scale;
}
.header__button[data-open="false"] {
transition: background-color 250ms linear;
}
@keyframes scale {
from {
transform: scale(0);
}
to {
transform: scale(100%);
}
}
.header__nav {
background-color: #6046FF;
position: fixed;
overflow: hidden;
z-index: 1;
top: 0;
left: 0;
width: 100%;
height: 100%;
box-sizing: border-box;
padding: 40px 30px;
display: flex;
flex-direction: column;
justify-content: space-between;
visibility: hidden;
clip-path: circle(var(--radius) at calc(100% - 55px) 47px);
}
.header__nav[data-active="true"] {
visibility: visible;
}
.header__menu {
padding: 0;
margin: 0;
}
.header__menu > .header__menu-item {
font-size: 12vh;
}
.header__menu > .header__menu-item:not(:last-of-type) {
margin-bottom: 0em;
}
.header__menu-item a {
letter-spacing: -4px;
font-weight: 300 !important;
color: #fff;
text-decoration: none;
}
.first {
display: flex;
flex-direction: column;
align-items: flex-start;
padding: 0px;
gap: 10px;
position: absolute;
width: 943px;
height: 252px;
left: 60px;
top: 211px;
}
.heading {
font-family: 'Gracheva';
font-size: 75px;
color: #2b2b2b;
}
.heading2 {
font-family: 'Gracheva';
font-size: 60px;
color: #2b2b2b;
}
#para {
width: 732px;
height: 46px;
font-family: 'Uncut Sans', sans-serif;
font-weight: 100;
font-size: 16px;
color: #1b1b1b;
font-weight: 300;
line-height: 146.3%;
letter-spacing: 0.04em;
color: #383838;
/* Inside auto layout */
flex: none;
order: 1;
flex-grow: 0;
}
.second {
/* Auto layout */
display: flex;
flex-direction: column;
align-items: flex-start;
padding: 0px;
gap: 53px;
position: absolute;
width: 1164px;
height: 898px;
left: 60px;
top: 748px;
}
.line {
/* Line 1 */
width: 1164px;
height: 0px;
border: 0.2px solid #000000;
/* Inside auto layout */
flex: none;
order: 0;
flex-grow: 0;
}
.works {
/* Works */
/* Auto layout */
display: flex;
flex-direction: column;
align-items: flex-start;
padding: 0px;
gap: 53px;
position: absolute;
width: 1164px;
height: 898px;
left: 60px;
top: 748px;
}
.selfelevate {
/* Auto layout */
display: flex;
flex-direction: column;
align-items: flex-start;
padding: 0px;
gap: 43px;
width: 1164px;
height: 135px;
/* Inside auto layout */
flex: none;
order: 0;
flex-grow: 0;
}
body元素的overflow属性设置为hidden,这样即使内容溢出也不会出现滚动条。要在内容溢出时显示垂直滚动条,可以去掉 overflow: hidden;来自 body 元素的 CSS 的行。
改变这个:
body {
margin: 0;
padding: 40px 30px;
height: 100vh;
color: #fff;
background-color: #fff;
font-family: 'Gracheva';
font-size: 60px;
line-height: 1.2;
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: space-between;
box-sizing: border-box;
}
对此:
body {
margin: 0;
padding: 40px 30px;
height: 100vh;
color: #fff;
background-color: #fff;
font-family: 'Gracheva';
font-size: 60px;
line-height: 1.2;
display: flex;
flex-direction: column;
justify-content: space-between;
box-sizing: border-box;
}
去除溢出:隐藏;行将允许内容溢出视口,并在需要时出现垂直滚动条。