html - 固定 div 在 y 位置但不在 x 位置取决于其他 div

标签 html css sidebar

我固定了侧边栏和导航栏,我想知道是否可以根据每篇文章的宽度调整侧边栏的 x 位置。

HTML:

<div id="sidebar">
</div>

CSS:

div#sidebar{
    width: 200px;
    height: 100%;
    position: fixed;
    margin-top: 50px;
    float: left;
}

最佳答案

在文章中设置侧边栏怎么样?

jsfiddle

HTML:

<div id="article">article
    <div id="sidebar">sidevar
    </div>
</div>

CSS:

#article
{
    margin-left: 30px;
    background: white;
    width: 200px;
    height: 300px;

}

#sidebar
{
    position: fixed;

    top: 0px;
    width: 30px;
    height: 100%;
    background: blue;
    color: white;
}

关于html - 固定 div 在 y 位置但不在 x 位置取决于其他 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27728347/

相关文章:

jquery 根据标题在页面加载时隐藏图像

CSS 沿边界对齐元素,而不是基线或顶部

html - 全屏背景htm5手机

html - 垂直对齐 div 但保持顺序一致

html - 表格突出显示和轮廓大小

c# - 如何将启动时窗口的位置定位到用户屏幕的右侧?

python-sphinx - 如何在每个页面的侧边栏中包含目录树

html - 像谷歌一样设置侧边栏

jquery - 使用音频标签设置循环之间的延迟

html - 有人能告诉我为什么 a :hover doesn't work?