简体   繁体   English

覆盖项目中的JavaScript / HTML / CSS /等文件

[英]Overriding JavaScript/HTML/CSS/ etc… files in projects

I'm trying to build a web library that is supposed to be an infrastructure to my other projects. 我正在尝试构建一个Web库,该库应该是我其他项目的基础结构。
In those other projects I'll be overriding some of the scripts, styles and other components, but some of the functionality should stay the same and not be overriden. 在那些其他项目中,我将覆盖一些脚本,样式和其他组件,但是某些功能应保持不变,而不应被覆盖。 I'd like NOT to copy all the files to every project, but packing them and extracting the files in production will be ok. 我不想将所有文件复制到每个项目,但可以打包并在生产中提取文件。

What is the best/standard way to do it? 最好/标准的方法是什么?

This may help: Mozzila Web Developer Website or may overriding a style rule in CSS: 这可能会有所帮助: Mozzila Web Developer网站或可能会覆盖CSS中的样式规则:

 a { color: white; color: red !important; display: none; display: flex !important; } 
 <a href='https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/HTML_and_CSS'>Mozzila Test</a> 

btw if you want to override Files: 顺便说一句,如果您想覆盖文件:

 <link rel="stylesheet" href="style.css" /> <link rel="stylesheet" href="overrided.css" /> 

That's the way you work with other frameworks like Bootstrap and Foundation. 这就是您与其他框架(如Bootstrap和Foundation)一起工作的方式。 The order in which you load your css files into html lets the latter overwrite the former, if there are rules of same or higher specificity. 如果存在相同或更高特异性的规则,则将css文件加载到html的顺序可以使后者覆盖前者。

So just create your base styles and then load overrides: 因此,只需创建您的基本样式,然后加载覆盖:

<link rel="stylesheet" type="text/css" href="base.css">
<link rel="stylesheet" type="text/css" href="overrides.css">

For example 例如

 .button{ padding : 12px 6px !important; color : #434343 !important; margin : 1em 3em !important; } 

It works everywhre via !important that browser only must use these properties in all same name classes . 它可以通过!important在每个地方都起作用,仅浏览器必须在所有相同的名称类中使用这些属性。 If you use this with other css framework , you need to put tour CustomCss under bootstrap css's. 如果与其他css框架一起使用,则需要将CustomCss放到引导css的下面。

ANOTHER SOLUTION 另一个解决方案

USE SASS OR LESS 少用或少用

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

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