我正在尝试制作一个 Bootstrap 5 手风琴,这样我就可以组织我的内容,但是在我的网站上,手风琴项目总是打开的,当点击手风琴项目时,手风琴项目会进行一些移动,然后返回到它的原始状态,但是手风琴项目顶部的手风琴文本/正文,再次单击时,文本/正文返回中心并显示它不应该显示的位置。
这是它的一个片段:
$(document).ready(function () {
// Hamburger
$(".burger-container").click(function () {
$(".nav-menu").toggleClass("menu-opened");
$("body").toggleClass("unscrollable");
});
// Dark-Light switcher
$("body").toggleClass("light", localStorage.toggled == "light");
document.getElementById("checkBox").addEventListener("click", darkLight);
function darkLight() {
if (localStorage.toggled != "light") {
$("body").toggleClass("light", true);
localStorage.toggled = "light";
} else {
$("body").toggleClass("light", false);
localStorage.toggled = "";
}
}
if ($("body").hasClass("light")) {
$("#checkBox").prop("checked", true);
} else {
$("#checkBox").prop("checked", false);
}
$(function () {
$(".info-sections").addClass("default");
$(".info-sections").on("click", function () {
var e = $(".collapse > .info-sections");
if (e.hasClass("expand")) {
e.removeClass("expand");
$(this).addClass("expand");
} else {
$(this).addClass("expand");
}
});
});
});
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Dark colors */
:root {
--white-color: #d9d9d9;
--black-color: #0d0d0d;
--text-color: #d9d9d9;
--grey-color-1: #595959;
--grey-color-2: #666666;
--body-bg-color: #262626;
--text-hover-color: #a6a6a6;
}
/* Light colors */
:root .light {
--white-color: #a6a8ab;
--black-color: #e6e6e6;
--text-color: #030302;
--grey-color-1: #c4c4c4;
--grey-color-2: #b1b1b1;
--body-bg-color: #f5f5f4;
--text-hover-color: #797274;
}
/* ======== MAIN CSS ======== */
html {
width: 100%;
height: 100%;
}
body {
width: 100%;
height: 100%;
background-color: var(--body-bg-color) !important;
position: relative;
overflow: hidden;
font-family: "Nunito", sans-serif;
color: var(--text-color);
}
main {
background-color: var(--body-bg-color);
}
.wrapper {
height: 100vh;
overflow-y: auto;
overflow-x: hidden;
perspective: 10px;
}
.top {
z-index: 999;
position: sticky;
top: 0;
left: 0;
width: 100%;
transition: 0.5s ease;
}
nav {
position: sticky;
top: 0;
z-index: 999;
width: 100vw;
height: 3.5rem;
background-color: var(--black-color);
}
.unscrollable {
overflow: hidden;
}
.active {
text-decoration: underline;
}
/* ======= PARALLAX ======= */
.parallax {
position: relative;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
transform-style: preserve-3d;
z-index: -1;
}
.background {
transform: translateZ(-10px) scale(2);
-webkit-user-drag: none;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
.foreground {
transform: translateZ(-5px) scale(1.5);
-webkit-user-drag: none;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
.background,
.foreground {
position: absolute;
height: 100%;
width: 100%;
object-fit: cover;
z-index: -1;
}
.hero-text {
text-align: center;
color: var(--text-color);
position: absolute;
top: 50%;
left: 50%;
min-width: 14rem;
transform: translate(-50%, -50%);
}
.hero-text > h1 {
font-size: 3rem;
}
.hero-text > p {
font-size: 1rem;
}
/* ======== HAMBURGER ======== */
.burger-container {
position: absolute;
right: 1rem;
top: 0.1rem;
display: inline-block;
height: 50px;
width: 50px;
transform: rotate(0deg);
transition: all 0.3s cubic-bezier(0.4, 0.01, 0.165, 0.99);
user-select: none;
z-index: 999;
-webkit-tap-highlight-color: transparent;
}
#burger {
position: relative;
top: 50%;
width: 18px;
height: 8px;
display: block;
margin: -4px auto 0;
}
.bar {
position: relative;
width: 100%;
height: 1px;
display: block;
background: var(--white-color);
transition: all 0.3s cubic-bezier(0.4, 0.01, 0.165, 0.99);
transition-delay: 0s;
}
.topBar {
transform: translateY(0px) rotate(0deg);
}
.btmBar {
transform: translateY(6px) rotate(0deg);
}
.menu {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
padding: 0;
background: var(--black-color);
height: 100%;
list-style: none;
}
.menu-item {
transform: translateY(-200px);
transition: transform 0.5s cubic-bezier(0.4, 0.01, 0.165, 1);
}
.menu-item a {
display: block;
position: relative;
color: var(--text-color);
font-family: "Roboto", sans-serif;
font-weight: 300;
text-decoration: none;
font-size: 1.3rem;
line-height: 2.35;
border-bottom: 1px solid var(--body-bg-color);
width: 100%;
}
.menu-item a:hover {
color: var(--text-hover-color);
text-decoration: none;
}
.nav-menu {
height: 3.5rem;
transition: height 0.4s;
}
.nav-menu.menu-opened {
transition: height 0.4s;
position: absolute;
top: 0;
height: 100vh;
width: 100vw;
}
.nav-menu.menu-opened .burger-container {
transform: rotate(90deg);
}
.nav-menu.menu-opened .burger-container #burger .bar {
transition: all 0.4s cubic-bezier(0.4, 0.01, 0.165, 0.99);
transition-delay: 0.2s;
}
.nav-menu.menu-opened .burger-container #burger .bar.topBar {
transform: translateY(4px) rotate(45deg);
}
.nav-menu.menu-opened .burger-container #burger .bar.btmBar {
transform: translateY(3px) rotate(-45deg);
}
.nav-menu.menu-opened ul.menu li.menu-item {
transform: scale(1) translateY(0px);
}
/* ======== Dark Light switcher ====== */
.switcher > span {
color: var(--text-color);
padding: 0 0.5rem;
font-size: 1.3rem;
}
.switcher {
display: flex;
align-items: center;
}
.toggler-container {
display: block;
margin-top: 1rem;
transform: translateY(-200px);
transition: transform 0.5s cubic-bezier(0.4, 0.01, 0.165, 1);
}
.nav-menu.menu-opened ul.menu li.toggler-container {
transform: scale(1) translateY(0px);
}
.switch {
position: relative;
align-self: center;
display: inline-block;
width: 3.2rem;
height: 1.5rem;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
cursor: pointer;
background-color: #808080;
-webkit-transition: 0.4s;
transition: 0.4s;
border-radius: 1rem;
}
.slider:before {
position: absolute;
left: 4px;
bottom: 4px;
content: "";
height: 1rem;
width: 1rem;
background-color: rgb(207, 207, 207);
-webkit-transition: 0.4s;
transition: 0.4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #808080;
}
input:checked + .slider:before {
-webkit-transform: translateX(1.7rem);
-ms-transform: translateX(1.7rem);
transform: translateX(1.7rem);
}
/* ======== CONTENT ======= */
.content {
color: var(--text-color);
}
.content h2 {
font-size: 1.4rem;
font-family: "Roboto", sans-serif;
}
.content p {
font-size: 1.1rem;
font-family: "Nunito", sans-serif;
}
.collapse {
display: block !important;
}
.info-sections {
width: 100%;
margin-top: 2rem;
}
.info-sections h3 {
font-size: 1.3rem;
}
.info-sections span {
display: none;
}
/* ======== FOOTER ======== */
footer {
padding: 4rem 0 6rem 0;
background-color: var(--grey-color-1);
position: sticky;
bottom: 0;
z-index: -2;
}
footer ul {
margin: 0;
padding: 0;
list-style: none;
text-align: center;
font-size: 1.3rem;
}
footer ul a {
color: var(--text-color);
text-decoration: none;
}
footer ul li {
display: block;
padding: 0.25rem 0;
}
footer ul a:hover {
color: var(--text-hover-color);
}
footer hr {
color: var(--text-hover-color);
max-width: 13rem;
margin: 1.5rem auto;
}
footer .copyright {
margin-top: 1rem;
text-align: center;
font-size: 0.75rem;
color: var(--text-hover-color);
}
/* ======== MEDIA QUERIES ======== */
/* TABLET */
@media only screen and (min-width: 600px) {
/* ======= FOOTER ======= */
footer ul {
font-size: 1.1rem;
}
footer ul li {
display: inline-block;
padding: 0 0.2rem;
}
footer hr {
max-width: 35rem;
}
}
/* DESKTOP */
@media only screen and (min-width: 769px) {
/* ======== MAIN CSS ======== */
.top {
overflow: hidden;
}
.hero-text {
position: absolute;
top: 40%;
left: 30%;
max-width: 20rem;
}
.hero-text > h1 {
font-size: 3.5rem;
}
.hero-text > p {
font-size: 1.2rem;
}
/* ======= Scrollbar ======== */
::-webkit-scrollbar {
width: 7px;
background: transparent;
}
::-webkit-scrollbar-thumb {
border-radius: 100px;
background: rgb(109, 109, 109);
}
::-webkit-scrollbar-thumb:hover {
background-color: rgb(148, 148, 148);
}
/* ======== HAMBURGER ======== */
nav {
width: 100%;
background-color: var(--black-color);
backdrop-filter: none;
}
.nav-menu {
transition: all 0.3s ease-in, 0.5s ease-in;
transition-delay: 0.25s;
width: 100%;
height: 3.5rem;
display: flex;
align-items: center;
}
.nav-menu.menu-opened {
height: 100%;
}
.burger-container {
display: none;
}
.menu-item {
transform: scale(1) translateY(0px);
display: inline;
margin-right: 0.8rem;
border-bottom: 0;
margin-top: 0;
}
.menu {
flex-direction: row;
position: absolute;
top: 0;
margin: 0 0 0 1.5rem;
height: 3.5rem;
width: 100%;
}
.menu-item a {
display: inline;
border: none;
font-size: 1rem;
transition: all 0.15s cubic-bezier(0.54, 0.12, 0.54, 0.94);
}
.flex-filler {
flex: 1 1 auto;
}
/* ======== Dark-light switcher ======== */
.toggler-container {
display: block;
margin: 0 2.5rem 0 0;
transform: scale(1) translateY(0px);
}
.switcher > span {
font-size: 1.2rem;
padding: 0 0.4rem;
}
.switch {
width: 2.5rem;
height: 1.3rem;
}
.slider:before {
height: 0.8rem;
width: 0.8rem;
left: 4px;
bottom: 4px;
}
input:checked + .slider:before {
-webkit-transform: translateX(1.2rem);
-ms-transform: translateX(1.2rem);
transform: translateX(1.2rem);
}
/* ======== CONTENT ========*/
.content h2 {
font-size: 1.5rem;
}
.content p {
font-size: 1.15rem;
}
.collapse:not(.show) {
display: flex !important;
}
.collapse {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
align-content: center;
position: relative;
min-height: 50vh;
transition: all 200ms ease-in-out 50ms;
}
.collapse .info-sections {
margin-left: 5px;
margin-right: 5px;
border-radius: 3px;
background: var(--grey-color-1);
transition: all 200ms ease-in-out 50ms;
font-weight: 500;
cursor: pointer;
position: relative;
}
.collapse .default {
height: 29rem;
width: 50vw;
color: rgba(0, 0, 0, 0);
overflow: hidden;
}
.collapse .expand {
height: 29rem;
width: 100vw;
background: var(--grey-color-2);
color: var(--text-color-1);
padding: 1rem;
}
.info-sections h3 {
color: var(--text-color);
font-size: 1rem;
}
.info-sections span {
color: var(--text-color);
display: block;
font-size: 1.3rem;
}
.info-top {
margin: 1rem auto;
display: flex;
justify-content: space-evenly;
max-width: 11rem;
}
.info-sections p {
font-size: 1rem;
}
.info-sections.expand span {
display: none;
}
.info-sections.expand h3 {
font-size: 1.2rem;
}
}
/* MEDIUM-DESKTOP */
@media only screen and (min-width: 991px) {
.collapse .default {
height: 26rem;
}
.collapse .expand {
height: 26rem;
}
.info-sections h3 {
font-size: 1.1rem;
}
.info-sections span {
font-size: 1.5rem;
position: absolute;
top: 1rem;
right: 1rem;
}
.info-top {
margin: 1rem;
display: block;
max-width: 100%;
}
.info-sections p {
font-size: 1.1rem;
}
.info-sections.expand h3 {
font-size: 1.3rem;
}
}
/* XL-DESKTOP */
@media only screen and (min-width: 1200px) {
/* ======= HAMBURGER ======= */
.menu-item {
margin-right: 1.3rem;
}
.menu-item a {
font-size: 1.1rem;
}
/* ======= CONTENT ======= */
.info-sections h3 {
font-size: 1.2rem;
margin-top: 1rem;
}
.info-sections span {
font-size: 1.6rem;
top: 1rem;
right: 1rem;
}
.collapse .default {
height: 23rem;
}
.collapse .expand {
height: 23rem;
}
/* ======= FOOTER ======= */
footer ul {
font-size: 1.2rem;
}
footer ul li {
padding: 0 0.4rem;
}
footer hr {
max-width: 40rem;
}
}
/* Custom style */
.accordion-button::after {
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='%23333' xmlns='http://www.w3.org/2000/svg'%3e%3cpath fill-rule='evenodd' d='M8 0a1 1 0 0 1 1 1v6h6a1 1 0 1 1 0 2H9v6a1 1 0 1 1-2 0V9H1a1 1 0 0 1 0-2h6V1a1 1 0 0 1 1-1z' clip-rule='evenodd'/%3e%3c/svg%3e");
transform: scale(0.7) !important;
}
.accordion-button:not(.collapsed)::after {
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='%23333' xmlns='http://www.w3.org/2000/svg'%3e%3cpath fill-rule='evenodd' d='M0 8a1 1 0 0 1 1-1h14a1 1 0 1 1 0 2H1a1 1 0 0 1-1-1z' clip-rule='evenodd'/%3e%3c/svg%3e");
}
<!DOCTYPE html>
<html lang="sv">
<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" />
<title>Lagar och säkerhet | Webbhotell</title>
<link rel="stylesheet" href="../css/style.css" />
<link
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;0,1000;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900;1,1000&display=swap"
rel="stylesheet"
/>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
/>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0"
/>
<script defer src="../js/script.js"></script>
</head>
<body>
<div class="top">
<nav>
<div class="nav-menu">
<div class="burger-container">
<div id="burger">
<div class="bar topBar"></div>
<div class="bar btmBar"></div>
</div>
</div>
<ul class="menu">
<li class="menu-item"><a href="../index.html">Hem</a></li>
<li class="menu-item"><a href="losenord.html">Lösenord</a></li>
<li class="menu-item">
<a href="keylogger.html">Keylogger</a>
</li>
<li class="menu-item">
<a href="statlig-kontroll.html">Statlig kontroll</a>
</li>
<li class="menu-item">
<a href="tredjepartskod.html">Tredjepartskod</a>
</li>
<li class="menu-item">
<a href="#">Webbhotell</a>
</li>
<li class="flex-filler"></li>
<li class="toggler-container">
<div class="switcher">
<span class="material-symbols-outlined"> dark_mode </span>
<label class="switch">
<input type="checkbox" id="checkBox" />
<span class="slider"></span>
</label>
<span class="material-symbols-outlined"> light_mode </span>
</div>
</li>
</ul>
</div>
</nav>
</div>
<div class="wrapper" id="wrapper">
<header class="parallax">
<img
src="https://cdn.imgpaste.net/2022/10/10/Kem93m.png"
class="background"
alt="background"
/>
<img
src="https://cdn.imgpaste.net/2022/10/10/KemO9N.png"
class="foreground"
alt="foreground"
/>
<div class="hero-text">
<h1>Webbhotell</h1>
<p>
Vad är ett webbhotell och vad ska man tänka på när man väljer webbhotell som utvecklare?
</p>
</div>
</header>
<main>
<div class="content container text-center py-5">
<section class="row">
<h2>Webbhotell</h2>
<p>
Ett webbhotell är en extern tjänst som tillhandahåller infrastruktur och
lagringsutrymme för att göra en webbplats tillgänglig på internet. När man väljer ett
webbhotell är det viktigt att ha säkerheten i åtanke.
</p>
</section>
</div>
<div class="container">
<div class="m-4">
<div class="accordion" id="myAccordion">
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<button
type="button"
class="accordion-button collapsed"
data-bs-toggle="collapse"
data-bs-target="#collapseOne"
>
1. What is HTML?
</button>
</h2>
<div
id="collapseOne"
class="accordion-collapse collapse"
data-bs-parent="#myAccordion"
>
<div class="card-body">
<p>
HTML stands for HyperText Markup Language. HTML is the standard markup
language for describing the structure of web pages.
<a href="https://www.tutorialrepublic.com/html-tutorial/" target="_blank"
>Learn more.</a
>
</p>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingTwo">
<button
type="button"
class="accordion-button"
data-bs-toggle="collapse"
data-bs-target="#collapseTwo"
>
2. What is Bootstrap?
</button>
</h2>
<div
id="collapseTwo"
class="accordion-collapse collapse show"
data-bs-parent="#myAccordion"
>
<div class="card-body">
<p>
Bootstrap is a sleek, intuitive, and powerful front-end framework for faster
and easier web development. It is a collection of CSS and HTML conventions.
<a
href="https://www.tutorialrepublic.com/twitter-bootstrap-tutorial/"
target="_blank"
>Learn more.</a
>
</p>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingThree">
<button
type="button"
class="accordion-button collapsed"
data-bs-toggle="collapse"
data-bs-target="#collapseThree"
>
3. What is CSS?
</button>
</h2>
<div
id="collapseThree"
class="accordion-collapse collapse"
data-bs-parent="#myAccordion"
>
<div class="card-body">
<p>
CSS stands for Cascading Style Sheet. CSS allows you to specify various style
properties for a given HTML element such as colors, backgrounds, fonts etc.
<a href="https://www.tutorialrepublic.com/css-tutorial/" target="_blank"
>Learn more.</a
>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<footer>
<ul class="list">
<li>
<a href="../index.html">Hem</a>
</li>
<li>
<a href="losenord.html">Lösenord</a>
</li>
<li>
<a href="keylogger.html">Keylogger</a>
</li>
<li>
<a href="statlig-kontroll.html">Statlig kontroll</a>
</li>
<li>
<a href="tredjepartskod.html">Tredjepartskod</a>
</li>
<li>
<a href="#" class="active">Webbhotell</a>
</li>
</ul>
<hr />
<p class="copyright">Copyright © All rights reserved by Vincent Cornelius</p>
</footer>
</div>
</body>
</html>