在移动视图中居中对象Bootstrap失败

时间:2017-06-02 12:55:10

标签: html css twitter-bootstrap centering

我遇到了一个针对客户的非常简单的“正在建设中”网站的问题。我使用Bootstrap来做出响应。但是现在在1024px的宽度下,内容并没有集中在它应该如何。

以下是我正在使用的代码:

HTML

    <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet"> 

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <div id="logo">

      <a href="#">
      <img id="logo_img" src="img/logo.png">
    </a>

  </div>
  <div id="underc">
    <p>Under Construction</p>
  </div>
  <div id="underline">
  </div>
  <div id="social_media">

      <a href="">
    <img id="fb" src="img/facebook.png">
      </a>
      <a href="">
    <img id="tw" src="img/twitter.png">
    </a>
      <a href="">
    <img id="ig" src="img/instagram.png">
  </a>

  </div>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

CSS

    body {
      margin: 0;
      background-image: url("../img/background2.jpg");
      /* Set rules to fill background */
      min-height: 100%;
      min-width: 1024px;

      /* Set up proportionate scaling */
      width: 100%;
      height: auto;

      /* Set up positioning */
      position: fixed;
      top: 0;
      left: 0;
    }




#underline {
  height: 5px;
  background-color: #f57300;
  margin-bottom: 5px;
  margin-top: -20px;
  width: 800px;
  margin: 0 auto;
}
#logo {
  padding-top: 220px;
  height: 100px;
  width: auto;
  text-align: center;
}
#logo_img {
  height: 250px;
}
#underc {
  color: #f57300;
  text-align: center;
  padding-top: 275px;
  font-family: 'Pacifico', cursive;
  font-size: 80px;
}
#social_media {
padding-top: 10px;
text-align: center;
}
#fb {
  height: 30px;
}
#tw {
  height: 30px;
}
#ig {
  height: 30px;
}
@media (max-width: 700px) {
  #underline {
  height: 5px;
  background-color: #f57300;
  margin-bottom: 5px;
  margin-top: -20px;
  width: 600px;
  margin: 0 auto;
}
#logo {
  padding-top: 220px;
  height: 100px;
  text-align: center;
}
#logo_img {
  height: 150px;
  text-align: center;
}
#underc {
  color: #f57300;
  text-align: center;
  padding-top: 275px;
  font-family: 'Pacifico', cursive;
  font-size: 30px;
}
#social_media {
padding-top: 10px;
text-align: center;
}
#fb {
  height: 30px;
}
#tw {
  height: 30px;
}
#ig {
  height: 30px;

}

}

然而,当屏幕在某个阶段变得“更小”时,它会开始粘在页面的右侧而且它不会居中。

截图: enter image description here

1 个答案:

答案 0 :(得分:0)

正文具有最小宽度属性

min-width: 1024px;

删除该属性或使用media queries在不同的屏幕上显示不同的尺寸。