【问题标题】:Centering objects in mobile view Bootstrap failed在移动视图中将对象居中引导失败
【发布时间】:2017-11-03 21:36:15
【问题描述】:

我遇到了一个非常简单的客户“正在建设”网站的问题。我正在使用 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;

}

}

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

屏幕截图:

【问题讨论】:

    标签: html css twitter-bootstrap centering


    【解决方案1】:

    body 有 min-width 属性

    min-width: 1024px;
    

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

    【讨论】:

    • 是的,非常感谢您,先生!我已将您的答案标记为正确。
    猜你喜欢
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 2021-08-30
    • 2018-05-13
    • 2022-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多