gpt4 book ai didi

html - 可变宽度的固定侧边栏旁边的流动内容

转载 作者:太空宇宙 更新时间:2023-11-04 07:56:08 25 4
gpt4 key购买 nike

我正在尝试使用 bootstrap、一堆示例和其他在线作品来实现可切换的侧边栏(如在短形式侧边栏和长形式侧边栏之间切换)。

侧边栏在切换时改变宽度,我希望内容出现在它旁边,尽管它是“长”或“短”。

我在每个页面上使用一个部分,并希望每个部分在屏幕上显示为全宽(如 so )

$(document).ready(function() {
$("#sidebarCollapse").click(function() {
$("#sidebar").toggleClass("active");
$(this).toggleClass('active');
});
});
$("#aboutbutton").click(function() {
$('html, body').animate({
scrollTop: $("#aboutDiv").offset().top
}, 2000);
});
body {
font-family: 'Poppins', sans-serif;
background: #fafafa;
}

p {
font-family: 'Poppins', sans-serif;
font-size: 0.1em;
font-weight: 300;
line-height: 1.7em;
color: #3498db;
}

a,
a:hover,
a:focus {
color: inherit!important;
text-decoration: none!important;
transition: all 0.3s;
}

.wrapper {
display: flex;
}

#sidebar {
min-width: 250px;
max-width: 250px;
background: #2980b9;
color: #ecf0f1;
transition: all 0.3s;
height: 100%;
min-height: 100vh;
position: fixed;
}

#sidebar.active {
min-width: 80px;
max-width: 80px;
text-align: center;
}

#sidebar ul.components {
padding: 20px 0;
}

#sidebar ul p {
color: #fff;
padding: 10px;
}

#sidebar ul li a {
padding: 10px;
font-size: 1.6em;
display: block;
text-align: left;
}

#sidebar ul li a:hover {
color: #ecf0f1;
background: #3498db;
}

#sidebar .active ul li a {
padding: 20px 10px;
text-align: center;
font-size: 0.85em;
}

#sidebar .active i {
font-size: 1em;
}

#sidebar .active ul li a i {
margin-right: 0;
display: block;
font-size: 1.8em;
margin-bottom: 5px;
}

#sidebar ul li.active>a,
a[aria-expanded="true"] {
color: #ecf0f1;
background: #3498db;
}

ul ul a {
font-size: 0.9em !important;
padding-left: 30px !important;
background: #ecf0f1;
}

#sidebarCollapse {
width: 100%;
height: 80%;
background: #2980b9;
padding: 20px 0;
font-size: 1.6em;
display: block;
border: 0;
}

#sidebarCollapse-wrapper {
padding-top: 5%;
padding-bottom: 5%;
}

#sidebarCollapse span {
width: 30%;
height: 2px;
margin: 0 auto;
display: block;
background: #fff;
transition: all 0.8s cubic-bezier(0.810, -0.330, 0.345, 1.375);
}

#sidebarCollapse span:first-of-type {
/* rotate first one */
transform: rotate(45deg) translate(2px, 2px);
}

#sidebarCollapse span:nth-of-type(2) {
/* second one is not visible */
opacity: 0;
}

#sidebarCollapse span:last-of-type {
/* rotate third one */
transform: rotate(-45deg) translate(1px, -1px);
}

#sidebarCollapse.active span {
/* no rotation */
transform: none;
/* all bars are visible */
opacity: 1;
margin: 5px auto;
}

section {
min-height: 100vh;
height: 100vh;
box-sizing: border-box;
display: flex;
}
<link href="https://fonts.googleapis.com/css?family=Poppins" rel="stylesheet">
<link href="https://cdn.rawgit.com/konpa/devicon/df6431e323547add1b4cf45992913f15286456d3/devicon.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.4.3/css/mdb.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.1/js/tether.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.4.3/js/mdb.min.js"></script>




<!DOCTYPE html>
<html lang="en">

