首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bootstrap CSS按钮问题,未更改颜色

问Bootstrap CSS按钮问题,未更改颜色
EN

Stack Overflow用户
提问于 2021-01-13 08:49:58
回答 2查看 39关注 0票数 0

我有一个引导按钮,如下所示:

​

​

此按钮的HTML代码如下:

代码语言:javascript
复制
<button type="button" class="btn-primary.custom-btn" data-bs-toggle="modal" data-bs-target="#exampleModal">
   More Info
</button>

由于某些原因,我的CSS没有显示出来。我认为这是因为我的页面上有其他按钮,而它们的CSS是冲突的,所以我更改了类以将它们分开:

代码语言:javascript
复制
<button class="btn-filter active" onclick="filterSelection('all')"> Show all</button>

这只是btn,我把它改成了btn-filter,这样我就可以很容易地分辨出我的CSS的不同之处,但是我仍然遇到了自定义btn没有改变成正确的颜色的问题。

下面是我的CSS:

代码语言:javascript
复制
  <style>
  * {
    box-sizing: border-box;
  }

  body {
    background-color: #f1f1f1;
    padding: 20px;
    font-family: Arial;
  }

  /* Center website */
  .main {
    max-width: 1000px;
    margin: auto;
  }

  h1 {
    font-size: 50px;
    word-break: break-all;
  }

  .row {
    margin: 10px -16px;
  }

  /* Add padding BETWEEN each column */
  .row,
  .row > .column {
    padding: 8px;
  }

  /* Create three equal columns that floats next to each other */
  .column {
    float: left;
    width: 33.33%;
    display: none; /* Hide all elements by default */
  }

  /* Clear floats after rows */
  .row:after {
    content: "";
    display: table;
    clear: both;
  }

  /* Content */
  .content {
    background-color: white;
    padding: 10px;
  }

  /* The "show" class is added to the filtered elements */
  .show {
    display: block;
  }

  /* Style the buttons */
  .btn-filter {
    border: none;
    outline: none;
    padding: 12px 16px;
    background-color: white;
    cursor: pointer;
  }

  .btn-filter:hover {
    background-color: #ddd;
  }

  .btn-filter.active {
    background-color: #666;
    color: white;
  }


    .slidecontainer {
      width: 100%;
    }

    .slider {
      -webkit-appearance: none;
      width: 100%;
      height: 25px;
      background: #E7E7E7;
      outline: none;
      opacity: 0.7;
      -webkit-transition: .2s;
      transition: opacity .2s;
    }

    .slider:hover {
      opacity: 1;
    }

    .slider::-webkit-slider-thumb {
      -webkit-appearance: none;
      appearance: none;
      width: 25px;
      height: 25px;
      background: #4CAF50;
      cursor: pointer;
    }

    .slider::-moz-range-thumb {
      width: 25px;
      height: 25px;
      background: #4CAF50;
      cursor: pointer;
    }

    body {
      padding-top: 75px;
    }


    .footer {
      background-color: transparent;
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      width: max-content;
      display: inline-block !important;

    }

    .wrapper {
      display: block;
    }

    #sidebar {
      min-width: 250px;
      max-width: 250px;
      height: 100vh;
      position: fixed;
      top: 0;
      left: -250px;
      z-index: 99999;
      background: #212529;
      transition: all 0.3s;
      padding: 1em;
    }

    #sidebar.active {
      left: 0;
    }

    .overlay {
      display: none;
      position: fixed;
      width: 100vw;
      height: 100vh;
      background: rgba(0, 0, 0, 0.7);
      z-index: 9999;
      opacity: 0;
      transition: all 0.5s ease-in-out;
      top: 0;
    }

    /* display .overlay when it has the .active class */
    .overlay.active {
      display: block;
      opacity: 1;
    }

    #dismiss {
      width: 35px;
      height: 35px;
      position: absolute;
      /* top right corner of the sidebar */
      top: 10px;
      right: 10px;
      color: #dc880a;
    }

    #sidebar .sidebar-header {
      padding: 20px;
      background: #212529;
    }

    #sidebar ul.components {
      padding: 20px 0;
    }

    #sidebar ul p {
      color: #fff;
      padding: 10px;
    }

    #sidebar ul li a {
      padding: 10px;
      font-size: 1.1em;
      display: block;
      color: #dc880a;
    }


    #sidebar ul li.active>a,
    a[aria-expanded="true"] {
      color: #fff;
      background: #6d7fcc;
    }

    ul ul a {
      font-size: 0.9em !important;
      padding-left: 30px !important;
      background: #6d7fcc;
    }

    .btn-primary.custom-btn {
        background-color: #dc880a;
        border-color: #dc880a;

    }

    * {
            padding: 0;
            margin: 0;
      }
  </style>

我不确定我在这里错过了什么。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-01-13 09:08:39

您需要调整按钮上的css类。具体来说,class="btn-primary.custom-btn"需要更改为class="btn-primary custom-btn"。

原因是CSS选择器.btn-primary.custom-btn意味着“所有具有btn-primary和定制-btn类的元素”,但实际应用于按钮的类只有一个名为btn-primary.custom-btn的类。

代码语言:javascript
复制
<button type="button" class="btn-primary custom-btn" data-bs-toggle="modal" data-bs-target="#exampleModal">
   More Info
</button>
票数 1
EN

Stack Overflow用户

发布于 2021-01-13 09:23:30

它不能识别你的风格的原因是你的类名不正确。您需要将按钮类名称从class="btn-primary.custom-btn"更改为class="btn-primary custom-btn"。在为HTML元素指定类名时,不需要点。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65694181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档