在CSS中移动侧边栏

问题描述 投票:1回答:1

.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">

我想将此侧边栏移到最左边和最上面。

我尝试删除填充,但是没有填充,所以它什么也没做。

如何将侧栏移到最左侧和最顶部?

html css sidebar
1个回答
1
投票

由于您正在使用position: fixed。只需在导航侧边栏容器中将topleft css属性设置为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">
© www.soinside.com 2019 - 2024. All rights reserved.