gpt4 book ai didi

html - 单击鼠标将侧边栏滑入 View

转载 作者:太空宇宙 更新时间:2023-11-04 11:34:34 24 4
gpt4 key购买 nike

我正在尝试创建自己的可切换侧边栏。我已经完成了这个片段(按屏幕中的棕色来切换):

我希望背景有整个屏幕的宽度,所以当我点击棕色部分时,背景是棕色的,而不是白色的。

$(document).ready(function() {
$("#rest-of-the-page").click(
function() {
$("#sidebar").toggleClass("hidden");

}
);
});
html,
body {
height: 100%;
margin: 0;
}
.container {
background-size: cover;
background-repeat: no-repeat;
background-position: center;
height: 100%;
}
#sidebar {
position: absolute;
height: 100%;
width: 15%;
background-color: rgba(27, 26, 26, .8);
transition: all .2s linear 0s;
}
.hidden {
margin-left: -30%;
transition: all .2s linear 0s;
}
#logo-container {
min-height: 150px;
height: 30%;
width: 100%;
border-bottom: 3px solid #1A1A1A;
}
#logo {
width: 100%;
height: 100%;
background: url(Images/logo.png) no-repeat center center;
background-size: 75% auto;
}
.menu-options-container {
height: 50%;
width: 100%;
}
#menu-options-ul {
width: 100%;
list-style-type: none;
padding: 0;
margin: 0;
text-align: center;
height: 70%;
}
#menu-options-ul li {
width: 100%;
border-top: 2px solid #373737;
border-bottom: 2px solid #1A1A1A;
height: 3em;
margin-top: 0;
color: #999;
display: table;
}
#menu-options-ul li:hover {
background: rgba(255, 255, 255, 0.2);
}
#menu-options-ul li p {
vertical-align: middle;
display: table-cell;
width: 100%;
}
#menu-options-ul li p:hover {
color: #fff;
}
#rest-of-the-page {
position: absolute;
top: 0;
left: 15%;
width: 85%;
height: 100%;
transition: all .2s linear 0s;
cursor: pointer;
background-color: antiquewhite
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="container">
<div id="sidebar">
<div id="logo-container">
<div id="logo"></div>
</div>
<div class="menu-options-container">
<ul id="menu-options-ul">
<li>
<p>Hola</p>
</li>
<li>
<p>Adios</p>
</li>
<li>
<p>Buenas</p>
</li>
</ul>
</div>
</div>
<div id="rest-of-the-page"></div>
</div>

最佳答案

只需添加一个带有 left:0 的类,将其命名为“fullpage

#rest-of-the-page 的宽度设置为 100%

#rest-of-the-page{
position:absolute;
top:0;
width:100%;
left:15%;
height:100%;
transition: all .2s linear 0s;
cursor:pointer;
background-color:antiquewhite
}
#rest-of-the-page.fullpage{
left:0;
}

更新:另一件事使 margin-left :-15% 而不是 -30% 因为侧边栏的宽度只有 15%

.hidden{ 
margin-left: -15%;
transition: all .2s linear 0s; //you don't need this
}

添加隐藏到正文的溢出

html, body {
height: 100%;
margin:0;
overflow-x:hidden;
}

toggleClass fullpage for #rest-of-the-page

https://jsfiddle.net/yggt4s83/2/

关于html - 单击鼠标将侧边栏滑入 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31833807/

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