我正在为我的页面创建滑入/滑出侧边栏,但我不能这样做,除非我的包装器 DIV 覆盖了主体宽度和高度的整个长度,而它没有,我也没有知道为什么。
我不完全确定要包含哪些代码,所以我在这里包含了一些我认为是的代码。如果您需要预览所有代码,我在下面提供了一个 Pastebin 链接。
问题图片 - http://i.imgur.com/wWNAeBP.png 如果需要,请在此处查看所有代码:
HTML - http://pastebin.com/TQT6Xc4z CSS - http://pastebin.com/mS5Gh56x
提前致谢。
HTML:
<div id="wrapper">
<div id="sidebar">
<nav id="nav">
<h3 id="welcometext">Welcome To<br>Lakeside Books</h3>
<div id="searchbar">
<form action="http://www.example.com/search.php">
<input type="text" name="search" placeholder=" Book Search" class="searchstyle"/>
</form>
</div>
<ul>
<li style="background-color: #333">
<a href="1Index.html" class="link">
<span style="color: #ed786a">Home</span>
</a>
</li>
<li>
<a href="2Catgeories.html" class="link">
Categories
</a>
</li>
<li>
<a href="http://example.com" class="link">
Bestsellers
</a>
</li>
<li>
<a href="http://example.com" class="link">
Find Us
</a>
</li>
<li>
<a href="http://example.com" class="link">
Contact
</a>
</li>
</ul>
</nav>
</div>
CSS:
html, body { /* ### */
margin:0;
padding:0;
height:100%;
width:100%;
}
body {
background-color: #fdfdfd;
font-family: Arial, "Open Sans", sans-serif-light, sans-serif, "Segoe UI";
}
#wrapper {
width: 100%;
height: 100%;
margin:0 0 0 20%; /* ### */
}
#sidebar {
background-color: #212528;
position: fixed;
width: 20%;
height: 100%;
top: 0;
left: 0;
overflow: hidden;
text-shadow: 0.1em 0.1em 0 rgba(0, 0, 0, 0.1);
}
在尝试创建打开和关闭侧边栏时,我真的一直坚持这个问题,所以非常感谢您的帮助!
最佳答案
尝试将您的包装器 css 更改为
#wrapper {
width: 100%;
height: auto;
overflow:auto;
margin:0 0 0 20%; /* ### */
}
关于javascript - 包装器不随内容扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29811934/