【问题标题】:Bootstrap and Centering a Webpage引导和居中网页
【发布时间】:2017-02-04 13:09:09
【问题描述】:

我正在尝试使用 Bootstrap 在 Dreamweaver CC 中创建一个简单的网页。我无法弄清楚如何使显示的网页在浏览器中居中。该页面保持左对齐。这是我尝试使用的代码:

HTML5 和 CSS

#banner {
    background-image: url(../images/2000%20x%20150_Bubble_Final_Crop.jpg);
    height: 150px;
}
body {
    width: 1200px;
}
h1 {
    color: #FFFFFF;
    padding-top: 25px;
    font-family: Cambria, "Hoefler Text", "Liberation Serif", 
    Times, "Times New Roman", serif;
    font-size: 58pt;
    text-shadow: 2px 2px 24px #D7DC23;
    text-align: center;
}
.container-fluid {
    margin: 0 auto;

}
<!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">
    <title>Pixinsight Basics</title>
    <!-- Bootstrap -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet" type="text/css">
  </head>

  <body>
  <div class="container-fluid">
  <section class="row">

    <header id="banner">
    <h1>Pixinsight Basics</h1>
    </header>

    <div class="col-sm-6">
<h3>Heading 3</h3>
    <p>Hello my fellow astronomers. I have chosen to use Pixinsight
 as my primary processing software. Like you (probably) I have sifted
 around the internet looking for information/tutorials on how to use
 Pixinsight. While this is by no means a comprehensive data set on
 how to use Pixinsight, it should at least get you up and running. 
I have divided this information into 3 distinct processing areas of 
interest:</p>
<ul>
  <li>
    <!--[if !supportLists]--><!--[endif]-->
    Calibration</li>
  <li>
    <!--[if !supportLists]--><!--[endif]-->
    Linear</li>
  <li>
    Non–Linear</li>
</ul>
<p>Just click on one of the buttons below and it will
 take you to your area of interest.</p>
</div>


    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
    <script src="js/jquery-1.11.2.min.js"></script>


    <script src="js/bootstrap.js"></script>
    </section>
    </div> <!--container-fluid-->

    </body>
</html>

感谢任何帮助。

【问题讨论】:

  • .container-fluid 获取设备的全宽。如果您没有定义宽度并且还需要使用全宽,请不要为 .container-fluid 类定义样式。另一件事是,如果您不需要使用流体宽度并且专注于固定宽度,请使用 .container 类,其默认宽度为 1170px,如果需要,您可以覆盖它。

标签: html css twitter-bootstrap dreamweaver


【解决方案1】:

要解决此问题,请移除主体宽度,并将宽度添加到 container-fluid,结果为 css:

#banner {
  background-image: url(../images/2000%20x%20150_Bubble_Final_Crop.jpg);
  height: 150px;
}
body {
  margin:0;
  padding:0;
}
h1 {
  color: #FFFFFF;
  padding-top: 25px;
  font-family: Cambria, "Hoefler Text", "Liberation Serif", 
    Times, "Times New Roman", serif;
  font-size: 58pt;
  text-shadow: 2px 2px 24px #D7DC23;
  text-align: center;
}
.container-fluid {
  margin: 0 auto;
  width: 1200px;
}
<!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">
<title>Pixinsight Basics</title>
    <!-- Bootstrap -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet" type="text/css">
  </head>

  <body>
  <div class="container-fluid">
  <section class="row">

    <header id="banner">
    <h1>Pixinsight Basics</h1>
    </header>

    <div class="col-sm-6">
<h3>Heading 3</h3>
    <p>Hello my fellow astronomers. I have chosen to use Pixinsight
 as my primary processing software. Like you (probably) I have sifted
 around the internet looking for information/tutorials on how to use
 Pixinsight. While this is by no means a comprehensive data set on
 how to use Pixinsight, it should at least get you up and running. 
I have divided this information into 3 distinct processing areas of 
interest:</p>
<ul>
  <li>
    <!--[if !supportLists]--><!--[endif]-->
    Calibration</li>
  <li>
    <!--[if !supportLists]--><!--[endif]-->
    Linear</li>
  <li>
    Non–Linear</li>
</ul>
<p>Just click on one of the buttons below and it will
 take you to your area of interest.</p>
</div>


    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
    <script src="js/jquery-1.11.2.min.js"></script>


    <script src="js/bootstrap.js"></script>
    </section>
    </div> <!--container-fluid-->

    </body>
</html>

【讨论】:

  • 非常感谢吉什努。成功了。不知道它是如何工作的,但我会试着弄清楚。
  • 使用 .container 类而不是向 .container-fluid 添加宽度
  • 是的,对,`container-fluid 用于流体设计
【解决方案2】:

你必须删除正文规则

body {
    width: 1200px;
}

还有容器流体规则

.container-fluid {
    margin: 0 auto;
}

来自您的 CSS。将类 col-sm-6 替换为 col-sm-12 并将类 text-center 添加到此 div。 如果你想左右两边都有一些排水沟,请使用 container 类而不是 container-fluid。选择是你的。但我建议您使用container 类,因为它适合您的需要。

最后的样子:

<!DOCTYPE html>
<html>
<head>
    <title>Regent</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/bootstrap.css" rel="stylesheet" />
    <style>
#banner {
    background-image: url(../images/2000%20x%20150_Bubble_Final_Crop.jpg);
    height: 150px;
}

h1 {
    color: #FFFFFF;
    padding-top: 25px;
    font-family: Cambria, "Hoefler Text", "Liberation Serif", 
    Times, "Times New Roman", serif;
    font-size: 58pt;
    text-shadow: 2px 2px 24px #D7DC23;
    text-align: center;
}

    </style>
</head>
<body>

  <div class="container">
  <section class="row">

    <header id="banner">
    <h1>Pixinsight Basics</h1>
    </header>

    <div class="col-sm-12 text-center">
<h3>Heading 3</h3>
    <p>Hello my fellow astronomers. I have chosen to use Pixinsight
 as my primary processing software. Like you (probably) I have sifted
 around the internet looking for information/tutorials on how to use
 Pixinsight. While this is by no means a comprehensive data set on
 how to use Pixinsight, it should at least get you up and running. 
I have divided this information into 3 distinct processing areas of 
interest:</p>
<ul>
  <li>
    <!--[if !supportLists]--><!--[endif]-->
    Calibration</li>
  <li>
    <!--[if !supportLists]--><!--[endif]-->
    Linear</li>
  <li>
    Non–Linear</li>
</ul>
<p>Just click on one of the buttons below and it will
 take you to your area of interest.</p>
</div>


    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
    <script src="js/jquery-1.11.2.min.js"></script>


    <script src="js/bootstrap.js"></script>
    </section>
    </div> <!--container-fluid-->

</body>
</html>

【讨论】:

    猜你喜欢
    • 2020-04-15
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    • 2018-07-11
    • 1970-01-01
    • 2022-07-23
    • 1970-01-01
    相关资源
    最近更新 更多