假設我有檔案_buttons.scss:
.btn {
display: inline-block;
font-family: $btn-font-family;
font-weight: $btn-font-weight;
color: $body-color;
text-align: center;
text-decoration: if($link-decoration == none, null, none);
white-space: $btn-white-space;
}
現在在我的覆寫檔案'buttons.scss'中,我想洗掉color并添加我的自定義字體系列和重量:
.btn {
font-family: $custom-font-family;
font-weight: $custom-font-weight;
}
現在,如果我想.btn在 an 上使用該類,由于生成的 CSS 檔案而不是定義的顏色<a>,它仍然會從 Bootstrap 中獲取該類的顏色。.btn<a>
例如在 html 中:
<a href="#" class="btn btn-sm dropdown-toggle" data-toggle="dropdown">Attachment <span class="badge" data-bind="text: Documents().length">1</span></a>
我怎樣才能防止這種情況?
編輯:編譯后的 CSS 將類似于:
.btn {
display: inline-block;
font-weight: 400;
color: #212529;
text-align: center;
}
.btn {
font-family: "Segoe UI", "Segoe UI Light", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 200;
}
因此,它仍將使用來自引導程式#212529的類的顏色。.btn
uj5u.com熱心網友回復:
您必須手動將顏色設定為“未設定”
.btn {
font-family: $custom-font-family;
font-weight: $custom-font-weight;
color: unset; /* or "inherit" or whatever, based on your needs */
}
這是覆寫 CSS 屬性的正確方法,請注意您可能需要 !important 根據您的 CSS 框架需要遵循 CSS 規則。換句話說,如果您無法處理加載順序,則需要指定!important(如果可以,請不要):)
如果您沒有像現在一樣指定顏色,那么您只是覆寫其他屬性并保持顏色
uj5u.com熱心網友回復:
添加!important到您的 CSS 屬性應該會有所幫助。
關于 !import 在 w3schools 上。
.btn {
font-family: $custom-font-family !important;
font-weight: $custom-font-weight !important;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/429612.html
上一篇:如何在保持影片淡入激活的同時禁用Boostrap5Modal的淡出?
下一篇:斷點的順序在引導程式5中是否重要
