Bootstrap container-fluid 不是屏幕的整个宽度

新手上路,请多包涵

我正在做一个网站,我首先从移动样式表开始。但是容器流体的宽度与窗口的宽度不同。

我试图解决这个问题的是:

  .container-fluid{
      width: 105%
 }

现在的问题是,当我把窗口变小一点时,仍然不够,但是当我把窗口变大一点时,它就太大了,当我这样做时,底部会出现一个滚动条。

100% 不起作用,因为我已经说过它不是窗口的整个宽度。

这是 HTML 文件的整个正文:

 <body>
<!-- Introduction -->

<div id="introduction" class="container-fluid">
    <div class="row">
        <header>
            <h1> Mosescu Bogdan Gabriel </h1>
            <img id="profilepic" src="profilepic.png" />
            <h2> Web Designer | Motion Graphics Artist </h2>
        </header>
    </div>
</div>
<!-- //Introduction// -->

<div id="about" class="container-fluid">
    <div class="row">
        <h1 id="about-title"> Who I am </h1>
    </div>
</div>
</body>

这是CSS文件:

 /*Introduction CSS */
#introduction{
background-color: #542437;
color: white;
margin-top: -21px;
}
#introduction header{
text-align: center;
}
#introduction header h1{
font-family: montserrat;
font-weight: bold;
}
#introduction header h2{
font-family: montserrat;
font-weight: normal;
font-size: 1em;
}
#profilepic{
border-radius: 100%;
width: 150px;
height: 150px;
}
/* //Introduction CSS// */

/* About CSS */
#about{
background-color: #f2f2f2;
color: #1a1a1a;
text-align: center;
margin-top: -24px;
}
#about-title{
font-family: montserrat;
font-weight: bold;
font-size: 2.25em;
border-bottom: solid 1px black;
}

原文由 Blaze26 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.2k
2 个回答

引导容器被填充。

  .container-fluid {
    padding-right:15px;
    padding-left:15px;
    margin-right:auto;
    margin-left:auto
 }

您需要删除填充。

 .container-fluid {
    padding-right:0;
    padding-left:0;
    margin-right:auto;
    margin-left:auto
 }

编辑:这是一个简单的例子。如果您将其复制并粘贴到一个新的 .html 文档中,您将在容器上看到没有填充。如果您随后删除 container-fluid 覆盖,您将看到填充。

 <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">

        <!-- put your override styles here - AFTER you include Bootstrap -->
        <link href="style-mobile.css" rel="stylesheet">

    </head>
    <style>
        /* override Bootstrap's container */
        .container-fluid {
            padding-right:0;
            padding-left:0;
            margin-right:auto;
            margin-left:auto
         }
    </style>
    <body>

        <div class="container-fluid">
            This text hits the left side of the viewport.
        </div>

    </body>
</html>

编辑 HTML 示例以包含新的 css 链接

编辑:引导程序 4

@Dagrooms 评论说:“在 Bootstrap 4 中执行此操作的最佳方法是将 px-0 添加到您的 container-fluid div 中。”

这将从容器的左侧和右侧移除填充,使其接触浏览器视口的两侧。

 <div class="container-fluid px-0">
    This text hits the left side of the viewport.
</div>

原文由 timgavin 发布,翻译遵循 CC BY-SA 4.0 许可协议

在尝试了大多数这些答案之后,这是我唯一可以开始工作的事情。

CSS:

 #mydiv {
  margin: 0 -9999rem;
  padding: 0.25rem 9999rem;
  background-color:#2A2A52
}

html:

 <div class="container-fluid px-0">
    <div id="mydiv">
        <div class="row">
            <div class="col-md-12">
                 <p>YOUR CONTENT HERE</p>
              </div>
         </div>
     </div>
</div>

注意:我需要在容器上指定 px-0 并将行包装在单独的 div 中,以便文本与页面上的其他文本水平对齐,该页面是典型容器流体 div 的一部分。

原文由 tomb 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题