在CSS中移动侧边栏



.wrapper{
width: 1024px;
margin: auto;
}
.left-sidebar {
z-index: 9999;
width: 200px;
background: #303030;
height:100%;
overflow: auto;
}
#sidebar {
min-width: 200px;
min-height: 200px;
background: #303030;
color: #fff;
position:fixed;
transition: all 0.3s;
z-index:999;
height:100%;
width: 25%;
float: left;
}
<div class="wrapper">
<div class="left-sidebar">
<nav id="sidebar">

我想把这个侧边栏移到最左边和最上面。

我试着去掉填充物,但没有填充物,所以什么也没做。

如何将侧栏移动到最左边和最上面?

因为您使用的是position: fixed。只需在导航侧边栏容器中将topleftcss属性设置为0。

.wrapper {
width: 1024px;
margin: auto;
}
.left-sidebar {
z-index: 9999;
width: 200px;
background: #303030;
height:100%;
overflow: auto;
}
#sidebar {
min-width: 200px;
min-height: 200px;
background: #303030;
color: #fff;
position: fixed;
top: 0;
left: 0;
transition: all 0.3s;
z-index: 999;
min-height: 100%;
width: 25%;
float: left;
}
<div class="wrapper">
<div class="left-sidebar">
<nav id="sidebar">