使用Bootstrap禁用侧栏上的滚动

时间:2015-12-14 00:56:44

标签: html twitter-bootstrap scroll positioning

我是Bootstrap的新手,在两个问题上需要帮助:

  1. 第一个,是如何禁用侧边栏上的滚动?我希望将左列固定到屏幕上,而不是滚动右侧的内容。

  2. 最后,如何将侧边栏上的内容移动/推送到浏览器窗口的最边缘?我还希望第二栏向左移动。

  3. 这是我的代码:

    <!DOCTYPE html>
        <html lang="en-US">
            <head>
                <meta charset="UTF-8" />
                <meta http-equiv="X-UA-Compatible" content="IE=edge">
                <meta name="viewport" content="width=device-width, initial-scale=1">
                <title>CodeButler</title>
                <meta name="viewport" content="width=device-width, initial-scale=1">
                <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
                <link href="css/stylesheet.css" type="text/css" rel="stylesheet" />
                <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
                <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
            </head>
            <body>
                <div class="container">
                    <div class="row">
                        <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12 sidebar">
                            <h1>Title of Webpage</h1>
                            <p>Some text will go here.</p>
                            <ul>
                                <li><a href="index.html" alt="Home">Home</a></li>
                                <li><a href="about.html" alt="About">About</a></li>
                                <li><a href="archives.html" alt="Archives">Archives</a></li>
                            </ul>
                        </div>
                        <div class="col-lg-4 col-md-8 col-sm-6 col-xs-12 articles">
                            <h6>Date Here</h6>
                            <h3>Title Here</h3>
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sed mi a purus euismod dapibus at eu ante. Nunc erat risus, laoreet at elementum id, dignissim at quam. In accumsan sem a lectus vulputate, eget condimentum odio condimentum. Nulla facilisi. Duis enim dolor, tristique eu finibus sit amet, molestie vel metus. Sed a ultricies urna. Duis eget lectus vitae ligula accumsan feugiat at ut libero.</p>
                            <h6>Date Here</h6>
                            <h3>Title Here</h3>
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sed mi a purus euismod dapibus at eu ante. Nunc erat risus, laoreet at elementum id, dignissim at quam. In accumsan sem a lectus vulputate, eget condimentum odio condimentum. Nulla facilisi. Duis enim dolor, tristique eu finibus sit amet, molestie vel metus. Sed a ultricies urna. Duis eget lectus vitae ligula accumsan feugiat at ut libero.</p>
                        </div>
                    </div>
                </div>
            </body>
        </html>
    

    谢谢!

2 个答案:

答案 0 :(得分:2)

要修复侧边栏,您只需要添加一些css。

 .sidebar { 
    position: fixed; 
    top: 0; 
    bottom: 0;
    left: 0;
 }

答案 1 :(得分:0)

看看你是否在寻找吼叫:

<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>CodeButler</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link href="css/stylesheet.css" type="text/css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-lg-4 sidebar">
                <h1>Title of Webpage</h1>
                <p>Some text will go here.</p>
                <ul>
                    <li><a href="index.html" alt="Home">Home</a></li>
                    <li><a href="about.html" alt="About">About</a></li>
                    <li><a href="archives.html" alt="Archives">Archives</a></li>
                </ul>
            </div>
            <div class="col-lg-8 articles">
                <h6>Date Here</h6>
                <h3>Title Here</h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sed mi a purus euismod dapibus at eu ante. Nunc erat risus, laoreet at elementum id, dignissim at quam. In accumsan sem a lectus vulputate, eget condimentum odio condimentum. Nulla facilisi. Duis enim dolor, tristique eu finibus sit amet, molestie vel metus. Sed a ultricies urna. Duis eget lectus vitae ligula accumsan feugiat at ut libero.</p>
                <h6>Date Here</h6>
                <h3>Title Here</h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sed mi a purus euismod dapibus at eu ante. Nunc erat risus, laoreet at elementum id, dignissim at quam. In accumsan sem a lectus vulputate, eget condimentum odio condimentum. Nulla facilisi. Duis enim dolor, tristique eu finibus sit amet, molestie vel metus. Sed a ultricies urna. Duis eget lectus vitae ligula accumsan feugiat at ut libero.</p>
            </div>
        </div>
    </div>
</body>
</html>