html - 无法更改背景颜色,用于 Bootstrap

标签 html css twitter-bootstrap

<分区>


这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助 future 的读者。

关闭 7 年前

我正在尝试将背景颜色更改为黑色。但它不起作用。 我提供的 .css 引用链接有问题吗?背景图片效果很好,但是当我只想制作一个具有特定颜色的普通背景时,它总是显示白色。

我什至尝试添加 !important, "background-color: black !important;...但仍然没有用。

<!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>Project Selector</title>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/annyang/1.1.0/annyang.min.js"></script>

  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
        integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

  <!-- Optional theme -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css"
        integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
  <style>


    body {
      position: relative;
    }

    #home {
      padding-top: 50px;
      height: 667px;
      background-color: black;
    }

    h1.h11 {
      position: relative;
      text-align: center;
      color: black;
      top: 250px;
    }

  </style>

</head>

<body>

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="projectf.html">Projects</a>
    </div>
    <div>
      <div class="navbar-collapse collapses">
        <ul class="nav navbar-nav">
          <li><a href="#home">Home</a></li>
          <li><a href="#search">Search</a></li>
          <li><a href="#LoT">List of topics</a></li>
          <li><a href="#tutorial">Tutorial</a></li>
          <li><a href="#about">About</a></li>
        </ul>
      </div>
    </div>
  </div>
</div>

<div class="home">
  <div class="container-fluid">
    <h1 class="h11">Project Selection Interface</h1>

  </div>
</div>

<!-- JQUERY JS file -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>

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

</body>
</html>

最佳答案

您在 CSS 中使用的是 ID,而不是在 html 中使用的类

违规代码

#home{
padding-top:50px;
height:667px;
background-color:black;

}

更正代码

.home{
padding-top:50px;
height:667px;
background-color:black;

}

关于html - 无法更改背景颜色,用于 Bootstrap ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36601831/

上一篇:html - 溢出有图像问题

下一篇:html - 在 ionic 中制作一个 3 列 div 组件

相关文章:

html - 将 CSV 数据从 div 复制到 Excel 工作表

javascript - 图像仅改变一次

javascript - 使用 jquery 选择单个下一个兄弟

html - Bootstrap Pills 在小屏幕上不可点击

javascript - 删除表单元素并在其位置放置一个具有唯一 id 的 div?

html - CSS:使用 div 和背景图像,图像未调整大小以适合 div 大小

javascript - CSS 帮助 - 移动网站的页脚

html - IE11 剪切文本

jquery - 是否可以在溢出 div 顶部打开 Bootstrap 下拉菜单?

javascript - 带 Bootstrap 滚动 spy 的三级层次结构?