侧边栏问题 - 暂时的位置:固定的侧边栏不会停留在它的位置..代码和&包括图像

时间:2012-03-16 19:28:55

标签: css position

这是我第一次尝试和自己设计/编码网站,到目前为止我学到了很多东西,因为我正在进行最后的修改,我似乎无法纠正这最后一个问题。 理想情况下,侧边栏应位于最右侧的固定位置,水平放置,左侧为导航栏。目前,它位于左侧标题/导航附近的主要内容之上。

enter image description here

header {
    background: none;
    float: left;
    margin-top: 123px;
    margin-left: 22px;
    position: fixed;
    width: 158px; 
}
#main {
    float: left;
    margin-left: 300px;
    margin-top: 310px;
}
#sidebar {
    border-top: 1px solid #202020;
    float: right;
    height: 100%;
    margin-left: 252px;
    margin-top: 295px;
    padding-top: 25px;
    position: fixed;
    width: 158px;
}

    <header>
        <div id="logo">
            <a href="#"><img src="img/logo.png" alt="whskytngfxtrt logo" height="139" width="158" /></a>
        </div><!-- end logo -->
        <nav>
            <ul>
                <li id="blog"><a href="#">BLOG</a></li>
                <li id="work"><a href="#">WORK</a></li>
                <li id="about"><a href="#">ABOUT</a></li>
                <li id="contact"><a href="#">CONTACT</a></li>
            </ul>
        </nav><!-- end nav -->
    </header><!-- end header -->

    <div id="main">
        <article>
            <h1><a href="#">Clever Headline</a></h1>
            <h2 class="postinfo">
            <ul>
                <li>Posted by <a href="#">Alex Chennault</a></li>
                <li>1st March 2012</li>
                <li>tags: <a href="#">cool</a>, <a href="#">awesome</a></li>
            </ul>
            </h2>
            <p>One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. "What's happened to me? " he thought. It wasn't a dream. His room, a proper human room although a little too small, lay peacefully between its four familiar walls. A collection of textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture that he had recently cut out of an illustrated magazine and housed in a nice, gilded frame. It showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards the viewer.</p>
        </article><!-- end article -->
    </div><!-- end main -->

    <div id="sidebar">
        <section id="dictionary">
            <h3><b>hwis-kee tang-goh foks-trot</b></h3>
            <h4><p><i>noun</i> 1. the best damn creative studio there ever was</p></h4>
        </section><!-- end dictionary -->

        <section id="twitter">
            <h3><a href="http://www.twitter.com/whskytngfxtrt">@whskytngfxtrt</a></h3>
            <h4><ul>
                <li><a href="#">sometimes i just really love the internet</a></li>
                <li><a href="#">sometimes i just really love the internet</a></li>
                <li><a href="#">sometimes i just really love the internet</a></li>
            </ul></h4>
        </section><!-- end twitter-feed -->
    </div><!-- end sidebar -->

1 个答案:

答案 0 :(得分:0)

您可能想要调整的几件事情:

  1. 您正在向样式规则添加一些属性,这些属性会降低您的内容,即:

    margin-top: 295px;
    padding-top: 25px; 
    

    您可能希望减少或消除这些。

  2. 您的排名设置为fixed,但您没有使用任何特定属性来设置排名,例如topleft。您可以在此处阅读更多内容:http://reference.sitepoint.com/css/position