尽管使用溢出标记,但无法在页面内滚动div

时间:2013-09-26 17:44:15

标签: html css overflow

我正在创建一个使用ajax调用来加载内容窗格的网站。只是用一些数据快速嘲笑这个,(在我的网站上ajax工作正常,所以这里不需要)我无法在内容窗格溢出时滚动 - 整个页面滚动而不是。

有一些问题类似于此但我遇到的每一个都没有使用溢出标签,它解决了他们的问题。我试过了,但没有成功。

我不知道如何让div认识到它正在溢出。到目前为止,我已经设法让它滚动的唯一方法是修复高度,但我觉得这样做很糟糕,因为根据屏幕尺寸,我希望它像人们期望的那样滚动。

这是html:

<body>
    <div id="content-container">
        <img src="http://i.imgur.com/69BtzId.png" alt="logo">
        <div class="navbar">
            <nav>
                <ul>
                    <li class="homeLink">   <a href="index.html">HOME </a>

                    </li>
                    <li id="activePortfolioLink">   <a href="portfolio.html">PORTFOLIO </a>

                    </li>
                    <li class="aboutLink">  <a href="about.html">ABOUT </a>

                    </li>
                </ul>
            </nav>
        </div>
        <div id="portfolioUnderline"></div>
    </div>
    <div id="left">
        <ul class="verticalNavBar">
            <li id="webDesignLink"> <a>WEB DESIGN</a>

            </li>
            <li id="uiLink">    <a>USER INTERACTION DESIGN</a>

            </li>
            <li id="graphicDesignLink"> <a>GRAPHIC/ TYPOGRAPHY DESIGN</a>

            </li>
        </ul>
    </div>
    <div id="verticalLine"></div>
    <div id="rightContent">
        <div class="portfolioImages">
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ut massa in tortor ullamcorper iaculis. Ut placerat imperdiet metus sed pellentesque. Proin iaculis erat eget fringilla lobortis. Pellentesque sit amet urna condimentum, tristique erat et, egestas ante. Duis eu pulvinar leo, fringilla posuere ligula. Nunc commodo tellus at lorem interdum feugiat. Cras varius consequat diam vitae scelerisque. Mauris nec ligula in mi accumsan scelerisque sed vel augue. Aliquam elementum, dolor id ornare feugiat, ante justo sollicitudin erat, ut gravida velit nibh vel velit. Fusce ultrices consectetur eros, ac tincidunt libero auctor ut. Quisque dapibus congue arcu sed imperdiet. Pellentesque lorem nisi, dictum sit amet libero in, cursus eleifend ante. Nunc vel euismod erat. Duis massa tellus, tincidunt in fermentum ut, sagittis vulputate lectus. Nunc ut iaculis nibh. In congue laoreet arcu commodo imperdiet. Nullam rutrum augue nec mauris rhoncus facilisis. Donec bibendum luctus magna. Vivamus tempor egestas turpis. Curabitur non porta lorem, nec elementum ante. Cras faucibus consequat augue, laoreet pretium lorem tincidunt sed. Vestibulum magna dolor, pulvinar vitae facilisis eget, posuere sit amet est. Suspendisse vel elit a neque laoreet faucibus eget et quam. Integer feugiat, tellus sit amet tempus dignissim, neque justo congue enim, quis commodo neque neque quis orci. Suspendisse scelerisque erat lobortis felis fermentum, in molestie nulla pharetra. Suspendisse lacinia ac orci et tincidunt. Duis lobortis at leo a viverra. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Etiam libero turpis, consequat non convallis at, eleifend non dolor.</br>
                </br>
                </br>
                </br>
                </br>Maecenas tincidunt lorem vitae fringilla consectetur. Interdum et malesuada fames ac ante ipsum primis in faucibus. Maecenas sit amet magna tincidunt, pellentesque arcu posuere, euismod lectus. Sed nec pellentesque diam, id varius quam. Praesent mattis sapien odio, in mattis dui tempus sit amet. Morbi pulvinar odio nec augue tempus varius. Sed porttitor consequat magna, sit amet lobortis mauris congue eleifend. Donec pretium elit vitae egestas rutrum. Sed sapien libero, vulputate eu lacinia sit amet, aliquam et elit. Aenean nisi mi, vulputate id nulla ut, vestibulum porta enim. Nunc quis tellus eleifend, adipiscing lorem in, congue justo. Vivamus ornare risus quis faucibus pretium. Vestibulum eu velit placerat, lacinia justo rutrum, sagittis nisi. Donec quis tincidunt justo, eu posuere mauris. Morbi eleifend, dui eget aliquet adipiscing, tellus risus hendrerit dolor, non aliquet magna sapien malesuada ante. Fusce lobortis commodo sem id tempus. Nulla eget vehicula mi, id volutpat erat. Proin sed enim egestas, rhoncus ipsum a, consectetur mi. Quisque est arcu, tempus a ligula eu, aliquam elementum quam. Sed tristique sit amet sapien eget ornare. In vitae adipiscing neque. Ut aliquet felis vitae porttitor vehicula. Morbi aliquam rhoncus lacinia. Vestibulum at viverra nisl. Donec rhoncus, dolor eu luctus egestas, magna leo consequat justo, ac venenatis odio ligula ac tortor. Nullam faucibus ante enim, vitae cursus mauris interdum ut. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc turpis massa, viverra vitae rutrum non, elementum sit amet orci.</p>
        </div>
    </div>