<head>

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>José Gomes - Website</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<!-- Material Design Bootstrap -->
<link rel="stylesheet" href="css/mdb.min.css">
<!-- Scrollbar Custom CSS -->
<link rel="stylesheet" href="css/jquery.mCustomScrollbar.css">
<!-- Our Custom CSS -->
<link rel="stylesheet" href="css/custom.css">

<!-- in your header -->
<link rel="stylesheet" href="https://cdn.rawgit.com/konpa/devicon/df6431e323547add1b4cf45992913f15286456d3/devicon.min.css">
</head>

<body>

<!-- Content will go here -->
<div class="wrapper">
<!-- Sidebar -->
<nav class="sidebar-nav" data-spy="affix" id="sidebar">
<!-- Sidebar Header -->
<div id="sidebarCollapse-wrapper">
<button type="button" id="sidebarCollapse" class="navbar-btn waves-effect waves-light">
<span></span>
<span></span>
<span></span>
</button>
</div>
<!-- Sidebar Links -->
<ul class="list-unstyled components">
<li class="active waves-effect waves-light" id="aboutbutton"><a href="#"><i class="fa fa-user-circle" aria-hidden="true"></i> Home</a></li>
<li class="waves-effect waves-light"><a href="#"><i class="fa fa-briefcase" aria-hidden="true"></i> Page1
</a></li>
<li class="waves-effect waves-light"><a href="#"><i class="fa fa-cogs" aria-hidden="true"></i> Page2</a></li>
<li class="waves-effect waves-light"><a href="#"><i class="fa fa-home" aria-hidden="true"></i> Page3</a></li>
</ul>
</nav>
</div>


<!-- Page Content -->
<div id="content container-fluid p-0">


<div class="d-flex flex-column">
<section class="p-3 p-lg-5 content-page" id="Section1">
Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST -
</section>
<section class="p-3 content-page">
Section 2 TEST - Section 2 TEST - Section 2 TEST - Section 2 TEST - Section 2 TEST -
</section>
<section class="p-3 content-page">
Section 3 TEST - Section 3 TEST - Section 3 TEST - Section 3 TEST</section>
</div>

</div>

</div>

这是上面代码的jsfiddle

我尝试了内容包装器并为内容类设置了边距,但它仍然将内容向下推到侧边栏下方或内部。

最佳答案

是这样的吗?

$(document).ready(function() {
$("#sidebarCollapse").click(function() {
$("#sidebar").toggleClass("active");
$(this).toggleClass('active');
});
});
$("#aboutbutton").click(function() {
$('html, body').animate({
scrollTop: $("#aboutDiv").offset().top
}, 2000);
});
body {
font-family: 'Poppins', sans-serif;
background: #fafafa;
}

p {
font-family: 'Poppins', sans-serif;
font-size: 0.1em;
font-weight: 300;
line-height: 1.7em;
color: #3498db;
}

a,
a:hover,
a:focus {
color: inherit!important;
text-decoration: none!important;
transition: all 0.3s;
}

.wrapper {
display: flex;
}

#sidebar {
min-width: 250px;
max-width: 250px;
background: #2980b9;
color: #ecf0f1;
transition: all 0.3s;
height: 100%;
min-height: 100vh;
position: fixed;
}

#sidebar.active {
min-width: 80px;
max-width: 80px;
text-align: center;
}

#sidebar ul.components {
padding: 20px 0;
}

#sidebar ul p {
color: #fff;
padding: 10px;
}

#sidebar ul li a {
padding: 10px;
font-size: 1.6em;
display: block;
text-align: left;
}

#sidebar ul li a:hover {
color: #ecf0f1;
background: #3498db;
}

#sidebar .active ul li a {
padding: 20px 10px;
text-align: center;
font-size: 0.85em;
}

#sidebar .active i {
font-size: 1em;
}

#sidebar .active ul li a i {
margin-right: 0;
display: block;
font-size: 1.8em;
margin-bottom: 5px;
}

#sidebar ul li.active>a,
a[aria-expanded="true"] {
color: #ecf0f1;
background: #3498db;
}

