简体   繁体   中英

How to change bootstrap link_to color on navbar

How to change link_to color on navbar to make it look like this;

<a class='brand' href='#'>PROJECT_NAME</a>

so far i have

.brand
   = link_to "PROJECT_NAME", root_path

but its still blue:(

Here's what worked for me ( part of the code is from the rails tutorial by Michael Hartl ):

<%= link_to "delete user", user, method: :delete,
      data: {confirm: "Are you sure you want to delete this user?" }, class: 'delete' %>

Then in my custom.css.scss file I have:

li {
    overflow: auto;
    padding: 10px 0;
    border-bottom: 1px solid $gray-lighter;
    a:link {
      &.delete {
        color: red;
      }
    }
  }

If you just want to add a class to link_to element, you need to add it after comma.

= link_to "PROJECT_NAME", root_path, class: 'brand'

But of my experience of working with Bootstrap, I think, that it won't change your color. So, you need to add !important to your .brand class in CSS file to overwrite default Bootstrap colors. Or you can hardcode it like this (to avoid !important conditions):

.navbar .nav > li > a {
  &.brand {
    color: #color;
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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