2016-09-21 159 views
-1

在名爲first.css一個文件,有很多CSS的,我需要它,但這是CSS,我不需要像在這裏看到的一塊,但似乎是越來越應用到我的input如何用默認配置覆蓋CSS?

first.css:

.ng-invalid :not(.ng-valid)>.form-control { 
    border-color: #b94a48; 
    -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); 
      box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); 
} 

.ng-invalid :not(.ng-valid)>.form-control:focus { 
    border-color: #953b39; 
    -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #d59392; 
      box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #d59392; 
} 

我基本上不想讓CSS不適用於我的輸入形式,所以我做這樣的事情:

second.css:

.ng-invalid :not(.ng-valid)>.form-control input { 
    //I simply want the default CSS to apply, and not that from first.css 
} 

.ng-invalid :not(.ng-valid)>.form-control:focus input { 
     //I simply want the default CSS to apply, and not that from first.css 
} 

second.html:

<form style="margin-top: 10px" name="configurationForm" ng-class="{'submitted': submitted}" ng-submit="createConfiguration(configurationForm.$valid)" novalidate> 
     <div class="form-group row" ng-class="{'has-error': configurationForm.name.$invalid && !configurationForm.name.$pristine && submitted }"> 
      <label for="name" class="col-xs-1 col-form-label">Name</label> 
      <div class="col-xs-11"> 
       <input name="name" style="font-size: 10px; border-radius: 4px !important;" type="text" class="form-control" placeholder="Name" ng-model="configuration.name" required /> 
      </div> 
     </div> 
     ... <More form-control> ... 
    </form> 

有沒有辦法簡單地防止first.css的CSS從應用?我只是想要默認的配置(不管它們是什麼)應用,而不是上面這就是爲什麼我留下了空的second.css css元素。任何幫助,將不勝感激。謝謝。

+0

嘗試使用'!important'關鍵字:https://www.smashingmagazine.com/2010/11/the-important-css-declaration-how-and-when-to-use-it/ – Nestoraj

+0

重要的應該是'如果你在第一次之後包括第二名,那麼你就是必須的。 – Roberrrt

+0

@Nestoraj你說的只是包括在second.css CSS值中重要嗎? – user1871869

回答

2

負載second.css後first.css

<head> 
    <link rel="stylesheet" type="text/css" href="first.css"> 
    <link rel="stylesheet" type="text/css" href="second.css"> 
</head> 

然後在第二個CSS樣式那些重置none。但好像邊框顏色不能有none值,以便您可以嘗試transparent

.ng-invalid :not(.ng-valid)>.form-control input { 
    border-color: 'transparent'; 
    -webkit-box-shadow: 'none'; 
      box-shadow: 'none'; 

} 

.ng-invalid :not(.ng-valid)>.form-control:focus input { 
     border-color: 'transparent'; 
    -webkit-box-shadow: 'none'; 
      box-shadow: 'none' 
} 
0

嘗試second.css

+0

這不提供問題的答案。要批評或要求作者澄清,請在其帖子下方留言。 - [來自評論](/評論/低質量帖/ 13743082) – Jost

+0

@Jost這**是答案**。請閱讀並閱讀[本文](http://meta.stackoverflow.com/questions/287563/youre-doing-it-wrong-a-plea-for-sanity-in-the-low-quality-posts-隊列)和[本文](http://meta.stackexchange.com/questions/225370/your-answer-is-in-another-castle-when-is-an-answer-not-an-answer)我們應該在LQP審查隊列中刪除哪些答案,我們應該只是冷靜下來,我們應該放棄什麼。 –

0

使用none價值box-shadow財產只是新的屬性添加到second.css覆蓋的CSS樣式first.csshttps://jsfiddle.net/vLhuowss/

.myDiv { 
 
\t height: 100px; 
 
\t width: 100px; 
 
\t background-color: red; 
 
} 
 

 
.myDiv { 
 
\t background-color: blue; 
 
}
<div class="myDiv"></div>