ul ul a {
font-size: 0.9em !important;
padding-left: 30px !important;
background: #ecf0f1;
}

#sidebarCollapse {
width: 100%;
height: 80%;
background: #2980b9;
padding: 20px 0;
font-size: 1.6em;
display: block;
border: 0;
}

#sidebarCollapse-wrapper {
padding-top: 5%;
padding-bottom: 5%;
}

#sidebarCollapse span {
width: 30%;
height: 2px;
margin: 0 auto;
display: block;
background: #fff;
transition: all 0.8s cubic-bezier(0.810, -0.330, 0.345, 1.375);
}

#sidebarCollapse span:first-of-type {
/* rotate first one */
transform: rotate(45deg) translate(2px, 2px);
}

#sidebarCollapse span:nth-of-type(2) {
/* second one is not visible */
opacity: 0;
}

#sidebarCollapse span:last-of-type {
/* rotate third one */
transform: rotate(-45deg) translate(1px, -1px);
}

#sidebarCollapse.active span {
/* no rotation */
transform: none;
/* all bars are visible */
opacity: 1;
margin: 5px auto;
}

.sidebar-nav.active + div#content{
margin-left:80px;
}
.sidebar-nav:not(.active) + div#content{
margin-left:250px;
}


section {
min-height: 100vh;
height: 100vh;
box-sizing: border-box;
display: flex;
}
<link href="https://fonts.googleapis.com/css?family=Poppins" rel="stylesheet">
<link href="https://cdn.rawgit.com/konpa/devicon/df6431e323547add1b4cf45992913f15286456d3/devicon.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.4.3/css/mdb.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.1/js/tether.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.4.3/js/mdb.min.js"></script>




<!DOCTYPE html>
<html lang="en">

<head>

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>José Gomes - Website</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<!-- Material Design Bootstrap -->
<link rel="stylesheet" href="css/mdb.min.css">
<!-- Scrollbar Custom CSS -->
<link rel="stylesheet" href="css/jquery.mCustomScrollbar.css">
<!-- Our Custom CSS -->
<link rel="stylesheet" href="css/custom.css">

<!-- in your header -->
<link rel="stylesheet" href="https://cdn.rawgit.com/konpa/devicon/df6431e323547add1b4cf45992913f15286456d3/devicon.min.css">
</head>

<body>

<!-- Content will go here -->
<!-- Sidebar -->
<nav class="sidebar-nav" data-spy="affix" id="sidebar">
<!-- Sidebar Header -->
<div id="sidebarCollapse-wrapper">
<button type="button" id="sidebarCollapse" class="navbar-btn waves-effect waves-light">
<span></span>
<span></span>
<span></span>
</button>
</div>
<!-- Sidebar Links -->
<ul class="list-unstyled components">
<li class="active waves-effect waves-light" id="aboutbutton"><a href="#"><i class="fa fa-user-circle" aria-hidden="true"></i> Home</a></li>
<li class="waves-effect waves-light"><a href="#"><i class="fa fa-briefcase" aria-hidden="true"></i> Page1
</a></li>
<li class="waves-effect waves-light"><a href="#"><i class="fa fa-cogs" aria-hidden="true"></i> Page2</a></li>
<li class="waves-effect waves-light"><a href="#"><i class="fa fa-home" aria-hidden="true"></i> Page3</a></li>
</ul>
</nav>


<!-- Page Content -->
<div id="content" class="p-0">


<div class="d-flex flex-column">
<section class="p-3 p-lg-5 content-page" id="Section1">
Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST - Section 1 TEST -
</section>
<section class="p-3 content-page">
Section 2 TEST - Section 2 TEST - Section 2 TEST - Section 2 TEST - Section 2 TEST -
</section>
<section class="p-3 content-page">
Section 3 TEST - Section 3 TEST - Section 3 TEST - Section 3 TEST</section>
</div>

</div>

</div>

关于html - 可变宽度的固定侧边栏旁边的流动内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47314904/

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