简体   繁体   English

如何在实现CSS中更改默认按钮的颜色?

[英]How to change default button color in materialize css?

I have added a button in navbar. 我在导航栏中添加了一个按钮。 Navbar has 4 li elements and 4th contains button. 导航栏有4个li元素,第4个包含按钮。 I want to change the default color of the button I want to use custom css. 我想更改要使用自定义CSS的按钮的默认颜色。

header.js: header.js:

class Header extends Component {

  render() {
    return (
      <div>   
        <div class="navbar-fixed">
          <nav className="navbar">
            <div className="nav-wrapper">
              <a href="#" className="brand-logo">Udacity Logo</a>
              <ul id="nav-mobile" className="right hide-on-med-and-down">
                <li><a href="#">Nanodegree</a></li>
                <li><a href="#">Hire Talent</a></li>
                <li><a href="#">For Business</a></li>
                <li><a className="waves-effect waves-light btn findbtn">Course Finder</a></li>
              </ul>
            </div>
          </nav>
         </div>
      </div>
    );
  }
}

I tried to add following CSS property to .findbtn class but it does not work. 我试图将以下CSS属性添加到.findbtn类,但是它不起作用。

In header.css: 在header.css中:

.findbtn{
    background-color: #5E35B1;
}

Screenshot: 截图:

在此处输入图片说明

I just tried the code and it works 我只是尝试了代码,它就可以了

 import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; class App extends Component { constructor(){ super() } render() { return ( <div> <div class="navbar-fixed"> <nav className="navbar"> <div className="nav-wrapper"> <a href="#" className="brand-logo">Udacity Logo</a> <ul id="nav-mobile" className="right hide-on-med-and-down"> <li><a href="#">Nanodegree</a></li> <li><a href="#">Hire Talent</a></li> <li><a href="#">For Business</a></li> <li><a className="waves-effect waves-light btn findbtn">Course Finder</a></li> </ul> </div> </nav> </div> </div> ); } } export default App; 

And in CSS file App.css you have to include 在CSS文件App.css中,您必须包含

 .findbtn{ background-color: #5E35B1; } /* if it does not work try with background-color: #5E35B1 !important; may there is some css that is overriding the values */ 

If it does not work try with !important tag in css may be there is some other class which is not allowing to apply your css 如果它不起作用,请尝试在CSS中使用!important标记,可能还有其他某些类不允许应用您的CSS

Try following 尝试跟随

a[classname='findbtn']{
background-color: #5E35B1;
}

You can try this: 您可以尝试以下方法:

.findbtn{
    background-color: #5E35B1 !important;
}

If above example not working, use Developer Tools for check whether component sees your CSS code. 如果上述示例不起作用,请使用开发人员工具检查组件是否看到您的CSS代码。 Maybe you forgot to require this CSS file. 也许您忘记了需要此CSS文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM