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

我想将此侧边栏移至最左侧和顶部。

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

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


斯蒂芬大帝
浏览 26回答 1
1回答

忽然笑

既然你正在使用position: fixed. 只需在导航侧边栏容器中将top和css 属性设置为 0 即可。left.wrapper {&nbsp; &nbsp; width: 1024px;&nbsp; &nbsp; margin: auto;}.left-sidebar {&nbsp; &nbsp; z-index: 9999;&nbsp; &nbsp; width: 200px;&nbsp; &nbsp; background: #303030;&nbsp; &nbsp; height:100%;&nbsp; &nbsp; overflow: auto;}#sidebar {&nbsp; &nbsp; min-width: 200px;&nbsp; &nbsp; min-height: 200px;&nbsp; &nbsp; background: #303030;&nbsp; &nbsp; color: #fff;&nbsp; &nbsp; position: fixed;&nbsp; &nbsp; top: 0;&nbsp; &nbsp; left: 0;&nbsp; &nbsp; transition: all 0.3s;&nbsp; &nbsp; z-index: 999;&nbsp; &nbsp; min-height: 100%;&nbsp; &nbsp; width: 25%;&nbsp; &nbsp; float: left;}<div class="wrapper">&nbsp; <div class="left-sidebar">&nbsp; &nbsp; <nav id="sidebar">
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5