</body>

这是CSS:

* {
    font-family:'Lato', sans-serif;
    font-weight: lighter;
    padding: 0;
    margin: 0;
    color:white;
}
body {
    background: #111111;
    height: 100%;
}
#content-container {
    background-color: #111111;
    height: 113px;
    width: 100%;
}
#content-container img {
    padding: 15px;
    padding-top: 15px;
    /*float: left; */
}
.navbar {
    float: right;
    background-color: #111111;
    font-size: 25px;
    padding-top: 45px;
}
nav ul li {
    display: inline;
}
nav ul li a {
    text-decoration: none;
    color: white;
    padding: 15px;
    float:right;
}
nav ul li.homeLink a {
    padding-left: 41px;
    padding-right: 43px;
}
nav ul li.portfolioLink a {
    padding-left: 9px;
    padding-right: 9px;
    padding-bottom: 1px;
}
nav ul li.aboutLink a {
    padding-left: 37px;
    padding-right: 37px;
}
#activePortfolioLink a {
    padding-left: 9px;
    padding-right: 9px;
    background: #0033cc;
    font-weight: normal;
}
#portfolioUnderline {
    background-color: #0033cc;
    width: 100%;
    height: 10px;
    margin-top: -12px;
}

#left {
    float: left;
    width: 300px;
    overflow: hidden;
}
#rightContent {
    margin-left: 300px padding-left:300px;
    height:100%;
    overflow:scroll;
}
.verticalNavBar {
    float: right;
    text-align: right;
    margin-top: 20px;
    color: white;
    font-size: 15px;
}
.verticalNavBar li {
    list-style: none;
    color: white;
    padding-top:10px;
    padding-bottom: 10px;
}
.verticalNavBar li a {
    text-decoration: none;
    color: white;
    padding: 10px;
}
#verticalLine {
    background-color: #0033cc;
    float:left;
    width: 10px;
    height: 905px;
}
#webDesignLink a {
    background: #0033cc;
    font-weight: normal;
}

.portfolioImages {
    margin: 0 auto;
    padding-top: 20px;
    padding: 10;
    margin-right: 10%;
    margin-left: 10%;
    margin-bottom: 20px;
    overflow: auto;
}
img.individualImage {
    margin-left: 450px;
}
.portfolioImages p {
    font-size: 15px;
    font-weight: lighter;
    text-align: center;
}

以下是代码的jsfiddle:http://jsfiddle.net/GGSSj/

谢谢你的时间!

3 个答案:

答案 0 :(得分:0)

您可以根据屏幕尺寸修复高度,但必须固定高度/某种方式/以使其独立滚动。

这是每个片段绝对定位的小提琴:http://jsfiddle.net/GGSSj/3/

#content-container {
    position:absolute; top:0; left:0; width:100%; height:113px;
}
#left {
    position:absolute; top:123px; bottom:0; left:0; width:300px;
}
#rightContent {
    position:absolute; top:123px; bottom:0; left:310px; right:0;
    overflow-y:scroll;
}

答案 1 :(得分:0)

您可以根据屏幕尺寸修复高度,但来修复可滚动容器的高度(以某种方式使用javascript作为全屏高度)以使其独立滚动。< / p>

试一试:fiddle updated here

#rightContent {
  height: 555px; /* fit height to your needs */
  overflow: auto;
}

答案 2 :(得分:0)

您需要将顶部区域和左侧区域设置为position:fixed;

http://jsfiddle.net/GGSSj/

    #left {
    position:fixed;
    top: 113px;
    left: 0;
    width: 300px;
    overflow: hidden;
}
#rightContent {
    margin-left:300px; 
    padding-top:113px;
    height:100%;
    overflow: auto;
}
#content-container {
    position: fixed;
    background-color: #111111;
    height: 113px;
    width: 100%;
}