简体   繁体   English

如何使用弄乱了我的页面的外部CSS样式表?

[英]How to work with an external css stylesheet that is messing up my page?

I have a webpage written in PHP that displays a table, and I use nvd3 to also show a graph based on the table, however according to this tutorial: http://lsxliron.github.io/nvd3Tutorial/ I should use several css stylesheets, inlcuding 我有一个用PHP编写的可显示表格的网页,并且我还使用nvd3来显示基于表格的图形,但是根据本教程: http : //lsxliron.github.io/nvd3Tutorial/我应该使用几个CSS样式表,包括

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css" />

in my head for the page. 在我的页面上。 I also use my own external stylesheet. 我还使用自己的外部样式表。 However the linked one has the code 但是链接的有代码

td,th {
  padding: 15px 5px;
  display: table-cell;
  text-align: left;
  vertical-align: middle;
  border-radius: 2px
}

td,th {
  padding: 0
}

table {
  border-collapse: collapse;
  border-spacing: 0
}

table {
  width: 100%;
  display: table
}

,th,td {
  border: none
}

*,*:before,*:after {
  box-sizing: inherit
}

in it which messes up my table, short of either not including this stylesheet, explicitly overriding it with my own local css, or making the graph show in a new webpage is there anything I can do? 在其中弄乱了我的表,除了不包括此样式表,用我自己的本地CSS显式覆盖它,还是使图形显示在新的网页中,我能做些什么? And if those are my only options, how could I override the *,*:before,*:after section? 如果只有这些选项,我该如何覆盖*,*:before,*:after部分? It is making my headers off center 它使我的标头偏离中心

Thanks in advance 提前致谢

Edit: The code being affected by 编辑:该代码受

*,*:before,*:after {
  box-sizing: inherit
}

is a div inside of a td used to space out my headings and subheadings, I added box-sizing: initial to the div, and it works fine now (everything was shifted to the left before). 是td内的div,用于分隔我的标题和副标题,我在div中添加了box-sizing: initial ,并且现在工作正常(所有内容之前都移到了左侧)。 The box-sizing inherit was shrinking the content and increasing the margin. box-sizing inherit会缩小内容并增加边距。

materialize is not required for NVD3. NVD3不需要实现。 I would ignore that part of the tutorial unless you want to use Material Design. 除非您要使用Material Design,否则我将忽略本教程的这一部分。 If you do want to use materialize, then just make your selectors more specific. 如果确实要使用物化,则只需使选择器更具体。

eg 例如

.my-table-wrapper td, .my-table-wrapper th {
  padding: 15px 5px;
  /* etc. */
}
  1. put your CSS after all others 将您的CSS放在所有其他人之后
  2. add !important to every rule you want to override 向要覆盖的每个规则添加!important
  3. check with inspector in your favorite browser which rules you have to override additionally and do it also with !important 在您喜欢的浏览器中与检查器进行检查,您必须额外覆盖哪些规则,并使用!important
  4. remember that the more specific your rule is the higher its priority: ul li a.menu-link will override a.menu-link for all anchors in ul>li 请记住,规则越具体则优先级越高: ul li a.menu-link将覆盖ul> li中所有锚点的a.menu-link

Example

td,th {
  padding: 15px 5px !important;
  display: table-cell !important;
  text-align: left !important;
  vertical-align: middle !important;
  border-radius: 2px !important;
}

You only need to import the materialize fiel in your new css3 file, how you know css work over waterfall, that mean that whe your use import in css on the top of the page, that style will charge in the same css, and beacuse css work over waterfall all the last style overwrite the first style (As long as styles repeat themselves). 您只需要在新的css3文件中导入实例化字段,就可以知道css在瀑布上的工作方式,这意味着您将使用导入到页面顶部的css中,该样式将在同一css中收费,并且因为css在瀑布上工作时,所有最后一个样式都会覆盖第一个样式(只要样式重复出现即可)。 Go: 走:

@import url("https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css");

td,th {
 padding: 15px 5px;
 display: table-cell;
 text-align: left;
 vertical-align: middle;
 border-radius: 2px
 padding: 0
 border: none;
}

table {
 border-collapse: collapse;
 border-spacing: 0
 width: 100%;
}

*,*:before,*:after {
  box-sizing: inherit
}

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

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