【问题标题】:My sidebar pushes my whole website down我的侧边栏将我的整个网站推倒
【发布时间】:2013-06-24 15:03:10
【问题描述】:

所以我得到了这个网站,所有内容都完美排列,页眉、正文页脚等。上周我尝试添加一个侧边栏,我意识到它把我的主要内容推到了下面。 很多问题是,我怎样才能使侧边栏的边距/高度独立于我的主要内容? (下面贴出 CSS 代码)

演示: 编辑:http://oldtimesdaily.tumblr.com/ 我的 tumblr 与代码。现在的样子。绝对位置有效,主要内容回到顶部。但是现在我侧边栏的所有内容都卡在一起了,我猜绝对定位会删除所有边距?我应该用什么来代替侧边栏上的不同内容?

#quote { /*style for quote division*/
    position:relative;
    width:375px;
    height:70px;
    border:1px solid black;
    font-family:sans-serif;
    font-size:95%;
    padding:3px;
    background-color:lightyellow;
}
#auth { /*style for quote author, if any*/
    position:absolute;
    bottom:3px;
    right:10px;
}
#sidebar {           /*editable*/
    background: url('http://s10.postimg.org/uag5u79d1/vline.png') repeat-y left center;
    background-color: white;
    width: 260px;
    position: relative;
    top: 700px;
    left: 55%;
}
#sidebar .sTitle {
    padding: 0 0 10px 0;
    position: relative;
    margin: 0px 20px 0px;
    color: #222;
    font-size: 15px;
    line-height: 1;
    font-family: QuicksandBold, Helvetica, Arial, sans-serif;
    font-weight: bold;
    letter-spacing: 3px;
    text-decoration: none;
    border-bottom: 0px;
}
#sidebar .Categories {
    font-size: 11px;
    text-align: center;
    padding: 3px 5px;
    margin: 50px;
}

【问题讨论】:

  • 你能添加一个演示链接吗?使用 jsfiddle.net 或 codepen.io

标签: html css sidebar margins


【解决方案1】:

position: absolute;

将使侧边栏独立于页面的其余部分

【讨论】:

  • 成功了!但是我之前没用过绝对定位,怎么定位东西呢?我的侧边栏现在有 2 个 div,一个用于 Quotes,一个用于 Category。当我使用 relative 时,它​​们被放置在彼此之上。当我更改为绝对时,它们都被挤在一个空间中。
  • barelyfitz.com/screencast/html-training/css/positioning 尝试仅将position: absolute 用于您希望独立于其余元素的 div。
  • 真正的问题是它把主要内容往下推。我不希望边栏的边距和高度影响我的主要内容。我现在注意到,使用绝对位置时,当我缩小或放大时它也会变得混乱。有没有可能的方法来保持相对定位,同时也避免我的侧边栏的内容弄乱我网站的其余部分?
  • 只有实际的侧边栏包装应该有position:absolute;里面的其他东西不应该;否则它们也将独立于包装器内的其他东西
  • 哦,解决了!你能检查一下吗? oldtimesdaily.tumblr.com 你的解决方案解决了这一切。但是当我放大很多时,侧边栏会四处移动。这对于分辨率较低的移动设备来说会是个问题吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-22
  • 1970-01-01
相关资源
最近更新 更多