如何消除使用bootstrap创建的html / css页面中的水平滚动条?

时间:2017-04-11 05:31:04

标签: html css html5 twitter-bootstrap

我的问题是,当我在笔记本电脑中查看此页面时,页面底部会出现一个水平滚动条。我尝试过人类的东西,但不能让它消失。 还有一个问题是,当我在笔记本电脑中查看此页面时,它看起来太小了,但是当我用chrome检查它时,它似乎没问题。

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<style type="text/css">
  header {
    background-color: #EE6E73;
    width: 100%;
  }

  header h1 {
    margin: 0;
    font-size: 45px;
  }

  body {
    background-color: white;
    min-height: 100%;
  }

  footer {
    background-color: #EF9A9A;
    position: fixed;
    width: 100%;
    bottom: 0;
  }

  footer h2 {
    margin: 0;
  }

  header h1 {
    text-align: center;
  }

</style>
<title>My Resume</title>
</head>

<body>
<div class="row">
  <div class="col-sm-12 col-md-12 col-lg-12">
    <header>
      <h1>My Resume</h1></header>
  </div>
  <div class="col-sm-12 col-md-8 col-lg-8">
    <p style="font-size: 1.5625em">My name is John Doe. I have completed my abc from xyz and pursuing def from pqr. I am interested in making applications for the web and mobile, especially android os.</p>
  </div>


  <div class="col-sm-12 col-md-4 col-lg-4">
    <p style="font-size: 1.5625em">My hobbies are:
      <ol style="font-size: 1.5625em">
        <li>Playing basketball</li>
        <li>reading</li>
        <li>traveling</li>
      </ol>
  </div>
  <div class="col-sm-12 col-md-12 col-lg-12">
    <footer>
      <h2 align="center">Contact Me</h2>
      <br>
      <p align="center">John Doe</p>
      <p align="center">City</p>
    </footer>
  </div>
</body>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" 
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" 
integrity="sha384-
BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" 
crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" 
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-
theme.min.css" integrity="sha384-
rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" 
crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script 
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" 
integrity="sha384-
Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" 
crossorigin="anonymous"></script>

</html>

这是一个jsfiddle链接:https://jsfiddle.net/zvdm6de4/1/

3 个答案:

答案 0 :(得分:2)

尝试这个代码

在行

的包装上添加container-fluid div

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <style type="text/css">
      header {
        background-color: #EE6E73;
        width: 100%;
      }
      
      header h1 {
        margin: 0;
        font-size: 45px;
      }
      
      body {
        background-color: white;
        min-height: 100%;
      }
      
      footer {
        background-color: #EF9A9A;
        position: fixed;
        width: 100%;
        bottom: 0;
      }
      
      footer h2 {
        margin: 0;
      }
      
      header h1 {
        text-align: center;
      }

    </style>
    <title>My Resume</title>
  </head>

  <body>
  <div class="container-fluid">
  
 
    <div class="row">
      <div class="col-sm-12 col-md-12 col-lg-12">
        <header>
          <h1>My Resume</h1></header>
      </div>
      <div class="col-sm-12 col-md-8 col-lg-8">
        <p style="font-size: 1.5625em">My name is John Doe. I have completed my abc from xyz and pursuing def from pqr. I am interested in making applications for the web and mobile, especially android os.</p>
      </div>


      <div class="col-sm-12 col-md-4 col-lg-4">
        <p style="font-size: 1.5625em">My hobbies are:
          <ol style="font-size: 1.5625em">
            <li>Playing basketball</li>
            <li>reading</li>
            <li>traveling</li>
          </ol>
      </div>
      <div class="col-sm-12 col-md-12 col-lg-12">
        <footer>
          <h2 align="center">Contact Me</h2>
          <br>
          <p align="center">John Doe</p>
          <p align="center">City</p>
        </footer>
      </div>
       </div>
  </body>
  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

  <!-- Optional theme -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

  <!-- Latest compiled and minified JavaScript -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

</html>

答案 1 :(得分:0)

在body之后添加一个带有container-fluid类的div,并将所有代码保存在这个div之间。

答案 2 :(得分:-1)

将body CSS更改为此

body {<br>
    background-color: white;<br>
    min-height: 100%;<br>
    overflow-x: hidden;<br>
}

您可以根据CSS文件中的需要使用overflow-x:hiddenoverflow-x:scroll(对于水平滚动条)

通常overflow-x用于水平滚动条&amp; overflow-y用于垂直scrollBar