从外部资源覆盖CSS [英] Override CSS from external resource
问题描述
我正在从NG-Bootstrap分页组件构建分页.在这种情况下,我想更改(实际上删除)一些在NG-Bootstrap库中声明的CSS.我该怎么做而不更改NG-Bootstrap样式表.
I am building a pagination from NG-Bootstrap pagination component. In that I want to change (actually remove) some CSS which is declared in NG-Bootstrap library. How can I do that without changing the NG-Bootstrap style sheet.
如上图所示,我要忽略在.pagination中声明的 padding-left:0 .我不需要为其添加其他值.我只想忽略它.是否有可能 ... ?
As shown in the above picture I want to ignore padding-left:0 which is declared in .pagination. I don't need to add another value for it.I just want to ignore it. Is it possible ... ?
推荐答案
要回答您的问题,不,您不能忽略CSS样式规则.但是您可以覆盖它而无需更改NG-Bootstrap样式表.
To answer your question, no, you can't ignore a CSS styling rule. But you can override it without altering the NG-Bootstrap style sheet.
您可以通过几种不同的方式将CSS规则附加到HTML文档,这是最常见的方式:
You can attach CSS rules to HTML documents in a few different ways, here are the most common:
-
通过在HTML文档的
-
链接到外部样式表:
<head>
部分中添加<link>
标记,Link to an external stylesheet by adding a
<link>
tag to the<head>
section of your HTML document:
<head>
<link rel="stylesheet" href="mystylesheet.css" />
</head>
<head>
<link rel="stylesheet" href="mystylesheet.css" />
</head>
使用<style>
标签将CSS 嵌入到HTML文档中:
Embed the CSS into your HTML document with a <style>
tag:
<style>
background-color: blue;
</style>
<style>
background-color: blue;
</style>
使用style
属性直接将CSS内联添加到单个HTML元素:
Add the CSS inline to individual HTML elements directly with the style
attribute:
<div style="background-color:gray;"></div>
<div style="background-color:gray;"></div>
根据您使用哪种方式,将根据其优先级应用不同的样式.内联优先于嵌入式,嵌入式优先于链接的样式表.
And depending on which way you do it, different styles will be applied depending on their precedence. Inline takes precedence over embedded, and embedded takes precedence over a linked stylesheet.
例如,如果在特定元素内联中指定灰色背景,并在嵌入式样式部分中为同一元素指定蓝色背景,则内联获胜且背景将为灰色.
For example, if you specify a gray background on a particular element inline, and specify a blue background on that same element in the embedded style section, inline wins and the background will be gray.
因此,根据您的情况,您可以嵌入CSS或将其内联在要更改的元素上.进行其中任何一项操作都会覆盖NG-Bootstrap样式表中的内容,而不会对其进行更改.
So for your situation you could either embed the CSS or put it inline on the elements you want to change. Doing either of those will override what's in the NG-Bootstrap style sheet without altering it.
这篇关于从外部资源覆盖CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!